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: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 06:48:41 |
| Calls: | 12,100 |
| Calls today: | 8 |
| Files: | 15,003 |
| Messages: | 6,517,926 |
| Posted today: | 1 |