Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: (SOLVED) parsing problems with prototype blocks (updated)

by haukex (Bishop)
on Nov 03, 2021 at 13:57 UTC ( #11138377=note: print w/replies, xml ) Need Help??


in reply to (SOLVED) parsing problems with prototype blocks (precedence)

Unfortunately I think you're right, these are just a few additional thoughts.

that's unfortunate, prototypes don't seem to influence precedence at all

Nitpick: They do influence precedence/parsing, just not in the way you want - from Prototypes:

sub mygrep (&@) mygrep { /foo/ } $a, $b, $c sub myrand (;$) myrand 42
... treated specially by the parser. mygrep() is parsed as a true list operator, myrand() is parsed as a true unary operator with unary precedence the same as rand() ...
$ perl -MO=Deparse,-p -e 'sub myrand (;$) {} rand 123 / rand 456; myra +nd 123 / myrand 456' sub myrand (;$) {} rand((123 / rand(456))); myrand((123 / myrand(456))); $ perl -MO=Deparse,-p -e 'sub mygrep (&@) {} grep {$A} + grep {$B} 1; +mygrep {$A} + mygrep {$B} 1' sub mygrep (&@) {} grep( {$A;} grep( {$B;} 1)); mygrep(sub {$A;}, mygrep(sub {$B;}, 1));

... so builtins do basically behave the same way in terms of precedence - though as of 5.34 there isn't a builtin with a prototype of (&) or even (&@); grep has no prototype, which indicates it is treated specially by the parser (which is why I had to add the 1 after the above grep lest it be a syntax error instead of Not enough arguments).

Update: Relevant: Named Unary Operators

Replies are listed 'Best First'.
Re^2: (SOLVED) parsing problems with prototype blocks (updated)
by LanX (Sage) on Nov 03, 2021 at 16:44 UTC
    On a similar note, I was once experimenting with constants (i.e. sub(){value} with empty prototype) returning objects with overloaded operators.

    I got bitten by the fact that < was interpreted as the start of of a diamond operator, leading to a compilation error.

    (I showed this here, but can't find the thread ATM)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11138377]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (2)
As of 2022-01-19 01:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (54 votes). Check out past polls.

    Notices?