This program is an event loop emulating a Lisp-like top level. It
reads in characters and evaluates the result when the user hits enter.
However the behaviour is erratic and I cannot exactly see why. To see
what I mean try to run it. I may have missed the obvious. Can
anybody suggest what is wrong?
Running CLisp on Windows XP.
Mark
(DEFUN toplevel ()
(SETQ *buffer* NIL)
(event-loop))
(DEFUN event-loop ()
(process-keyboard (READ-CHAR-NO-HANG))
(SLEEP .01)
(event-loop))
(DEFUN process-keyboard (C)
(COND ((NULL C))
((MEMBER C '(#\Newline #\Return) :TEST 'CHAR-EQUAL)
(LET ((Line (READ-FROM-STRING
(COERCE (NREVERSE *buffer*) 'STRING))))
(SETQ *buffer* NIL)
(PPRINT (EVAL Line))
(FORMAT T "~%~%> ")))
(T (FORMAT T "~C" C) (PUSH C *buffer*))))
Mark Tarver <··········@ukonline.co.uk> writes:
> This program is an event loop emulating a Lisp-like top level. It
> reads in characters and evaluates the result when the user hits enter.
>
> However the behaviour is erratic and I cannot exactly see why. To see
> what I mean try to run it. I may have missed the obvious. Can
> anybody suggest what is wrong?
>
> Running CLisp on Windows XP.
It runs ok on clisp 2.41 on linux.
> Mark
>
> (DEFUN toplevel ()
> (SETQ *buffer* NIL)
> (event-loop))
>
> (DEFUN event-loop ()
> (process-keyboard (READ-CHAR-NO-HANG))
> (SLEEP .01)
> (event-loop))
clisp does TCO only in the compiler, not in the interpreter.
> (DEFUN process-keyboard (C)
> (COND ((NULL C))
> ((MEMBER C '(#\Newline #\Return) :TEST 'CHAR-EQUAL)
> (LET ((Line (READ-FROM-STRING
> (COERCE (NREVERSE *buffer*) 'STRING))))
> (SETQ *buffer* NIL)
> (PPRINT (EVAL Line))
> (FORMAT T "~%~%> ")))
> (T (FORMAT T "~C" C) (PUSH C *buffer*))))
You could try to use the EXT:*KEYBOARD-INPUT* package. See the
Implementation Notes.
--
__Pascal Bourguignon__ http://www.informatimago.com/
HEALTH WARNING: Care should be taken when lifting this product,
since its mass, and thus its weight, is dependent on its velocity
relative to the user.
On 16 Mar, 09:12, Pascal Bourguignon <····@informatimago.com> wrote:
> Mark Tarver <··········@ukonline.co.uk> writes:
> > This program is an event loop emulating a Lisp-like top level. It
> > reads in characters and evaluates the result when the user hits enter.
>
> > However the behaviour is erratic and I cannot exactly see why. To see
> > what I mean try to run it. I may have missed the obvious. Can
> > anybody suggest what is wrong?
>
> > Running CLisp on Windows XP.
>
> It runs ok on clisp 2.41 on linux.
>
> > Mark
>
> > (DEFUN toplevel ()
> > (SETQ *buffer* NIL)
> > (event-loop))
>
> > (DEFUN event-loop ()
> > (process-keyboard (READ-CHAR-NO-HANG))
> > (SLEEP .01)
> > (event-loop))
>
> clisp does TCO only in the compiler, not in the interpreter.
>
> > (DEFUN process-keyboard (C)
> > (COND ((NULL C))
> > ((MEMBER C '(#\Newline #\Return) :TEST 'CHAR-EQUAL)
> > (LET ((Line (READ-FROM-STRING
> > (COERCE (NREVERSE *buffer*) 'STRING))))
> > (SETQ *buffer* NIL)
> > (PPRINT (EVAL Line))
> > (FORMAT T "~%~%> ")))
> > (T (FORMAT T "~C" C) (PUSH C *buffer*))))
>
> You could try to use the EXT:*KEYBOARD-INPUT* package. See the
> Implementation Notes.
>
> --
> __Pascal Bourguignon__ http://www.informatimago.com/
>
> HEALTH WARNING: Care should be taken when lifting this product,
> since its mass, and thus its weight, is dependent on its velocity
> relative to the user.
Indeed; this seems to be the solution. Here is some code I scavaged
and adapted. This works perfectly.
(DEFUN toplevel ()
(SETQ *buffer* NIL)
(event-loop))
(DEFUN event-loop ()
(process-keyboard (read-from-keyboard EXT:*KEYBOARD-INPUT*))
(SLEEP .01)
(event-loop))
(DEFUN read-from-keyboard (KeyBoard)
(EXT:WITH-KEYBOARD
(LET ((Char (READ-CHAR-NO-HANG KeyBoard NIL NIL)))
(IF (NULL Char) NIL (SYS::INPUT-CHARACTER-CHAR Char)))))
(DEFUN process-keyboard (C)
(COND ((NULL C))
((MEMBER C '(#\Newline #\Return) :TEST 'CHAR-EQUAL)
(LET ((Line (READ-FROM-STRING
(COERCE (NREVERSE *buffer*) 'STRING))))
(SETQ *buffer* NIL)
(PPRINT (EVAL Line))
(FORMAT T "~%~%> ")))
(T (FORMAT T "~C" C) (PUSH C *buffer*))))
Mark