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)
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.
(define (foo) (let1 x (random-integer 10) (and (< 5 x) x)))
(filter-map (^_ (foo)) (iota 10))
(7 8 9 6 6 7)
[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)
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)
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 417 |
Nodes: | 16 (2 / 14) |
Uptime: | 05:59:09 |
Calls: | 8,757 |
Files: | 13,285 |
Messages: | 5,963,069 |