From: Mark Tarver
Subject: event loop bug
Date: 
Message-ID: <ca4bbca2-17f9-4153-87a6-efe50af74938@z38g2000hsc.googlegroups.com>
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*))))

From: Pascal Bourguignon
Subject: Re: event loop bug
Date: 
Message-ID: <87lk4jowvm.fsf@thalassa.informatimago.com>
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.
From: Mark Tarver
Subject: Re: event loop bug
Date: 
Message-ID: <a9298e2f-6db4-498c-a3d3-a34b54993c67@k13g2000hse.googlegroups.com>
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