This commit is contained in:
Pekka Laiho 2020-05-28 16:49:32 +07:00
parent 26b3456595
commit 311d074546

View File

@ -111,6 +111,20 @@ class Lisp
} }
return $expr->get(1); return $expr->get(1);
} elseif ($first->getName() == 'if') {
if ($expr->count() != 4) {
throw new MadLispException("if requires exactly 3 arguments");
}
// Eval condition
$result = $this->eval($expr->get(1), $env);
// Eval true or false branch and return it
if ($result == true) {
return $this->eval($expr->get(2), $env);
} else {
return $this->eval($expr->get(3), $env);
}
} }
// Normal symbol, fetch from env // Normal symbol, fetch from env