mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-26 07:04:27 +00:00
add special form: case
This commit is contained in:
parent
2f6409ce72
commit
91eba046bc
@ -27,6 +27,24 @@ class Evaller
|
||||
}
|
||||
|
||||
return $value;
|
||||
} elseif ($ast->get(0)->getName() == 'case') {
|
||||
if ($ast->count() < 2) {
|
||||
throw new MadLispException("case requires at least 1 argument");
|
||||
}
|
||||
|
||||
for ($i = 1; $i < $ast->count() - 1; $i += 2) {
|
||||
$test = $this->eval($ast->get($i), $env);
|
||||
if ($test == true) {
|
||||
return $this->eval($ast->get($i + 1), $env);
|
||||
}
|
||||
}
|
||||
|
||||
// Last value, no test
|
||||
if ($ast->count() % 2 == 0) {
|
||||
return $this->eval($ast->get($ast->count() - 1), $env);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} elseif ($ast->get(0)->getName() == 'def') {
|
||||
if ($ast->count() != 3) {
|
||||
throw new MadLispException("def requires exactly 2 arguments");
|
||||
|
Loading…
Reference in New Issue
Block a user