Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You are farsighted, a good planner, an ardent lover, and a faithful friend.


comp / comp.lang.lisp / Re: shootout: implementing an interpreter

SubjectAuthor
* Re: shootout: implementing an interpreterB. Pym
`- Re: shootout: implementing an interpreterB. Pym

1
Subject: Re: shootout: implementing an interpreter
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Wed, 7 Aug 2024 17:28 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: shootout: implementing an interpreter
Date: Wed, 7 Aug 2024 17:28:34 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <v90as0$380ne$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Wed, 07 Aug 2024 19:28:35 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="7094501a9f209988b45d39573ac7d250";
logging-data="3408622"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/oDyTrPjKwX8Zi7j1Lyopw"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:KEJY0frZhot5OTIV89LYFxQKkZQ=
View all headers

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)))

Subject: Re: shootout: implementing an interpreter
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Thu, 8 Aug 2024 17:36 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: shootout: implementing an interpreter
Date: Thu, 8 Aug 2024 17:36:32 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <v92vmt$4rap$1@dont-email.me>
References: <v90as0$380ne$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Thu, 08 Aug 2024 19:36:32 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="623536926260db1f505ba92f19951445";
logging-data="159065"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX190P8RD6LfdWENcJgPyfxF6"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:8oufY7XJSVdt2y9hexyFcD+2ZkI=
View all headers

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))))
-

1

rocksolid light 0.9.8
clearnet tor