Subject: Real time input

From: haible (Bruno Haible)
Date: Wed, 1 Feb 95 01:44:42 +0100

[Forwarded from Ed Loper <ed@syse>???.]

-------------------------------------------------------------------------------

I have a question about the listen and read-char-no-hang 
functions.  I'm trying to make a program which will read 
characters as they are typed, but do other things if they 
are not typed.  This is, as far as I can tell, the 
function of read-char-no-hang.  However, clisp seems to 
wait until a newline has been pressed before putting 
typed characters into the buffer; thus, if a user types
"h", my program won't see it until he types a newline, at
which point it will see an "#\h" and a "#\Newline".  clisp
also seems to echo each character to the screen when it is
typed; I would prefer if it would let me handle this.  Is
this all happening because of the read-eval-print loop?  Is
there a special variable which I need to set in order to
tell clisp that I want each character put into the input
buffer as it is read?  Or is there some other way in which
I should arrange for characters to be read as soon as they
are typed?  I've looked through a lot of common lisp docs
and books with no success, so I thought that it might be
something particular to clisp.

In case it matters, I am running:
 - A version of clisp that was copyrighted 1994 (I can't 
   figure out where the version number
   is) on version 

The operating system is:
 - Version 1.1.73 of Linux (Slackware version 2.0)

A short function which demonstrates this problem is:
;;
;; This function creates a busy loop which echos characters
;; whenever it recieves them.  When it recieves the character
;; #\q, it immediately exits.
;;
(defun read-characters ()                                            
  (let ((input nil))                        ;Bind a var for input
    (loop                                   ;Loop until #\q is hit
     (when (setf input (read-char-no-hang)) ;When a char is typed,
         (write input)                      ;  write that character
         (format t "~%"))                   ;Write a newline
     (when (equal input #\q)                ;When the char is q,
           (return t)))))                   ;  exit and return t

I also had four less important questions:
  1. How portable is the screen package?  Is it only portable across
     common lisp, or is it a defined standard, a de facto standard,
     or is it only implemented in clisp?

  2. Because clisp doesn't compile to a machine-specific binary, is
     there no way to make a stand alone executable?  Is there some
     way to link clisp and my program into one binary file, and if
     so, do I have to worry about licensing stuff etc?  

  3. What x-windows packages are available for clisp? (clx, garnet, 
     etc.) and where can I get them?

  4. Eric Sauthier wrote that "One way to overcome this 'slowness'
     would be to add a step to the compiler, specific to a particular
     architexture, which would translate the intermediate language
     representation into machine instructions."  I was wondering if
     anyone was working on such an entity for linux.  I am neither
     a linux guru nor a lisp guru, so I couldn't give much help, but
     I would be interrested in such a project's progress.  I was also
     wondering whether it would in fact be easier to compile from
     clisp binaries to linux binaries, or whether it would be easier
     to compile directly from common lisp: are the binaries simpler
     then the common lisp code?  Do they only use a few commands?  If
     so, are they commands like first, rest, and list, or commands
     like jump, copy-memory, and add?

Thanx in advance for any help you can give me...

                                Edward Loper

---

From: [email-masked] (Joerg-Cyril Hoehle)
Date: Wed, 1 Feb 95 11:42:21 +0100

> wait until a newline has been pressed before putting 
It's not really CLISP, CLISP is simply reading characters in cooked
mode, using some OS-supplied functions. Cooked-mode reads one line at
a time, leaving you the usual editing capabilities of your console.

 > typed; I would prefer if it would let me handle this.  Is
You have to leave cooked-mode for this to work.

 > buffer as it is read?  Or is there some other way in which

There are different things one can do.

First there is (sys::terminal-raw *terminal-io* T/NIL) available on
some platforms (Amiga, UNIX, ACORN). On the Amiga (newer CLISPs), this
will do exactly what you want, namely no echo, read one character at a
time, working listen and read-char-no-hang. However the draw-back is
that if you enter the debugger or if your program requests input,
you'll be left in raw-mode and very disappointed (the next version
might switch modes in the debugger). You have to switch modes
yourself. Some implementations of CLISP switch modes internally,
causing portability problems.

Then there is (with-keyboard (read-char *keyboard-input*)) which uses
terminal-raw or some other magic. Following the documentation, it is
forbidden to access *terminal-io* (thus normally also
*standard-output*) while with-keyboard is active. Thus it's also
forbidden to enter the debugger then, if *debug-io* is synonym to
*terminal-io* as usually is the case :-)

All of the above is specific to CLISP.

 >      or is it only implemented in clisp?
That's the answer.

 >      there no way to make a stand alone executable?  Is there some
Why do you absolutely need a stand alone executable? Why can't you
start a binary with some switches?
 >      so, do I have to worry about licensing stuff etc?  
See the newer foreign stuff, which allows you to link .o files to
CLISP, or build an own version of CLISP (primarily add some
functions). In this case, main() remains in the control of CLISP though.

 >      representation into machine instructions."  I was wondering if
Why not use one of the Common-Lisp to C compilers around then?

 	Joerg Hoehle.
[email-masked]