为什么Lua会像它那样进行比较?

Seg*_*ult 2 comparison lua

如果标题没有多大意义,请原谅我.我不得不选择Is Lua的比较方式有用吗?Lua的比较.

我今天想做这样的事情:

 if currChar == nextChar == "-" then
    ... 
 end
Run Code Online (Sandbox Code Playgroud)

但它false每次都会回来:

> currChar="-"
> nextChar="-"
> =currChar == nextChar == "-"
false
>
-- All true in Python
print(5 == 5)                    -- true
print(5 == 5 == 5)               -- false
print((5 == 5) == (5 == 5))      -- true
print(5 == (4 + 1) == (6 - 1))   -- false
Run Code Online (Sandbox Code Playgroud)

我在一段时间内摆弄了这些值,并发现由于某种原因,Lua从左到右成对地比较值:

> = 52 > 3 > 2
stdin:1: attempt to compare number with boolean
stack traceback:
        stdin:1: in main chunk
        [C]: in ?
>
Run Code Online (Sandbox Code Playgroud)

我有一种情况,这种形式的比较是有用的吗?
为什么比较那样?

Dav*_*ave 5

Lua的比较运算符是真正的二元运算符.他们在两个操作数上工作,就是这样.在Lua中,5 == 5 == 5被评估为(5 == 5) == 5,简化为True == 5和错误.另一方面,在Python中,5 == 5 == 5被评估为5 == 5 and 5 == 5,这是真的.

Python在支持比较运算符的链接方面是非典型的,x < y < z转换为x < y and y < z.我知道支持该语法的语言并不多.

至于它是否有用,那完全是武断的.链接语法只是简写.