开发者

Mystified by end-of-file condition in common lisp

开发者 https://www.devze.com 2022-12-13 20:54 出处:网络
cann\'t read text file. READ: input stream #1=# has reached its end [Condition of type SYSTEM::SIMPLE开发者_JAVA百科-END-OF-FILE]

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消