mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-22 21:35:03 +00:00
quote and eval hash
This commit is contained in:
parent
773f195f37
commit
c1224fb66f
@ -22,9 +22,17 @@ class Evaller
|
||||
// Lookup symbol from env
|
||||
return $env->get($ast->getName());
|
||||
} elseif ($ast instanceof MList) {
|
||||
// Eval contents and return new list
|
||||
$results = array_map(fn ($a) => $this->doEval($a, $env), $ast->getData());
|
||||
$results = [];
|
||||
foreach ($ast->getData() as $val) {
|
||||
$results[] = $this->doEval($val, $env);
|
||||
}
|
||||
return new MList($results);
|
||||
} elseif ($ast instanceof Hash) {
|
||||
$results = [];
|
||||
foreach ($ast->getData() as $key => $val) {
|
||||
$results[$key] = $this->doEval($val, $env);
|
||||
}
|
||||
return new Hash($results);
|
||||
}
|
||||
|
||||
return $ast;
|
||||
@ -42,6 +50,19 @@ class Evaller
|
||||
return $ast;
|
||||
}
|
||||
|
||||
$first = $ast->get(0);
|
||||
|
||||
// Handle special keywords
|
||||
if ($first instanceof Symbol) {
|
||||
if ($first->getName() == 'quote') {
|
||||
if ($ast->count() != 2) {
|
||||
throw new MadLispException("quote requires exactly 1 argument");
|
||||
}
|
||||
|
||||
return $ast->get(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Get new evaluated list
|
||||
$ast = $this->evalAst($ast, $env);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user