aboutsummaryrefslogtreecommitdiff
path: root/php/step9_interop.php
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-04-23 21:59:50 -0500
committerJoel Martin <github@martintribe.org>2014-04-23 21:59:50 -0500
commit6301e0b6374cecc5599665be14d6ddc6a31ce1e8 (patch)
treedbf1dc2ff6c682fd87c72a7907e7f6e59c8d4c03 /php/step9_interop.php
parent89bd4de1e2704c1bc562788b2c5e4fc08b71a538 (diff)
downloadmal-6301e0b6374cecc5599665be14d6ddc6a31ce1e8.tar.gz
mal-6301e0b6374cecc5599665be14d6ddc6a31ce1e8.zip
All: TCO let* and quasiquote.
Diffstat (limited to 'php/step9_interop.php')
-rw-r--r--php/step9_interop.php12
1 files changed, 8 insertions, 4 deletions
diff --git a/php/step9_interop.php b/php/step9_interop.php
index f35244c..d4a59c7 100644
--- a/php/step9_interop.php
+++ b/php/step9_interop.php
@@ -94,11 +94,14 @@ function MAL_EVAL($ast, $env) {
for ($i=0; $i < count($a1); $i+=2) {
$let_env->set($a1[$i]->value, MAL_EVAL($a1[$i+1], $let_env));
}
- return MAL_EVAL($ast[2], $let_env);
+ $ast = $ast[2];
+ $env = $let_env;
+ break; // Continue loop (TCO)
case "quote":
return $ast[1];
case "quasiquote":
- return MAL_EVAL(quasiquote($ast[1]), $env);
+ $ast = quasiquote($ast[1]);
+ break; // Continue loop (TCO)
case "defmacro!":
$func = MAL_EVAL($ast[2], $env);
$func->ismacro = true;
@@ -110,7 +113,7 @@ function MAL_EVAL($ast, $env) {
case "do":
eval_ast($ast->slice(1, -1), $env);
$ast = $ast[count($ast)-1];
- break;
+ break; // Continue loop (TCO)
case "if":
$cond = MAL_EVAL($ast[1], $env);
if ($cond === NULL || $cond === false) {
@@ -119,7 +122,7 @@ function MAL_EVAL($ast, $env) {
} else {
$ast = $ast[2];
}
- break;
+ break; // Continue loop (TCO)
case "fn*":
return _function('MAL_EVAL', 'native',
$ast[2], $env, $ast[1]);
@@ -130,6 +133,7 @@ function MAL_EVAL($ast, $env) {
if ($f->type === 'native') {
$ast = $f->ast;
$env = $f->gen_env($args);
+ // Continue loop (TCO)
} else {
return $f->apply($args);
}