lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Luiz Henrique de Figueiredo writes:
> I'd rather write this is as
> 	a(1,("x" .. "y"),2).
> and have the lexer do the optimization.

But isn't that a problem since ".." is right-associative?

  local c = setmetatable({}, {__concat = function(x,y) return "d" end })
  print("a" .. "b" .. c) --> "ad"

I suppose this could require an very long look-ahead (~ 2*LUAI_MAXCALLS), or one
could initially assume the concatenation only involves constants (the common
case) and backtrack or correct (e.g. string split) if not.

This revisits the question of why concatenation is right associative[1].  In
particular, using the default value of LUAI_MAXCALLS, you cannot concatenate
more than 199 values at a time.

[1] http://lua-users.org/wiki/AssociativityOfConcatenation