Re: Redefine read-eval-print loop?
> David Fox writes
> ] I have a need to alter the STk read-eval-print loop in a way that
> ] prevents it from printing after evaluation.
>
> You could write your own:
>
> (let loop ()
> (display "STk> ")
> (flush (current-output-port))
> (eval (read))
> (loop))
Of course, you can do it in Scheme ;-) I should have answered this first.
However, I still think that the current implementaion was not coherent when
the interpreter is not used in interactive mode (i.e the prompt is not
printed and the result is).
Hereafter is a better version of the scheme solution, imho; the problem with
David's version is that it breaks the loop when an error occurs.
If you don't want this behaviour, you can use the following version:
(define (my-toplevel)
(let ((toplevel (lambda ()
(let loop ()
(display "> ")
(flush (current-output-port))
(let ((expr (read)))
(unless (eof-object? expr)
(eval expr)
(loop)))))))
(dynamic-wind (lambda () #f)
toplevel
toplevel)))
You need to enter an eof to exit this loop and the dynamic-wind avoids to
break it prematurely whence an error occurs.
-- Erick
Received on Mon Mar 24 1997 - 10:51:43 CET
This archive was generated by hypermail 2.3.0
: Mon Jul 21 2014 - 19:38:59 CEST