joswig@corporate-world.lisp.de wrote:
For combinations of this kind of stuff I really prefer the functional approach:
CL-USER 5 > (remove-if-not 'oddp '(1 2 3))
(1 3)
I know it is possible, but I'm not sure aboout how to write the following with a functional approach:
(loop for i from 1 to 10 collect (loop for j from 1 to i collect j))((1) (1 2) (1 2 3) (1 2 3 4) (1 2 3 4 5) (1 2 3 4 5 6) (1 2 3 4 5 6 7) (1 2
3 4 5 6 7 8) (1 2 3 4 5 6 7 8 9) (1 2 3 4 5 6 7 8 9 10))
CL-USER> [x (x <- '(1 2 3)) (oddp x)]
(1 3)
CL-USER> (loop for x in (list 1 2 3) when (oddp x) collect x)
(1 3)
LOOP does some kind of list comprehension aswell, without an additional software.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 74 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 01:26:00 |
| Calls: | 1,194 |
| Files: | 1,352 |
| D/L today: |
1 files (1,580K bytes) |
| Messages: | 290,958 |