• Re: Returning no value

    From B. Pym@21:1/5 to Ken Tilton on Fri Aug 30 09:13:19 2024
    XPost: comp.lang.scheme

    Ken Tilton wrote:

    Steven M. Haflich wrote:
    I think the OP may be looking for something like this:

    cl-user(10): (defun foo()
    (let ((x (random 10)))
    (and (< 5 x) x)))
    foo
    cl-user(11): (loop repeat 10
    as x = (foo)
    when x collect x) ; <<<<<
    (6 8 9)

    Sweet. But not wnat someone already offered?:

    (loop repeat 10
    when (foo)
    collect it)

    Gauche Scheme

    (define (foo) (let1 x (random-integer 10) (and (< 5 x) x)))

    (define (tcollect func tries)
    (if (zero? tries)
    '()
    (append (cond ((func) => list) (#t '()))
    (tcollect func (- tries 1)))))

    (tcollect foo 10)

    (9 8 9 6 7 9)

    (tcollect + 3)

    (0 0 0)

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