optimize: remove array_map

This commit is contained in:
Pekka Laiho 2020-06-05 15:55:38 +07:00
parent 7331cbe874
commit 18277d9566

View File

@ -202,10 +202,12 @@ class Evaller
if ($ast instanceof Symbol) { if ($ast instanceof Symbol) {
// Lookup symbol from env // Lookup symbol from env
return $env->get($ast->getName()); return $env->get($ast->getName());
} elseif ($ast instanceof MList) { } elseif ($ast instanceof Seq) {
return new MList(array_map(fn ($a) => $this->eval($a, $env), $ast->getData())); $results = [];
} elseif ($ast instanceof Vector) { foreach ($ast->getData() as $val) {
return new Vector(array_map(fn ($a) => $this->eval($a, $env), $ast->getData())); $results[] = $this->eval($val, $env);
}
return $ast::new($results);
} elseif ($ast instanceof Hash) { } elseif ($ast instanceof Hash) {
$results = []; $results = [];
foreach ($ast->getData() as $key => $val) { foreach ($ast->getData() as $key => $val) {