[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

MAKE-ECHO-STREAM, and related issues



Assuming that "FOO" is a file containing the single character "X", consider
the expression:

(WITH-OPEN-FILE ((STREAM "FOO" :DIRECTION :INPUT))
  (LET ((ECHO-STREAM (MAKE-ECHO-STREAM STREAM *TERMINAL-IO*)))
    (PEEK-CHAR ECHO-STREAM)
    (PRIN1 'FOO)
    (READ-CHAR ECHO-STREAM)))

Should this print "XFOO" or "FOOX"? I'll argue strongly that it's pretty 
critical that it be "XFOO" since it's easy for the user to simulate the
"FOOX" behavior and next to impossible to simulate the other behavior. 
Does anybody buy that? Can anyone find a passage in CLtL where it says 
one way or the other what happens in this case? The doc on p330 is 
completely vague on the issue.

In general, I think we should be clear on the fact that any peek operation
must not echo. For example, a system which is full duplex and not 
line-at-a-time (and hence must decide to echo the char either at the first
peek-char or at the read-char) should wait until the read. Among other 
things, failure to do this keeps you from writing a reader which can 
correctly handle a prompted read of foo'foo as two separate expressions.
You end up seeing:
 Form: foo'
 Form: foo
rather than
 Form: foo
 Form: 'foo
 Form:
On a line-at-a-time system, where the input is echoed at prescan time, you
end up seeing:
 Form: foo'foo
 Form:
 Form:
which is not optimal, but is probably tolerable since users of such systems
are probably used to this sort of effect. In fact, using LISTEN, you can can
write something which (barring timing errors due to high-speed typists) 
heuristically manages to optimize out the intermediate prompt.

Would people be willing to agree that we should have a way to detect whether 
the terminal, implementation, or whatever was line-at-a-time or not, or is
that too ill-defined? It would certainly be very useful to code which wants
to do something graceful in the face of radically varying styles of input
scanning.