• Re: shootout: implementing an interpreter

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Fri Jun 27 13:18:09 2025
    From Newsgroup: comp.lang.lisp

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

    --- Synchronet 3.21d-Linux NewsLink 1.2