Anonymous functions are one of my favorite language features. I don’t think I could work with a language that doesn’t have them (here’s lookin’ at you, java 7).
The first way to go about anonymous functions is via the fn keyword.
Since one can call a function with the form (function arg1 arg2 arg3)
we could call this function like so:
Kind of like doing the following in JS:
I love this second method. In general, I love any anonymous function shorthand. C#’s/LINQ’s j => j
for instance is a personal favorite.
Here’s the %
based version, note that there are two different ways to use it. Both start with a #
at the beginning:
So in the above version, %
refers to the one and only argument.
If you have multiple arguments, then there is a different way of using %
:
So you can use %[arg number]
to reference multiple arguments.