Those are basically all meta ops, ops that operate on other ops.
I can interpret your question in a couple ways.
Creating new meta ops
Iirc Larry has said there may one day (years from now) be a simple and convenient official way to add new meta ops without doing explicit direct modifications of the main grammar. But I'm pretty sure there's currently no official way to create new meta operators.
In the meantime it might be reasonable for someone into -Ofun culture to create a slang that adds a meta op.
Slangs are not officially supported. I can't even link to decent currently correct unofficial documentation. I'll just summarize them here.
The term "slang" is short for "sub-language". The full P6 language consists of a collection (called a "language braid") of slangs that can call into, and modify, each others' parsing and/or post-parse-processing. A slang consists of a grammar/actions pair. A grammar is either a special type of class that contains parsing declarations or a role that gets mixed into an existing grammar. An actions class is either a class that contains AST generation or manipulation methods or a role that gets mixed into an existing actions class.
Here's a toy slang demo that just tweaks parsing of identifiers.
Creating/naming ops that are aliases for metaop / op combinations
Is this code of interest?
sub op { @^lhs Z+ @^rhs };
say (1,2) [&op] (3,4); # (4 6)
This creates a function named op that is invoked using either op( arg1, arg2 ) or op arg1, arg2. The function applies the infix metaop Z combined with the infix op + to its left and right arguments. The next line uses this function via another infix metaop [...] where the ... is a named (not called) binary arity routine.
Or:
my &infix:<op> = { @^lhs Z+ @^rhs };
say (1,2) op (3,4); # (4 6)
This creates an infix operator named op. It does the same thing as the op function we created earlier but can be referred to in infix position as just op. (To bring things full circle, you could also write infix:<op>( arg1, arg2 ) or infix:<op> arg1, arg2.)
Or, simplifying / complexifying further:
my &infix:<op> = &[Z+];
say (1,2) op (3,4); # (4 6)
The syntax &[...] parses the ... part as an infix operator and returns the resulting routine. |