private function evalCode($code, array $envVars = array())
 {
     $parser = new Scheme_Parser($code);
     $expr = $parser->parse($code);
     $env = $this->rootEnv->createChildEnv();
     $env->bindAll($envVars);
     return $this->interp->evaluate($env, $expr);
 }
Exemple #2
0
 public function letrec(array $args, Scheme_Env $env)
 {
     $this->requireExactly(2, $args);
     $bindings = $args[0];
     $body = $args[1];
     $interpreter = $env->getInterpreter();
     $newEnv = $env->createChildEnv();
     $this->requireList($bindings);
     $initedBindings = array();
     foreach ($bindings->listToArray() as $binding) {
         $this->requireList($binding);
         $bindingArray = $binding->listToArray();
         $this->requireExactly(2, $bindingArray);
         $var = $bindingArray[0];
         $expr = $bindingArray[1];
         $this->requireSymbol($var);
         $value = $interpreter->evaluate($newEnv, $expr);
         $initedBindings[$var->value] = $value;
     }
     $newEnv->bindAll($initedBindings);
     return new Scheme_TailCall($body, $newEnv);
 }