Amb - non-deterministic operators
use Amb; if ( amb(1,0)) { print "failure"; die; } else { print "success" }
will print 'failure' and then 'success'.
There exist two kinds of non-deterministic operators, 'angelic' and 'demonic', that accept two parameters, and return one of them depending whether the result will lead to failure (die, in perl world) or success. Angelic operators will return the parameter that won't lead to the branch that dies. Demonic operators, on the contrary, return the parameter that leads to the branch that dies.
die
The non-deterministic operators are usually implemented using continuations. Perl5 lacks these, so this implementation hacks the optree to achieve the result. The side effect of this is that branches won't backtrack, and can be thought of as non-deterministic operators implemented with goto.
goto
amb, the only operator exported by default, is an angelic operator. Returns either arg1 or arg2, depending on which one won't lead do die call. If all branches lead to die call, dies itself.
amb
Same as amb
Returns the argument that will lead to die.
Since amb() is implemented with hacking op-tree, there are currently a number of untested calling combinations, that might fail or even coredump. For example, calling amb() like
amb()
my $a = amb(@a); if ( $a) ...
won't work. The only tested (and yet, up to a point) calling sequence is
if ( amb(@a) { ... } else { ... }
Other call styles are obliviously untested, so beware.
The module requires latest development version of B::Generate, which doesn't build on MSWin32. Apply patch from http://rt.perl.org/rt3/Public/Bug/Display.html?id=56536 and recompile perl.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Dmitry Karasik, <dmitry@karasik.eu.org>.
To install Amb, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Amb
CPAN shell
perl -MCPAN -e shell install Amb
For more information on module installation, please visit the detailed CPAN module installation guide.