function resolve_alias($value, $key = NULL) { // Maybe it's a value already? if (key_exists($value, $this->value2key)) { return $value; } $ret = $key ? subscript(subscript($this->aliases, $key), $value) : NULL; if (!is_string($ret)) { $ret = subscript($this->aliases, $value); } if (!is_string($ret)) { _die("value '{$value}' has no alias for key " . ($key == null ? 'nil' : "'{$key}'") . " depath name " . $this->name); } return $ret; }
return $x; }, 'chain' => function ($x, $y, $z) { return $x($z, $y($z)); }, 'zip' => function ($arr1, $arr2) { return foldr(function ($acc, $val) use($arr1, $arr2) { $lookup = subscript($val); $el1 = $lookup($arr1); $el2 = $lookup($arr2); return merge($acc, [[$el1, $el2]]); }, [], keys($arr1)); }, 'dup' => function ($x) { return [$x, $x]; }, 'swap' => function ($arr) { return merge([$arr[1], $arr[0]], array_slice($arr, 2)); }, 'first' => function ($f, $arr) { return cons($f(subscript(0, $arr)), array_slice($arr, 1)); }, 'second' => function ($f) { return compose('swap', first($f), 'swap'); }, 'head' => function ($arr) { return $arr[0]; }, 'delay' => function ($f, $args, $_) { return call_user_func_array($f, $args); }]); defun('format', function ($x) { return is_float($x) ? number_format($x, 6) : (is_array($x) ? map('format', $x) : $x); }); defun('benchmark', function ($f, $x) { $time = microtime(true); $f($x); return microtime(true) - $time; });