Programming in Lua 2nd ed says: ".. is the correct associative"

I don’t understand why you mentioned that string concatenation is “correct associative”. Concatenation is associative, so I don’t see how important it is, in what order it is evaluated. Did I miss something?

eg. a^(b^c) == (a^b)^c usually not true, but a..(b..c) == (a..b)..c is. I mean, if you used the concat metamethod for something that doesn't behave like concatenation, it will make a difference, but I don’t understand why anyone would want to do this.

+4
source share
2 answers

It seems that you answered your question, except that you finished it, but I don't see why anyone would want to do that.

It doesn't matter what you think is the correct use of this feature. Lua is a programming language. And there is nothing that programmers love more than abusing a feature of the language on something that is not intended.

To say that this is correct associativity simply provides information to the reader. What you do with this information is up to you.

+2
source

Some information on why .. associativity here right2left here http://lua-users.org/wiki/AssociativityOfConcatenation

This does not quite explain what “speed optimization" is. I understand that he / they came with a concatenated chain, but this could work with the association from left to right ...

0
source

Source: https://habr.com/ru/post/1447770/


All Articles