Re: [perl #130540] [BUG] || && and or cannot be "overloaded"

2017-01-12 Thread Bart Wiegmans
I'm not sure if this adds anything, but:
The reason why infix<||> doesn't work as you'd expect, is that operators
like '||' and '&&' operate on expressions, that is to say code, rather than
on values.
The only valid way to extend such operators is to either use macros (which
would receive both sides as arguments) or to create 'thunks' out of both
sides.
Either way, a sub that takes value arguments is incompatible with the
short-circuiting semantics, and I think it should fail at compile time.

Regards,
Bart

2017-01-11 23:42 GMT+01:00 Fernando Oliveira :

> But should those 2 forms behave differently?
>
> 20:40  m: multi infix:<||>(42, 42) {"OK"}; say
> infix:<||>(42, 42); say 42 || 42
> 20:40  rakudo-moar 8f3476: OUTPUT«OK␤42␤»
>
> Enviado do meu iPhone
>
> > Em 11 de jan de 2017, às 20:20, jn...@jnthn.net via RT <
> perl6-bugs-follo...@perl.org> escreveu:
> >
> >> On Tue, 10 Jan 2017 17:59:05 -0800, c...@zoffix.com wrote:
> >>> On Tue, 10 Jan 2017 16:23:18 -0800, fernandocor...@gmail.com wrote:
> >>> If I write another || operator it will continue to use the original
> >>> version.
> >>>
> >>> https://irclog.perlgeek.de/perl6/2017-01-10#i_13895823
> >>> 
> >>
> >> To save other readers sifting through the chan log... Even an only sub
> >> doesn't take root:
> >>
> >>  m: sub infix:<||> ($, $) {"hi"}; say 42 || 55
> >>  rakudo-moar 9a11ea: OUTPUT«42␤»
> >>
> >> This applies to &&, and, or, and I'd guess any shortcurcuiting
> >> operator.
> >
> > These are special compiler forms that receive special code-gen, due to
> their shortcircuiting nature, and so do not result in sub calls. Thus
> there's no sub to override.
> >
>


Re: [perl #130540] [BUG] || && and or cannot be "overloaded"

2017-01-12 Thread Fernando Oliveira
But should those 2 forms behave differently?

20:40  m: multi infix:<||>(42, 42) {"OK"}; say infix:<||>(42, 
42); say 42 || 42
20:40  rakudo-moar 8f3476: OUTPUT«OK␤42␤»

Enviado do meu iPhone

> Em 11 de jan de 2017, às 20:20, jn...@jnthn.net via RT 
>  escreveu:
> 
>> On Tue, 10 Jan 2017 17:59:05 -0800, c...@zoffix.com wrote:
>>> On Tue, 10 Jan 2017 16:23:18 -0800, fernandocor...@gmail.com wrote:
>>> If I write another || operator it will continue to use the original
>>> version.
>>> 
>>> https://irclog.perlgeek.de/perl6/2017-01-10#i_13895823
>>> 
>> 
>> To save other readers sifting through the chan log... Even an only sub
>> doesn't take root:
>> 
>>  m: sub infix:<||> ($, $) {"hi"}; say 42 || 55
>>  rakudo-moar 9a11ea: OUTPUT«42␤»
>> 
>> This applies to &&, and, or, and I'd guess any shortcurcuiting
>> operator.
> 
> These are special compiler forms that receive special code-gen, due to their 
> shortcircuiting nature, and so do not result in sub calls. Thus there's no 
> sub to override.
> 


[perl #130540] [BUG] || && and or cannot be "overloaded"

2017-01-12 Thread via RT
# New Ticket Created by  fernandocor...@gmail.com 
# Please include the string:  [perl #130540]
# in the subject line of all future correspondence about this issue. 
# https://rt.perl.org/Ticket/Display.html?id=130540 >


If I write another || operator it will continue to use the original version.

https://irclog.perlgeek.de/perl6/2017-01-10#i_13895823 



Re: [perl #130540] [BUG] || && and or cannot be "overloaded"

2017-01-12 Thread Elizabeth Mattijsen

[10:04:44]  re the shortcircuiting behaviour of && || and friends, 
and the fact you cannot override them (RT #130540)
[10:05:09]  I wonder whether we perhaps need a new kind of 
signature that would make this work:
[10:05:20]  sub a(*@a) { dd @a.shift }; my $a = 0; a $a++,$a++; dd 
$a   # sorta expected to see $a = 1 here
[10:05:27]  m: sub a(*@a) { dd @a.shift }; my $a = 0; a $a++,$a++; 
dd $a
[10:05:27] rakudo-moar 8f3476: OUTPUT«0␤Int $a = 2␤»
[10:05:52]  aka, a lazy slurpy signature
[10:06:41]  which would allow && || and friends to become full HLL 
citizens, rather then needing to be handled at codegen level and thus make them 
unoverridable

> On 12 Jan 2017, at 06:28, Lloyd Fournier  wrote:
> 
> There is a :<&&> which might be where some confusion comes from. I 
> guess that's there for meta operators. For example:
> multi sub infix:<&&>("foo","bar") { "win" };
> say "foo" && "bar" # bar
> say  Z&&  # win
> 
> so it does kinda work actually just not as you might expect.
> 
> LL
> 
> 
> On Thu, Jan 12, 2017 at 9:21 AM jn...@jnthn.net via RT 
>  wrote:
> On Tue, 10 Jan 2017 17:59:05 -0800, c...@zoffix.com wrote:
> > On Tue, 10 Jan 2017 16:23:18 -0800, fernandocor...@gmail.com wrote:
> > > If I write another || operator it will continue to use the original
> > > version.
> > >
> > > https://irclog.perlgeek.de/perl6/2017-01-10#i_13895823
> > > 
> >
> > To save other readers sifting through the chan log... Even an only sub
> > doesn't take root:
> >
> >  m: sub infix:<||> ($, $) {"hi"}; say 42 || 55
> >  rakudo-moar 9a11ea: OUTPUT«42␤»
> >
> > This applies to &&, and, or, and I'd guess any shortcurcuiting
> > operator.
> 
> These are special compiler forms that receive special code-gen, due to their 
> shortcircuiting nature, and so do not result in sub calls. Thus there's no 
> sub to override.


Re: [perl #130540] [BUG] || && and or cannot be "overloaded"

2017-01-11 Thread Lloyd Fournier
There is a :<&&> which might be where some confusion comes from. I
guess that's there for meta operators. For example:

multi sub infix:<&&>("foo","bar") { "win" };
say "foo" && "bar" # bar
say  Z&&  # win

so it does kinda work actually just not as you might expect.

LL

On Thu, Jan 12, 2017 at 9:21 AM jn...@jnthn.net via RT <
perl6-bugs-follo...@perl.org> wrote:

> On Tue, 10 Jan 2017 17:59:05 -0800, c...@zoffix.com wrote:
> > On Tue, 10 Jan 2017 16:23:18 -0800, fernandocor...@gmail.com wrote:
> > > If I write another || operator it will continue to use the original
> > > version.
> > >
> > > https://irclog.perlgeek.de/perl6/2017-01-10#i_13895823
> > > 
> >
> > To save other readers sifting through the chan log... Even an only sub
> > doesn't take root:
> >
> >  m: sub infix:<||> ($, $) {"hi"}; say 42 || 55
> >  rakudo-moar 9a11ea: OUTPUT«42␤»
> >
> > This applies to &&, and, or, and I'd guess any shortcurcuiting
> > operator.
>
> These are special compiler forms that receive special code-gen, due to
> their shortcircuiting nature, and so do not result in sub calls. Thus
> there's no sub to override.
>


[perl #130540] [BUG] || && and or cannot be "overloaded"

2017-01-11 Thread jn...@jnthn.net via RT
On Tue, 10 Jan 2017 17:59:05 -0800, c...@zoffix.com wrote:
> On Tue, 10 Jan 2017 16:23:18 -0800, fernandocor...@gmail.com wrote:
> > If I write another || operator it will continue to use the original
> > version.
> >
> > https://irclog.perlgeek.de/perl6/2017-01-10#i_13895823
> > 
> 
> To save other readers sifting through the chan log... Even an only sub
> doesn't take root:
> 
>  m: sub infix:<||> ($, $) {"hi"}; say 42 || 55
>  rakudo-moar 9a11ea: OUTPUT«42␤»
> 
> This applies to &&, and, or, and I'd guess any shortcurcuiting
> operator.

These are special compiler forms that receive special code-gen, due to their 
shortcircuiting nature, and so do not result in sub calls. Thus there's no sub 
to override.


[perl #130540] [BUG] || && and or cannot be "overloaded"

2017-01-10 Thread Zoffix Znet via RT
On Tue, 10 Jan 2017 16:23:18 -0800, fernandocor...@gmail.com wrote:
> If I write another || operator it will continue to use the original
> version.
> 
> https://irclog.perlgeek.de/perl6/2017-01-10#i_13895823
> 

To save other readers sifting through the chan log... Even an only sub doesn't 
take root:

 m: sub infix:<||> ($, $) {"hi"}; say 42 || 55
 rakudo-moar 9a11ea: OUTPUT«42␤»

This applies to &&, and, or, and I'd guess any shortcurcuiting operator.