Beispiel #1
0
    }, 0, $x)) !== $x;
}, 'loop1' => function ($x) {
    $n = $x % 8;
    $lhs = loop(function ($x, $m) use($n) {
        return [$m >= $n, snoc($m, $x)];
    }, []);
    $rhs = upto($n + 1);
    return $lhs === $rhs ? 0 : dump(get_defined_vars());
}, 'y1' => function ($x) {
    $n = $x % 4;
    return y(function ($f, $m) use($n) {
        return $m === $n ? $m : $f($m + 1);
    }, 0) !== $n;
}, 'stream_take1' => function ($x) {
    $n = $x % 8;
    $lhs = upto($n);
    $rhs = stream_take($n, y(function ($f, $n, $_) {
        return [$n, $f($n + 1)];
    }, 0));
    return $lhs === $rhs ? 0 : dump(get_defined_vars());
}, 'tabulate1' => function ($a, $b, $c, $d, $e, $f) {
    $result = tabulate($a, $b, [$c => $d, $e => $f]);
    return strpos($result, "{$c} {$d}") === FALSE;
}, 'tabulate2' => function ($a, $b, $c, $d, $e, $f) {
    $result = tabulate($a, [$b], [$c => $d]);
    return strpos($result, "{$a} {$b}") === FALSE;
}, 'fanout' => function ($x) {
    list($s, $m) = fanout(['strval', 'minus'], $x);
    if ($s !== strval($x)) {
        return true;
    }
Beispiel #2
0
{
    $args = func_get_args();
    $f = op(array_shift($args));
    return function () use($args, $f) {
        static $curried = true;
        return call_user_func_array('call_user_func', array_merge($args, func_get_args()));
    };
}
defun('parens', function ($x) {
    return "({$x})";
});
defun('upto', function ($n) {
    return $n ? range(0, $n - 1) : [];
});
defun('between', function ($x, $y) {
    return $x - $y ? map(plus($x), upto($y - $x + 1)) : [];
});
defun('branch', function ($then, $else, $condition, $x) {
    return $condition($x) ? $then($x) : $else($x);
});
defun('fanout', function ($funcs, $x) {
    return map(with($x), $funcs);
});
defun('until', function ($f, $x) {
    return loop(function ($y, $n) use($f) {
        return $f($y);
    }, $x);
});
defun('loop', function ($f, $acc) {
    return trampoline(y(function ($y, $f, $n, $x, $_) {
        list($stop, $x) = $f($x, $n);