• Re: loop with an optional limit?

    From B. Pym@21:1/5 to Novus on Sat Jul 19 20:55:25 2025
    XPost: comp.lang.scheme

    Novus wrote:

    (loop :for n :from 1
    :for form = (read s nil s)
    :until (eq form s)
    :collect (make-instance 'foo :src form)
    :until (and count (<= count n)))

    Or if you like loops that look more like lisp than loop:

    (iter (for form in-stream s)
    (for n upfrom 0)
    (until (and count (<= count n)))
    (collect (make-instance 'foo :src form))))

    Gauche Scheme

    (use gauche.generator)

    (define count 3)

    (map (^(form) (list 'foo form))
    (generator->list read (or count +inf.0)))

    1 2 3 4
    ((foo 1) (foo 2) (foo 3))
    gosh> 4

    --
    [T]he problem is that lispniks are as cultish as any other devout group and basically fall down frothing at the mouth if they see [heterodoxy].
    --- Kenny Tilton
    The good news is, it's not Lisp that sucks, but Common Lisp. --- Paul Graham

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