• sequence iteration

    From Robert L.@21:1/5 to All on Fri Feb 11 09:20:17 2022
    (loop
    for element in sequence
    collect (do-something-to element)
    until (> element 5))

    This performs some action on each element (do-something-to) and
    collects the results in a list (the return value of loop). If it runs
    into an element that is greater than 5, it will terminate early and
    return whatever it collected so far.

    (use srfi-42) ;; list-ec for Gauche Scheme.
    or
    (require srfi/42) ;; list-ec for Racket.

    (define nums '(-8 0 4 6 9))

    (list-ec (:until (:list x nums) (> x 5)) (abs x))


    (8 0 4 6)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From B. Pym@21:1/5 to Don Geddis on Mon Jun 23 01:49:35 2025
    Don Geddis wrote:

    Is there any generic iteration contruct for sequences? Ideally it
    would work just like DOLIST.
    > (do-sequence (e "ab c")
    (print e))
    #\a
    #\b
    #\Space
    #\c
    nil

    Well, I don't know if you consider the LOOP macro to be Common Lisp, but
    the following works in Allegro CL 4.2:

    USER(20): (loop for x across "ab c" do (print x))

    #\a
    #\b
    #\space
    #\c
    NIL

    CLtL2 says that the "across" keyword works for iteration over arrays (vectors),
    so it looks to be not quite as generic as over sequences. But it's close.

    Gauche Scheme

    (use gauche.collection)

    (for-each print '(a b c))
    a
    b
    c

    (for-each print #(a b c))
    a
    b
    c

    (for-each print "abc")
    a
    b
    c

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)