public function testWhoCares() { $x = callFresh(function ($q) { return fives($q); }); $result = $x(emptyState()); $this->assertEquals('((((#(0) . 5)) . 1))', sprintf('%s', take(1, $result))); }
public function testDisjPlus() { $x = callFresh(function ($q) { return disjPlus(eq($q, 1), eq($q, 2), eq($q, 'a')); }); $result = $x(emptyState()); $this->assertEquals('((((#(0) . 1)) . 1) . ((((#(0) . 2)) . 1) . ((((#(0) . a)) . 1))))', sprintf('%s', take(3, $result))); }
/** * Recursively builds calls to callFresh for fresh. * * Largely taken from the Underscore contributers' library implementation of * curry: http://git.io/eUBA5Q * * Thanks to @obmarg for the pointer. */ function collectArgs($f, $argCount, $args, $arg) { $args[] = $arg; if (count($args) === $argCount) { return call_user_func_array($f, $args); } else { return callFresh(function ($x) use($f, $argCount, $args) { return collectArgs($f, $argCount, $args, $x); }); } }
function manyNonAns() { return callFresh(function ($x) { return disj(relo(cons(5, 6)), eq($x, 3)); }); }