简体   繁体   English

Lua 2nd ed中的编程说“ ..是正确的关联”

[英]Programming in Lua 2nd ed says “.. is right associative”

I don't understand why you'd mention that string concatenation is "right associative". 我不明白为什么您会提到字符串连接是“正确的关联”。 Concatenation is associative, so I don't see how it matters in what order Lua evaluates it. 串联是关联的,所以我看不出Lua以什么顺序评估它有多重要。 Am I missing something? 我想念什么吗?

Eg a^(b^c) == (a^b)^c is not generally true, but a..(b..c) == (a..b)..c is. 例如a^(b^c) == (a^b)^c通常不是真的,但是a..(b..c) == (a..b)..c是。 I mean suppose if you'd use the concat metamethod for something that doesn't behave like concatenation it would matter, but I don't see why anyone would want to do that. 我的意思是假设如果您将concat元方法用于行为不像串联的事情,那将很重要,但是我不明白为什么有人会这样做。

You seem to have answered your own question, except you ended it with, but I don't see why anyone would want to do that. 您似乎已经回答了自己的问题,只是您以结束而已, but I don't see why anyone would want to do that.

It doesn't matter what you think is an appropriate use of the feature. 认为适当使用该功能并不重要。 Lua is a programming language . Lua是一种编程语言 And there is nothing programmers love more than to abuse a feature in the language for something that is not intended. 程序员除了无意中滥用该语言的功能外,没有什么比程序员更喜欢的了。

Saying that it is right associative is simply providing information to the reader. 说它是正确的关联只是向读者提供信息。 What you do with that info is up to you. 您可以根据自己的意愿来处理该信息。

Some info on why .. associativity is right2left here http://lua-users.org/wiki/AssociativityOfConcatenation 有关为何..关联正确的一些信息,请参见此处http://lua-users.org/wiki/AssociativityOfConcatenation

It does not quite explain what that "speed optimization" was though. 它并没有完全解释“速度优化”是什么。 I understand he/they came with concat chaining but that could have worked with left-to-right associativity too... 我了解他/他们采用了concat链接,但是也可以实现从左到右的关联性...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM