On Jan 5, 2010, at 1:23 AM, Helmut Eller wrote:
- Terje Norderhaug [2010-01-01 06:23+0100] writes:
One way to have the REPL respect reader macro characters is by making evaluation on swank return the index of the first character not read, with the client using this as the starting position for the next read.
Nice idea. But there are still problems with reader macros. E.g. input like
(progn #.(print 'foo) <RET> )
would print FOO twice.
Yes, this idea assumes that reader macros don't have side effects besides the reading from the stream.
Fortunately X3J13 comes to the rescue. According to the Hyperspec:
"The reader macro function must not have any side effects other than on the input stream; because of backtracking and restarting of the read operation, front ends to the Lisp reader (e.g., ``editors'' and ``rubout handlers'') may cause the reader macro function to be called repeatedly during the reading of a single expression in which x only appears once."
http://www.lispworks.com/documentation/HyperSpec/Body/02_b.htm
If you want to add this kind of state to the protocol it might be easier to make the REPL read from a custom stream. The stream informs Emacs when more input is requested. The REPL in turn tells Emacs when to print results and prompts.
I agree that using a stream and maintaining REPL state would be a beneficial upgrade, perhaps as a next step. Particularly as it is hard to enforce the prohibition on side effects for CL reader macros, but also as other lisp dialects may not require side effect free reader macros.
-- Terje Norderhaug terje@in-progress.com