[Ecls-list] About unread-char and bidirectional streams
Juan Jose Garcia-Ripoll
juanjose.garciaripoll at googlemail.com
Thu Jan 1 10:59:57 UTC 2009
[CC of a message from comp.lang.lisp]
Given the following piece of code, which behavior do you find more
correct of the ones shown below?
(with-open-file (s "foo.txt" :direction :io :if-exists :supersede)
(write-line (print "abcdefghijk") s)
(file-position s 0)
(let (a)
(print (list (file-position s)
(setf a (read-char s))
(file-position s)
(unread-char a s)
(file-position s)
(write-char #\x s)
(file-position s)
(read-char s)
(file-position s)
(read-char s))))
(file-position s 0)
(print (read-line s)))
Basically the problem relates to the value of file-position and the
actual place where data is written right after an unread-char
operation. This behavior also affects the behavior of an
implementation when reading, for instance, a Return + Linefeed
sequence.
Is this simply undefined? I found the section on streams in the ANSI
specification to be, say, lacking in all aspects, hehe.
This is SBCL 1.0.10, an implementation of ANSI Common Lisp.
"abcdefghijk"
(0 #\a 1 NIL 0 #\x 1 #\a 2 #\b)
"abxdefghijk"
ECL (Embeddable Common-Lisp) 8.12.0 (CVS 2008-07-12 18:54)
"abcdefghijk"
(0 #\a 1 NIL 1 #\x 2 #\a 2 #\c)
"axcdefghijk"
Welcome to GNU CLISP 2.45 (2008-04-04) <http://clisp.cons.org/>
"abcdefghijk"
(0 #\a 1 NIL 0 #\x 1 #\a 2 #\c)
"axcdefghijk"
--
Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28009 (Spain)
http://juanjose.garciaripoll.googlepages.com
More information about the ecl-devel
mailing list