[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [Proposal] Overload | for booleans
 
- From: Tim Hill <drtimhill@...>
 
- Date: Wed, 29 Jul 2015 11:05:04 -0700
 
> On Jul 29, 2015, at 7:53 AM, Soni L. <fakedme@gmail.com> wrote:
> 
> 
> 
> On 29/07/15 11:18 AM, Dirk Laurie wrote:
>> 2015-07-29 15:56 GMT+02:00 Soni L. <fakedme@gmail.com>:
>> 
>>> Can we get true | false to be a thing?
>> debug.setmetatable(true,{
>>   __bor = function(x,y)
>>     assert (type(x)=='boolean' and type(y)=='boolean')
>>     return x or y
>>   end;
>>     __band = function(x,y)
>>     assert (type(x)=='boolean' and type(y)=='boolean')
>>     return x and y
>>   end;
>> })
>> 
>> I like that! But why do you call it a proposal?
>> 
> It would be non-short-circuiting and/or.
> 
> -- 
> Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.
> 
> 
function andx(c1, c2) return c1 and c2 end
function orx(c1, c2) return c1 or c2 end
...
if andx(a < 100, b > 300) then … end
etc. And of course easy to extend andx() and orx() to take varargs for as many expressions as you want.
—Tim