private function expandSubLists(Environment $env, ListForm $form) { if (!count($form->toArray())) { return $form; } return new ListForm(array_merge([$form->nth(0)], $this->expandList($env, $form->cdr()))); }
public function evaluate(Environment $env, ListForm $args) { $name = $args->nth(0)->getSymbol(); $macroArgs = $args->nth(1); $macroBody = $args->nth(2); $env[$name] = new MacroOp($macroArgs, $macroBody); }
public function evaluate(Environment $env, ListForm $args) { $predicate = $args->nth(0); $trueForm = $args->nth(1); $elseForm = $args->nth(2); $form = $predicate->evaluate($env) ? $trueForm : $elseForm; return $form ? $form->evaluate($env) : null; }
public function evaluate(Environment $env, ListForm $args) { $pairs = $args->toArray(); foreach ($pairs as $pair) { list($predicate, $trueForm) = $pair->toArray(); if ($predicate->evaluate($env)) { return $trueForm->evaluate($env); } } return null; }
private function wrapSymbols(ListForm $rawBody) { $wrappedBody = array_map(function ($form) { if ($form instanceof ListForm) { return $this->wrapSymbols($form); } if (is_string($form)) { return new SymbolForm($form); } return $form; }, $rawBody->toArray()); return new ListForm($wrappedBody); }
public function evaluate(Environment $env, ListForm $args) { $symbols = $args->nth(0)->toArray(); $argNames = $this->getMappedSymbols($symbols); $bodyForms = $args->cdr()->toArray(); return function () use($env, $argNames, $bodyForms) { $subEnv = clone $env; $vars = array_combine($argNames, func_get_args()); foreach ($vars as $name => $value) { $subEnv[$name] = $value; } $value = null; foreach ($bodyForms as $form) { $value = $form->evaluate($subEnv); } return $value; }; }
public function evaluate(Environment $env, ListForm $args) { $name = $args->nth(0)->getSymbol(); $env[$name] = $args->nth(1)->evaluate($env); }
public function evaluate(Environment $env, ListForm $args) { list($value) = $args->getAst(); return $value; }
private function evaluateArgs(Environment $env, ListForm $args) { return array_map(function ($arg) use($env) { return $arg->evaluate($env); }, $args->toArray()); }