简体   繁体   中英

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. Am I missing something?

Eg a^(b^c) == (a^b)^c is not generally true, but a..(b..c) == (a..b)..c is. 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.

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.

It doesn't matter what you think is an appropriate use of the feature. Lua is a programming language . 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

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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