|Until recently, Anarki (like Arc 3.1) returned nil on (read) if there was nothing left to read (i.e. end-of-file or eof). However this would cause problems if you happened to read a real nil from stdin. To deal with this, (read) could be overridden to provide a symbol that the caller knew wasn't in the input. This has been a source of gotchas and questions on several occasions, as people learn the verbose idiom:|
A couple of days ago I changed Anarki so it always returns a uniq symbol on eof. The value returned on eof is stored also in the global variable eof. So now this always works and unambiguously signals end-of-file:
(read (stdin) eof))
To check for eof, do something this:
A subtlety here is that since uniq always returns uninterned symbols on Anarki , this works even if we have exceptionally bad luck and try to read the precise value of the eof variable.
(let var (read)
(unless (is var eof)
Github link: https://github.com/arclanguage/anarki/commit/06b82a57dc
eof858 ; you might see something different
arc> (fromstring "eof858" (is (read) eof))
nil ; sweet!
Thanks zck for the discussion, and for prodding for a change: https://github.com/arclanguage/anarki/issues/61