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))))
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 76 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 55:37:13 |
| Calls: | 1,265 |
| Calls today: | 1 |
| Files: | 1,362 |
| D/L today: |
3 files (2,684K bytes) |
| Messages: | 285,684 |