Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 28 |
Nodes: | 6 (1 / 5) |
Uptime: | 45:55:01 |
Calls: | 422 |
Calls today: | 1 |
Files: | 1,024 |
Messages: | 90,336 |
I wanted to write a function that reads whitespace-separated numbers
from a string, i.e. given a string like "1 2 3 4" I wanted my function
to return the list (1 2 3 4).
Two different solutions came to mind:
(defun foo1 (string)
(loop for start = 0 then pos
for (object pos) = (multiple-value-list
(read-from-string string nil nil :start start))
while object
collect object))
(defun foo2 (string)
(let ((start 0) object result)
(loop
(multiple-value-setq (object start)
(read-from-string string nil nil :start start))
(unless object
(return-from foo2 (nreverse result)))
(push object result))))