Inheritance: extends ArrayObject, implements Lisphp_Form
示例#1
0
 public function testEvaluate530()
 {
     $scope = new Lisphp_Scope();
     $scope['f'] = function ($a, $b) {
         return $a + $b;
     };
     $list = new Lisphp_List(array(Lisphp_Symbol::get('f'), new Lisphp_Literal(123), new Lisphp_Literal(456)));
     $this->assertEquals(579, $list->evaluate($scope));
 }
示例#2
0
 function testEvaluate530()
 {
     if (version_compare(phpversion(), '5.3.0', '<')) {
         $this->markTestSkipped('PHP version is less than 5.3.0.');
     }
     $scope = new Lisphp_Scope();
     eval('$scope["f"] = function($a, $b) { return $a + $b; };');
     $list = new Lisphp_List(array(Lisphp_Symbol::get('f'), new Lisphp_Literal(123), new Lisphp_Literal(456)));
     $this->assertEquals(579, $list->evaluate($scope));
 }
 /**
  * @param string $valueToApply
  * @param Lisphp_List $list
  */
 public function __construct($valueToApply, Lisphp_List $list = null)
 {
     $this->valueToApply = $valueToApply;
     $this->list = $list;
     $type = is_object($this->valueToApply) ? get_class($this->valueToApply) : (is_null($this->valueToApply) ? 'nil' : gettype($this->valueToApply));
     $msg = "{$type} cannot be applied; see Lisphp_Applicable interface";
     if ($list) {
         $msg .= ': ' . $list->__toString();
     }
     parent::__construct($msg);
 }
示例#4
0
文件: Let.php 项目: lisphp/lisphp
 public function apply(Lisphp_Scope $scope, Lisphp_List $arguments)
 {
     $vars = $arguments->car();
     $scope = new Lisphp_Scope($scope);
     foreach ($vars as $var) {
         list($var, $value) = $var;
         $scope->let($var, $value->evaluate($scope->superscope));
     }
     foreach ($arguments->cdr() as $form) {
         $retval = $form->evaluate($scope);
     }
     return $retval;
 }
示例#5
0
 function apply(Lisphp_Scope $scope, Lisphp_List $arguments)
 {
     $tmp = new Lisphp_Scope();
     $use = new Lisphp_Runtime_Use();
     $ns = (string) $arguments->car();
     $simpleNames = iterator_to_array($arguments[1]);
     foreach ($simpleNames as $name) {
         $names[] = Lisphp_Symbol::get("{$ns}/{$name}");
     }
     $retval = $use->apply($tmp, new Lisphp_List($names));
     foreach ($simpleNames as $i => $name) {
         $scope->let($name, $retval[$i]);
     }
     return $retval;
 }
示例#6
0
文件: Define.php 项目: lisphp/lisphp
 public function apply(Lisphp_Scope $scope, Lisphp_List $arguments)
 {
     $name = $arguments[0];
     if ($name instanceof Lisphp_Symbol) {
         $retval = $arguments[1]->evaluate($scope);
     } elseif ($name instanceof Lisphp_List) {
         $params = $name->cdr();
         $body = $arguments->cdr();
         $name = $name->car();
         $retval = new Lisphp_Runtime_Function($scope, $params, $body);
     } else {
         throw new InvalidArgumentException('first operand of define form must be symbol or list');
     }
     $scope->define($name, $retval);
     return $retval;
 }