The following code:
(defun prompt () (do ((line nil (and (listen) (read)))) ((eq line 'q)) (when line (print line)) (print '>) (sleep 5)))
when run in directly in the clisp interpreter in a shell, will output a > every 5 seconds, and print out any symbols entered until q is entered.
when run under slime, only > is printed every 5 seconds, the input is not printed out, instead a message in the minibuffer says: ; pipelined request... (swank:listener-eval "<input>")
Anyway to make this work? (I'm trying to do some processing in between user input.) I'm running clisp 2.34, slime 1.2.1, emacs 21.3.1 and windows xp.
Thanks, Dan
Daniel Patru writes:
The following code:
(defun prompt () (do ((line nil (and (listen) (read)))) ((eq line 'q)) (when line (print line)) (print '>) (sleep 5)))
when run in directly in the clisp interpreter in a shell, will output a > every 5 seconds, and print out any symbols entered until q is entered.
when run under slime, only > is printed every 5 seconds, the input is not printed out, instead a message in the minibuffer says: ; pipelined request... (swank:listener-eval "<input>")
Anyway to make this work? (I'm trying to do some processing in between user input.) I'm running clisp 2.34, slime 1.2.1, emacs 21.3.1 and windows xp.
You should have some notion of buffered vs. unbuffered I/O. This is basic CS stuff.
In lisp, this means use: FINISH-OUTPUT.
* Daniel Patru [2005-11-04 03:27+0100] writes:
Anyway to make this work? (I'm trying to do some processing in between user input.)
As Pascal Bourguignon said, you should flush the output buffer.
But you also need to be careful with LISTEN. Actually reading from *standard-input* in SLIME is a bit weird. LISTEN (in SLIME) returns true if there is any buffered input, e.g. if you call READ-CHAR the Emacs REPL buffer switches to "read-mode" and the next time you press return the entire line gets buffered.
Also note that the REPL buffer is usually not in "read-mode" and that pressing return (usually) doesn't write anything to the input buffer. Keep an eye on the modeline, there is an indicator [read] if the REPL is in read-mode.
Some other issues are:
- buffered input is discarded before evaluation requests i.e. about every time when SLIME prints a prompt. (This means that LISTEN returns false most of the time.)
- if you want to send an "end-of-transmission" (like C-d in a terminal) you have to press C-u RET.
Your example works a bit better if you write it like this:
(defun prompt () (do ((line nil (read))) ((eq line 'q)) (when line (print line)) (print '>) (finish-output) (sleep 1)))
Helmut.