gpt4 book ai didi

julia - parse() 什么时候应该抛出错误?

转载 作者:行者123 更新时间:2023-12-03 20:20:39 25 4
gpt4 key购买 nike

我正在交互式运行:

Julia Version 0.4.0-dev+1903
Commit 6b0fcce (2014-11-30 18:08 UTC)

从这里在 Base.parse 的文档中:

http://julia.readthedocs.org/en/latest/stdlib/base/?highlight=parse#Base.parse

我读到这个:

If raise is true (default), syntax errors will raise an error; otherwise, parse will return an expression that will raise an error upon evaluation.



当我这样做时,它的工作原理如下:
julia> parse("end")
ERROR: ParseError("unexpected end")

但当我这样做时不会:
julia> parse("println(")
:($(Expr(:incomplete, "incomplete: premature end of input")))
julia> eval(ans)
ERROR: syntax: incomplete: premature end of input

这是预期的行为吗? parse() 在第二种情况下应该抛出错误,还是应该等到 eval()

最佳答案

在这种情况下,解析应该引发错误。根据 Simon Byrne 的评论,我发布了一个 GitHub 问题,该问题已经有一个拉取请求等待关闭它:https://github.com/JuliaLang/julia/pull/9514/

谢谢大家!

关于julia - parse() 什么时候应该抛出错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27429182/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com