(defun partition (pred list)
(loop for item in list
when (funcall pred item)
collect item into in
else
collect item into out
finally (return (values in out))))
For what it's worth [if anything!], this version preserves the
initial relative ordering of items which pass/don't-pass the
predicate, e.g.:
> (partition (lambda (x) (zerop (mod x 3))) (iota 30))
(0 3 6 9 12 15 18 21 24 27)
(1 2 4 5 7 8 10 11 13 14 16 17 19 20 22 23 25 26 28 29)
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 299 |
Nodes: | 16 (2 / 14) |
Uptime: | 26:59:37 |
Calls: | 6,681 |
Calls today: | 4 |
Files: | 12,222 |
Messages: | 5,342,299 |
Posted today: | 2 |