Sujet : Re: shootout: implementing an interpreter
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lispDate : 08. Aug 2024, 19:36:32
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v92vmt$4rap$1@dont-email.me>
References : 1
User-Agent : XanaNews/1.18.1.6
B. Pym wrote:
Kent M. Pitman wrote:
(defun shrug (list)
(loop for (x . sublist-and-more) on list
for more = (member x sublist-and-more)
when more
collect `(g ,x ,(ldiff sublist-and-more more))))
=> SHRUG
(shrug '(a b c a d b d))
=> ((G A (B C)) (G B (C A D)) (G D (B)))
newLISP
(define (shrug xs (x (pop xs)))
(and xs
(if (match (list '* x '*) xs)
(cons (list 'g x ($it 0)) (shrug xs))
(shrug xs))))
(shrug '(a b c a d b d))
((g a (b c)) (g b (c a d)) (g d (b)))
Shorter:
(define (shrug xs (x (pop xs)))
(and xs
(if (find x xs)
(cons (list 'g x (0 $it xs)) (shrug xs))
(shrug xs))))
-