Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Create a new operator, get LHS

by raiph (Deacon)
on Sep 11, 2015 at 15:50 UTC ( [id://1141680]=note: print w/replies, xml ) Need Help??


in reply to Create a new operator, get LHS

»»» This post is about alpha status Perl 6, not rock solid Perl 5 «««

In Perl 6, operators are defined by subs. Operator subs have to have an appropriate name and signature. They get automatically added to the Perl 6 grammar in the current lexical scope as soon as their name and signature have been successfully parsed.

For example, infix operators have a name of the form 'infix:<op>' and two parameters. So the code:

sub infix:<foo> ($lhs, $rhs) { dd $lhs }; sub infix:<in> ($lhs, @rhs) { dd @rhs }; 1 foo 2; 3 in [3,4];
prints (via `dd`, the built in datadumper):
$lhs = 1 @rhs = [3, 4]

For more details start at the Defining Operators section in the official end user doc.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-03-29 00:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found