This commit is contained in:
Pekka Laiho 2020-05-30 19:19:37 +07:00
parent a4182f7d8e
commit debda2e602
2 changed files with 15 additions and 0 deletions

View File

@ -22,5 +22,10 @@ function ml_get_lisp(): array
return $results[count($results) - 1];
});
$env->set('print', function (...$args) use ($printer) {
$printer->print($args);
return null;
});
return [$lisp, $env];
}

View File

@ -60,6 +60,16 @@ class Evaller
$value = $this->doEval($ast->get(2), $env);
return $env->set($ast->get(1)->getName(), $value);
} elseif ($ast->get(0)->getName() == 'do') {
if ($ast->count() < 2) {
throw new MadLispException("do requires at least 1 argument");
}
for ($i = 1; $i < $ast->count(); $i++) {
$value = $this->evalAst($ast->get($i), $env);
}
return $value;
} elseif ($ast->get(0)->getName() == 'if') {
if ($ast->count() < 3 || $ast->count() > 4) {
throw new MadLispException("if requires 2 or 3 arguments");