I have a strings like "0 2 0 1". The number of values may vary, but they all can be read using READ
Right now I do the following
(loop
:for (x pos) = (multiple-value-list
(read-from-string first-line nil nil :start (or pos 0)))
:while x
:collect x)
Is there a more idiomatic way to read all the tokens in the string and return them as a list?
(with-input-from-string (in string)
(loop :for n = (read in nil nil)
:while n :collect n))
Pascal J. Bourguignon wrote:
I have a strings like "0 2 0 1". The number of values may vary, but they all can be read using READ
Right now I do the following
(loop
:for (x pos) = (multiple-value-list
(read-from-string first-line nil nil :start (or pos 0)))
:while x
:collect x)
Is there a more idiomatic way to read all the tokens in the string and return them as a list?
(with-input-from-string (in string)
(loop :for n = (read in nil nil)
:while n :collect n))
If we are allowed to use a collector, then the loop
becomes much shorter. Compare:
(loop :for n = (read in nil nil) :while n :collect n))
(until (eof-object? (bag (read))))
Gauche Scheme:
(define bag (mlistbag))
(with-input-from-string "0 4 2 5"
(lambda()
(until (eof-object? (bag (read))))))
;; Remove the eof-object.
(drop-right (bag) 1)
===>
(0 4 2 5)
Given:
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 65 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 04:12:51 |
| Calls: | 862 |
| Files: | 1,311 |
| D/L today: |
921 files (14,318M bytes) |
| Messages: | 264,528 |