Deutsch   English   Français   Italiano  
<v7beq0$2g7di$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: "B. Pym" <Nobody447095@here-nor-there.org>
Newsgroups: comp.lang.lisp
Subject: re: Generating code which compiles to a jmphash
Date: Thu, 18 Jul 2024 16:10:44 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <v7beq0$2g7di$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Thu, 18 Jul 2024 18:10:44 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="3a24c25a980f7b3f5878d5aa73c34d1d";
	logging-data="2629042"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+xuTN+PpHhV6xo2qy5n3Gw"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:8/gbR65cYsG/UoX77w6n/CBRGHc=
Bytes: 1725

fvmarcoline wrote:

> (defconstant dirs '(up down left right))
> 
> (defun all-moves ()
> 
>   (loop for dir in dirs
>      append
>        (loop for i from 0 to 4
>           collect (list i dir))))
> 
> (defun move-to-int (move)
>   (+ (first move) (* 5 (position (second move) dirs))))
> 
> > (nth 12 (all-moves))
>        => (2 left)
> > (map 'list 'move-to-int (all-moves))
>        => (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)

Gauche Scheme

(define dirs '(up down left right))
(define dir-table (map cons dirs '(0 5 10 15)))

(define (all-moves)
  (append-map
    (^(dir) (map (^i (list i dir)) (lrange 0 5)))
    dirs))

(define (move-to-int move)
  (+ (car move) (assv-ref dir-table (cadr move))))

(~ (all-moves) 12)
  ===>
(2 left)

(map move-to-int (all-moves))
  ===>
(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)