Re: shootout: implementing an interpreter

Liste des GroupesRevenir à cl lisp 
Sujet : Re: shootout: implementing an interpreter
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp
Date : 27. Jun 2025, 14:18:09
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <103m5mg$5tof$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)))

Gauche Scheme

Using recursion instead of looping and the symbol !
instead of the less distinctive G.

(define (shrug List)
  (if (pair? List)
    (let* ((x (pop! List)) (more (member x List)))
      (if more
        (cons `(! ,x ,(drop-right List (length more))) (shrug List))
        (shrug List)))
    ()))

(shrug '(a b c a d b d))
  ===>
((! a (b c)) (! b (c a d)) (! d (b)))


Date Sujet#  Auteur
7 Aug 24 * Re: shootout: implementing an interpreter3B. Pym
8 Aug 24 +- Re: shootout: implementing an interpreter1B. Pym
27 Jun 25 `- Re: shootout: implementing an interpreter1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal