(loop for x in list
unless (p x) collect x into new-list
finally (setq list new-list))
Jeff Barnett wrote:
Does the Common Lisp spec say anything about whether the following is
well defined given that the elements of "list" are unique:
(loop for x in list
when (p x)
do (setq list (delete x list)))
See http://www.lispworks.com/documentation/HyperSpec/Body/03_f.htm
But I wouldn't worry too much and just switch to a non-destructive version:
(loop for x in list
unless (p x) collect x into new-list
finally (setq list new-list))
Pascal Costanza wrote:
Jeff Barnett wrote:
Does the Common Lisp spec say anything about whether the following is well defined given that the elements of "list" are unique:
(loop for x in list
when (p x)
do (setq list (delete x list)))
See http://www.lispworks.com/documentation/HyperSpec/Body/03_f.htm
But I wouldn't worry too much and just switch to a non-destructive version:
(loop for x in list
unless (p x) collect x into new-list
finally (setq list new-list))
Gauche Scheme:
(remove odd? (iota 22))
===>
(0 2 4 6 8 10 12 14 16 18 20)
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 152:52:12 |
| Calls: | 12,091 |
| Calls today: | 4 |
| Files: | 15,000 |
| Messages: | 6,517,662 |