lua-users home
lua-l archive

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


Le ven. 7 juin 2019 à 17:56, Coda Highland <chighland@gmail.com> a écrit :
On Fri, Jun 7, 2019 at 3:02 AM Philippe Verdy <verdy_p@wanadoo.fr> wrote:
The ":" is a binary operator used in expressions, it is bound to a specific function that creates a binding between to object, that binding being a new object that can be used to perform a function call in a special way (which modifies the list of operands by prepending the first parameter of the binding). The ":" can be used between any pair of objects.


No, that's not true. That's how it works in Python, but in Lua it is NOT a binary operator but rather a part of a ternary function call operator.

But when you parse it, that's what happens: you have to take care of the associativity.

It's just that for now there are additional limitations on the second operand (which can only be a single identifier, limiting its usability, much like "." is limited unless rewritten as "[string _expression_]". The third operand(s) (with or without parentheses around them) do not play any syntaxic role for recognizing ":".

And I don't know if there's any future plan to allow the syntax "a:[string _expression_]()" or allow "a:b" alone or "a:[string _expression_]()" to be a new "functor" object type, i.e. without opening parentheses after it, to generalize the concept of function calls. Arbitrary example showing all cases of use:

   local functor = a:max or a
   x = functor() + functor c + functor(c + 1, x -2)

But that's not what I propose. I'm just limiting myself to the syntactic role (binary associativity) only, rather than semantic (only operators in expressions) which just comes next.