Feather2 / documentation / PosfixFunctions.md
Postfix Function
EXPERIMENTAL
This is an experimental feature, and may be removed in later versions.
Postfix functions take the form :
a : myFunction( arg1, arg2 )
In this example, there are two additional arguments, but any number are allowed, including zero.
This is equivalent to :
a.myFunction( arg1, arg2 )
Where myFunction
is a non-static method, which takes 2 arguments.
Or :
myFunction( a, arg1, arg2 )
Where myFunction
is a static method, which takes 3 arguments.
Postfix functions have the highest precedence (which means they are evaluated last). Consider these two expressions, the order of evaluation is different :
a + b.myFunction()
a + b : myFunction()
The first one is equivalent to a + (b.myFunction())
.
But the second one is equivalent to (a + b).myFunction()
.
Postfix functions were added to the language to avoid additional brackets, which can make code tricky to read.
They are particularly handy when using eval
or run
in conjunction wih complicated
Commands. e.g.
$( grep Hello ).pipe( $( wc ) < "file.txt" : eval()
Limitations
The only thing to the right of a postfix call is another postfix call. For example, this is illegal :
a + b : myFunction() + 1
I'd like this to be legal, and equivalent to :
( a + b ).myFunction() + 1
But my ANTLR skills aren't good enough to achieve it. I suspect, I'd need to rewrite the entire grammar.