Re: REPL script and @
Hi Alex, On 18. Dec, 2013, at 21:19, Alexander Burger a...@software-lab.de 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
Re: REPL script and @
Hi Jon, 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) ) ) ) Yes, right. That's better. The (flush) at the end is actually not needed, because the end-of-line in 'println' flushes the output automatically. However 'prin' does not, so I would move the (flush) up: (prin - ) (flush) (println Res) ) ) ) This is critical only when printing the result takes a long time. You see that, for example, if you calculate a big number which takes time to convert upon output. : (** 1 1) The - appears immediately due to the (flush), but the digits 1000... only after a second or so. ♪♫ Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
Re: REPL script and @
Hi Alex, On 29. Sep, 2014, at 15:40, Alexander Burger a...@software-lab.de wrote: Hi Jon, 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) ) ) ) Yes, right. That's better. The (flush) at the end is actually not needed, because the end-of-line in 'println' flushes the output automatically. However 'prin' does not, so I would move the (flush) up: (prin - ) (flush) (println Res) ) ) ) This is critical only when printing the result takes a long time. You see that, for example, if you calculate a big number which takes time to convert upon output. : (** 1 1) The - appears immediately due to the (flush), but the digits 1000... only after a second or so. ♪♫ Alex Thanks. I tried moving (flush) up, but it didn’t work well in my websocketd setup. The effect was that the arrow and result didn’t appear until I entered a new command, so it seemed as if ‘println’ didn’t flush. I’ll keep my (flush) at the end. ;-) I’m using 32-bit PicoLisp. /Jon
Re: REPL script and @
Hi Jon, Thanks. I tried moving (flush) up, but it didn’t work well in my websocketd setup. Ah, I should have said that Stdout in Unix is flushed at end of line only if output is to a TTY. So you actually need two (flush)s. ♪♫ Alex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe