Arc Forumnew | comments | leaders | submitlogin
Experimental change in Anarki
3 points by akkartik 46 days ago | discuss
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:

  (w/uniq eof
    (read (stdin) eof))
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:

To check for eof, do something this:

  (let var (read)
    (unless (is var eof)
A subtlety here is that since uniq always returns uninterned symbols on Anarki [1], this works even if we have exceptionally bad luck and try to read the precise value of the eof variable.

  arc> eof
  eof858  ; you might see something different
  arc> (fromstring "eof858" (is (read) eof))
  nil  ; sweet!
Github link:

Thanks zck for the discussion, and for prodding for a change: