Mystified by end-of-file condition in common lisp
cann't read text file.
READ: input stream #1=# has reached its end [Condition of type SYSTEM::SIMPLE开发者_JAVA百科-END-OF-FILE]
what means is "has reached its end."
Check out the documentation at the HyperSpec:
http://www.lispworks.com/documentation/HyperSpec/Body/f_rd_rd.htm
By default, READ
, READ-CHAR
, and similar functions will signal a condition of type END-OF-FILE
when there's no more data to be read from the stream.
If you want it to instead return a specific value when trying to read past the end of the stream, you'll need to pass a nil
to the eof-error-p
param of the function, and a value, symbol or keyword to the eof-value
parameter of the function; which is the data that you will get back when the end of the file/stream is reached.
For example, if you were reading the chars individually from a piece of text:
(with-open-file (s somefile :direction :input)
(do ((c (read-char s nil :eof)
(read-char s nil :eof)))
((eql c :eof) 'done)
(process-char c)))
It means that you have read all the data available at the location you opened the stream to, and then you tried to read some more.
精彩评论