Z Combinator for self-referencing anonymous functions
This library provides a utility function to support the creation of self-referencing anonymous functions.
It can be installed in whichever way you prefer, but I recommend NPM.
var z = require'z-combinator';// Factorialvar factorial = zreturnreturn 2 >= n ? n : n * fnn - 1;;factorial2 // => 2factorial3 // => 6factorial4 // => 24factorial5 // => 120
Just as you would with any other recursive function, make sure you include some sort of break condition. If you miss it out, the function will recur indefinitely.
var z = require'z-combinator';zreturnreturn fnn + 1; // <= Unconditional recursion;0;// => Error: Maximum call stack exceededzreturnreturn 100 <= n ? n : fnn + 1; // <= Conditional recursion;0;// => 100
I accept contributions to the source via Pull Request, but passing unit tests must be included before it will be considered for merge.
$ make install$ make tests
If you have Vagrant installed, you can build the dev environment to assist development.
The repository will be mounted in
$ vagrant up$ vagrant sshWelcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64)$ cd /srv