Skip to content

Commit a6b13ba

Browse files
committed
add let() helper for lexical vars
1 parent 782908e commit a6b13ba

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/eval.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ function lazy($exp, $x = 'x')
8686
return ['λ', $x, [$exp, $x]];
8787
}
8888

89+
function let(array $bindings, $body)
90+
{
91+
foreach (array_reverse($bindings) as $name => $value) {
92+
$body = call(['λ', $name, $body], $value);
93+
}
94+
95+
return $body;
96+
}
97+
8998
function to_int($exp)
9099
{
91100
$inc = function ($n) {

0 commit comments

Comments
 (0)