mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-22 21:35:03 +00:00
add do
This commit is contained in:
parent
a4182f7d8e
commit
debda2e602
@ -22,5 +22,10 @@ function ml_get_lisp(): array
|
|||||||
return $results[count($results) - 1];
|
return $results[count($results) - 1];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$env->set('print', function (...$args) use ($printer) {
|
||||||
|
$printer->print($args);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
return [$lisp, $env];
|
return [$lisp, $env];
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,16 @@ class Evaller
|
|||||||
|
|
||||||
$value = $this->doEval($ast->get(2), $env);
|
$value = $this->doEval($ast->get(2), $env);
|
||||||
return $env->set($ast->get(1)->getName(), $value);
|
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') {
|
} elseif ($ast->get(0)->getName() == 'if') {
|
||||||
if ($ast->count() < 3 || $ast->count() > 4) {
|
if ($ast->count() < 3 || $ast->count() > 4) {
|
||||||
throw new MadLispException("if requires 2 or 3 arguments");
|
throw new MadLispException("if requires 2 or 3 arguments");
|
||||||
|
Loading…
Reference in New Issue
Block a user