mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-22 21:35:03 +00:00
add if
This commit is contained in:
parent
01e5c4b198
commit
a4182f7d8e
@ -60,6 +60,20 @@ class Evaller
|
||||
|
||||
$value = $this->doEval($ast->get(2), $env);
|
||||
return $env->set($ast->get(1)->getName(), $value);
|
||||
} elseif ($ast->get(0)->getName() == 'if') {
|
||||
if ($ast->count() < 3 || $ast->count() > 4) {
|
||||
throw new MadLispException("if requires 2 or 3 arguments");
|
||||
}
|
||||
|
||||
$result = $this->doEval($ast->get(1), $env);
|
||||
|
||||
if ($result == true) {
|
||||
return $this->doEval($ast->get(2), $env);
|
||||
} elseif ($ast->count() == 4) {
|
||||
return $this->doEval($ast->get(3), $env);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} elseif ($ast->get(0)->getName() == 'let') {
|
||||
if ($ast->count() != 3) {
|
||||
throw new MadLispException("let requires exactly 2 arguments");
|
||||
|
Loading…
Reference in New Issue
Block a user