Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 40 |
Nodes: | 6 (0 / 6) |
Uptime: | 10:25:57 |
Calls: | 291 |
Files: | 910 |
Messages: | 76,423 |
(loop for x in things
when (foo-p x) collect x into foos
when (bar-p x) collect x into bars
when (and (foo-p x) (bar-p x)) collect x into both
finally (return (values foos bars both)))
(loop for x in things
when (foo-p x) collect x into foos
when (bar-p x) collect x into bars
when (and (foo-p x) (bar-p x)) collect x into both
finally (return (values foos bars both)))
It's shorter in Gauche Scheme.
(define things '(0 3 -5 4 9 -7 6 8))
1: (let@ (() odds posi both)
2: (dolist (x things)
3: (when (odd? x) (push! odds x))
4: (when (positive? x) (push! posi x)
5: (when (odd? x) (push! both x))))
6: (values odds posi both))
(-7 9 -5 3)
(8 6 9 4 3)
(9 3)
Given:
7: (define-macro let@
8: (lambda (lets . exprs)
9: (let ((lets lets)
10: (let-pairs '()))
11: (if (list? lets)
12: (while (pair? lets)
13: (let ((x (pop! lets)))
14: (cond
15: ((not (symbol? x))
16: (while (pair? lets)
17: (push! let-pairs (list (pop! lets) x))))
18: ((null? lets) (push! let-pairs (list x 0)))
19: (#t (push! let-pairs (list x (pop! lets)))))))
20: (set! let-pairs `((,lets 0))))
21: `(let* ,(reverse let-pairs)
22: ,@exprs))))