示例#1
0
文件: Walker.php 项目: igorw/ilias
 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())));
 }
示例#2
0
 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);
 }
示例#3
0
文件: IfOp.php 项目: igorw/ilias
 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;
 }
示例#4
0
文件: CondOp.php 项目: igorw/ilias
 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;
 }
示例#5
0
文件: MacroOp.php 项目: igorw/ilias
 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);
 }
示例#6
0
文件: LambdaOp.php 项目: igorw/ilias
 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;
     };
 }
示例#7
0
文件: DefineOp.php 项目: igorw/ilias
 public function evaluate(Environment $env, ListForm $args)
 {
     $name = $args->nth(0)->getSymbol();
     $env[$name] = $args->nth(1)->evaluate($env);
 }
示例#8
0
文件: QuoteOp.php 项目: igorw/ilias
 public function evaluate(Environment $env, ListForm $args)
 {
     list($value) = $args->getAst();
     return $value;
 }
示例#9
0
文件: ListForm.php 项目: igorw/ilias
 private function evaluateArgs(Environment $env, ListForm $args)
 {
     return array_map(function ($arg) use($env) {
         return $arg->evaluate($env);
     }, $args->toArray());
 }