使用从字符串读取时如何处理文件结束错误?
How to handle end-of-file error when using read-from-string?
我正在尝试使用函数 read-from-string,但是我不能用它从反面变成正面。
如果我正确理解文档,如果第二个参数不正确,则提供的字符串中的不平衡表达式不应导致错误。但是,如果尝试一下,我会得到:
> (read-from-string "(1 2" t 'EOF)
Condition of type: END-OF-FILE Unexpected end of file on
#<string-input stream from "(1 2">.
Available restarts:
- (RESTART-TOPLEVEL) Go back to Top-Level REPL.
Broken at SI:BYTECODES. [Evaluation of: (READ-FROM-STRING "(1 2" ...)]
In: #<process TOP-LEVEL>.
>> 1
1
>> (read-from-string "(1 2" nil 'EOF)
Debugger received error of type: END-OF-FILE Unexpected end of file on
#<string-input stream from "(1 2">. Error flushed.
无论我发送什么,我总是得到一个错误。
我正在使用 ECL 15.3.7
eof-error-p
和 eof-value
可选参数控制结果,如果你在找到任何东西之前就到达了字符串的末尾。所以:
> (read-from-string "")
Error: ...
而
> (read-from-string "" nil 'foo)
foo
0
如果通过不完整的对象 part-way 出现字符串结尾,则始终会发出错误信号。规范对此很清楚,尽管它在条目下面相当远:
If the end of the supplied substring occurs before an object can be read, an error is signaled if eof-error-p is true. An error is signaled if the end of the substring occurs in the middle of an incomplete object.
我正在尝试使用函数 read-from-string,但是我不能用它从反面变成正面。
如果我正确理解文档,如果第二个参数不正确,则提供的字符串中的不平衡表达式不应导致错误。但是,如果尝试一下,我会得到:
> (read-from-string "(1 2" t 'EOF)
Condition of type: END-OF-FILE Unexpected end of file on #<string-input stream from "(1 2">.
Available restarts:
- (RESTART-TOPLEVEL) Go back to Top-Level REPL.
Broken at SI:BYTECODES. [Evaluation of: (READ-FROM-STRING "(1 2" ...)] In: #<process TOP-LEVEL>.
>> 1
1
>> (read-from-string "(1 2" nil 'EOF)
Debugger received error of type: END-OF-FILE Unexpected end of file on #<string-input stream from "(1 2">. Error flushed.
无论我发送什么,我总是得到一个错误。
我正在使用 ECL 15.3.7
eof-error-p
和 eof-value
可选参数控制结果,如果你在找到任何东西之前就到达了字符串的末尾。所以:
> (read-from-string "")
Error: ...
而
> (read-from-string "" nil 'foo)
foo
0
如果通过不完整的对象 part-way 出现字符串结尾,则始终会发出错误信号。规范对此很清楚,尽管它在条目下面相当远:
If the end of the supplied substring occurs before an object can be read, an error is signaled if eof-error-p is true. An error is signaled if the end of the substring occurs in the middle of an incomplete object.