为什么这不是语法错误? [英] Why is this not a syntax error?

查看:58
本文介绍了为什么这不是语法错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我这样做:

(false true)

正如我所料,它因语法错误而失败.但如果我这样做:

it fails with a syntax error, as I expect. But if I do this:

(false
 true)

代码被执行,它丢弃第一个条件并返回第二个条件.

the code is executed, and it throws away the first condition and returns the result of the second.

这被认为是错误还是功能?

Is this considered a bug or a feature?

推荐答案

行尾是可选的,因此在这种情况下,返回导致解析器将其解释为以下内容:

Line endings are optional, so in this case, the return is causing the parser to interpret it as the following:

(false; true)

计算结果为:

(true)

如果这些是方法调用,那么两者都会被评估,但只会发出最后一个.例如:

If these were method calls then both would be evaluated, but only the last would be emitted. For example:

x = (p "hello"
p "world"
2)

这将输出hello"和world",x 将等于 2

This will output "hello" and "world" and x will equal 2

这篇关于为什么这不是语法错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆