develooper Front page | perl.perl6.users | Postings from June 2020

Re: junctions and parenthesis

Thread Previous | Thread Next
From:
Elizabeth Mattijsen
Date:
June 22, 2020 19:38
Subject:
Re: junctions and parenthesis
Message ID:
3BF154B7-D18D-4207-AF7F-F1644B6A157A@dijkmat.nl
BEGIN trait_mod:<is>(&any, :tighter(&infix:<*>));

comes to mind, but that doesn't seem to do the trick.

> On 22 Jun 2020, at 21:11, Tobias Boege <tobs@taboege.de> wrote:
> 
> On Mon, 22 Jun 2020, Joseph Brenner wrote:
>> Patrick R. Michaud <pmichaud@pobox.com> wrote:
>> 
>>> The "any" function is just like any other function taking an arbitrary list
>>> of arguments (including user-defined functions).  As such it parses with
>>> lower precedence than comparison operators -- so "eq" binds more tightly
>>> than "any".
>> 
>> Thanks, makes sense.
>> 
>>> I'm not exactly sure what sort of warning should go here, or how it'd be
>>> detected.
>> 
>> Yes, exactly.  From one point of view it's working as designed-- to me
>> it felt pretty weird, though.
>> 
>> Speculating wildly:  could there be a need for a different type of
>> function with different precedence?
>> 
> 
> You can achieve this today by redefining &any to be a prefix operator
> and provide it with tight enough precedence. In this example, I pick
> infix multiplication as the argument stopper, which is in particular
> tighter than the relevant eq operator; your mileage may vary:
> 
>  sub old-any (|c) { CORE::{'&any'}.(|c) }
> 
>  multi prefix:<any> (|c) is tighter(&infix:<*>) {
>      old-any |c
>  }
> 
>  say so any <a b c> eq any <c d>;            # True (fixed)
>  say so old-any(<a b c>) eq old-any(<c d>);  # True
>  say so old-any <a b c>  eq old-any <c d>;   # False
> 
> Now I'd be interested to see how someone would turn this into a
> frugal-sub declarator or an `is frugal` trait.
> 
> Regards,
> Tobias
> 
> -- 
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About