Arc Forumnew | comments | leaders | submitlogin
Load stops after nil
7 points by rincewind 5950 days ago | 1 comment
Put this into a file:

  (prn "SPAM")
  nil
  (prn "This won't even be loaded")
and load the file. Only SPAM is printed, because load stops after encountering a nil or (). I think this is wrong, unobvious and may lead to bugs when loading/saving generated code. To fix this, the expression

   (whilet e (read f)
         (eval e))
in arc.arc (Arc2, looks a bit different on anarki) should be replaced by

  (w/uniq eof 
      (whiler e (read f eof) eof
          (eval e)))
And the whiler macro should be implemented as

  (mac whiler (var snarfdata stopval . body)
   (w/uniq stop
     `(withs (,var nil ,stop (testify ,stopval))
        (while (no (,stop (= ,var ,snarfdata)))
                ,@body))))
because the current implementation also stops on nil, contrary to what the comment

   ; For the common C idiom while (x = snarfdata) != stopval.
by PG implies.


1 point by rincewind 5950 days ago | link

the old behaviour of whiler can the be achieved by writing

  (whiler var (snarfdata) [in var stopval nil]
     .. body)
or keeping the old whiler macro as whiler-old.

-----