Hi Alex, On 18. Dec, 2013, at 21:19, Alexander Burger <[email protected]> wrote:
> Hi Jon, > >> I just wrote a little PicoLisp script (for pil32) that "simulates" >> the REPL, quite similar to the one I did for Ersatz a while ago, >> <http://picolisp.com/5000/!wiki?SwingRepl>. The new REPL script >> looks like this: >> >> (in NIL >> (until (eof) >> (let (ProgText (pack (line)) >> Prog (str ProgText) >> Result (run Prog) ) >> (prinl "-> " (sym Result)) >> (flush) ) ) ) >> >> It works quite fine, but one minor flaw is that, when you're running >> this REPL, '@' always returns NIL. Is there some simple way to fix >> that? > > Yes, you could bind the symbol '@', like in > > (in NIL > (use (Exe Res) > (while (setq Exe (read)) > (prin "-> ") > (println > (setq Res > (let @ Res > (eval Exe) ) ) ) ) ) ) > > Note that I here use 'read', 'eval' and 'print' directly, so there is no > need to operate on the string level with 'pack', 'line', 'str' and > 'sym'. > > Note also that this REPL exits when NIL is read (while .. (read)), as > this is also the behavior of the built-in REPL. If you don't want this, > then your way of (until (eof) ..) is better. > > ♪♫ Alex I just noticed that doing the (prin "-> ") before the (eval Exe) causes the arrow to be printed before the first printed line, e.g. when entering an expression like (for N 3 (prinl N)). Instead, the arrow should appear just before the final result. I have now ended up with this: (in NIL (use Res (until (eof) (setq Res (let @ Res (eval (read)) ) ) (prin "-> ") (println Res) (flush) ) ) ) (bye) /Jon
