lua-users home
lua-l archive

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


On Feb 19, 2010, at 3:53 AM, Roberto Ierusalimschy wrote:

>> I realise I've probably missed the boat by a long time for 5.2, but
>> could I politely ask that you consider changing relational operators
>> so that you can compare between objects with different metatables, and
>> so that the operators can return results other than true or false?
>> 
>> Is this of interest to anyone else?  (I'd like to use it to write lp
>> constraints: x + y <= 3, rather than rima.constraint:new(x + y, "<=",
>> 3) )
> 
> We are considering the first change (compare objects with different
> metatables). The second one is more complex, because it is more
> ingrained. Even the opcodes for these operations assume boolean results:
> 
>  OP_LT,/*        A B C   if ((RK(B) <  RK(C)) ~= A) then pc++            */
>  OP_LE,/*        A B C   if ((RK(B) <= RK(C)) ~= A) then pc++            */
> 
> This is not reason enough not to change, but it is something to be
> weighted.


Maybe instead what is needed is an expression tree notion and a syntax to invoke it. The benefit of this over just using strings is that the compiler can syntax check the expressions rather than having to wait until runtime to check them (and editors can do appropriate highlighting).

Mark