• Re: Returning no value

    From B. Pym@21:1/5 to Ken Tilton on Thu Jul 18 22:38:01 2024
    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

    (use srfi-27) ;; random-integer

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

    (filter-map foo (iota 10))
    ===>
    (9 6 7 8 9)

    Another way.

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

    (filter-map (^_ (foo)) (iota 10))
    ===>
    (7 8 9 6 6 7)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From B. Pym@21:1/5 to B. Pym on Thu Jul 18 23:00:59 2024
    B. Pym wrote:

    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

    (use srfi-27) ;; random-integer

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

    (filter-map foo (iota 10))
    ===>
    (9 6 7 8 9)

    Another way.

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

    (filter-map (^_ (foo)) (iota 10))
    ===>
    (7 8 9 6 6 7)


    Another way:

    (use gauche.generator)

    (filter + (generator->list foo 10))
    ===>
    (7 8 9 8)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to B. Pym on Fri Jul 19 16:55:00 2024
    On 2024-07-18, B. Pym <Nobody447095@here-nor-there.org> wrote:
    Another way.

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

    (filter-map (^_ (foo)) (iota 10))

    (7 8 9 6 6 7)

    This is the TXR Lisp interactive listener of TXR 295.
    Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
    Please listen carefully to the following spec, as our Lisp has changed.
    [keep-keys-if (op < 5) 0..10 (ret (rand 10))]
    (9 9 7)
    [keep-keys-if (op < 5) 0..10 (ret (rand 10))]
    (6 8 8 7)

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • 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)