I am familiar with the basic template for collecting the Lisp objects from a file, as in:
(with-open-file (stream "filename.lisp")
(loop for object = (read stream nil 'eof)
until (eq object 'eof)
collect object))
But I'm not sure how to translate this into collecting the objects from a string, for example using read-from-string. Do you then have to keep track of the index where you left off in the string? Also, how do you avoid a name conflict with eof or any other legitimate Lisp object like nil or t in the input?
You can use with-input-from-string to read from a string.
To prevent a conflict with the eof symbol, you can use an uninterned symbol or some other object that's created dynamically.
(with-input-from-string (stream "this is a (list of 3 things)")
(loop with eof-marker = '#:eof
for object = (read stream nil eof-marker)
until (eq object eof-marker)
collect object))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With