lua-users home
lua-l archive

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


I think that :
x = var1 var2 var3 var4 
should parse as:
x = ((var1(var2))(var3))(var4)
i.e. use the curryfied semantics. If you want to designate var1 as the last function to call with its parameter computed from the others, you'd need to use explicit parentheses to separate it from the rest:
x = var1(var2 var3 var4)
i.e. the "__call" semantics should apply only to the first item to follows, allowing only left-to-right evaluation, It's up to the fist item "called" to decide what to return to process another item after it. If what it returns is not "callable", then the other variables would not be used and a type error would be thrown.

The alternative would be to parse it as: x= var1(var2(var3(var4)))
But I think it is much less flexible.


Le dim. 20 oct. 2019 à 18:20, Jonathan Goble <jcgoble3@gmail.com> a écrit :
On Sun, Oct 20, 2019 at 12:03 PM Mattia Maldini
<mattia512maldini@gmail.com> wrote:
>
> > I think you could achieve the same behaviour easier:
> Yes, but only in the specific case of string concatenation; my idea is to have all generic functions with partial argument invocation and space-separated variable parameters.

The problem is that functions are first-class values, and any object
can be callable if its metatable has a __call metamethod.

So what does this do?

x = var1 var2 var3 var4

Does that become var1(var2, var3, var4), var1(var2(var3, var4)),
var1(var2, var3(var4)), var1(var2(var3), var4), or
var1(var2(var3(var4)))? Remember that passing a function as an
argument to another function is perfectly valid and in many cases
desirable, and anything can be callable.

There's too much ambiguity here for what you want.