function testListSymbols() { $this->assertEquals(array(), array_diff(array('abc', 'def', 'ghi'), $this->scope->listSymbols())); $scope = new Lisphp_Scope($this->scope); $scope->let('jkl', 123); $scope->let('abc', 456); $this->assertEquals(array(), array_diff(array('def', 'ghi', 'jkl', 'abc'), $scope->listSymbols())); }
function apply(Lisphp_Scope $scope, Lisphp_List $arguments) { $values = array(); foreach ($arguments as $name) { foreach ($this->dispatch($name) as $name => $value) { $scope->let($name, $value); } $values[] = $value; } return new Lisphp_List($values); }
/** * @return Lisphp_Scope */ public static function webapp() { $scope = new Lisphp_Scope(self::sandbox()); $scope->let('*get*', $_GET); $scope->let('*post*', $_POST); $scope->let('*request*', $_REQUEST); $scope->let('*files*', $_FILES); $scope->let('*cookie*', $_COOKIE); $scope->let('*session*', $_SESSION); return $scope; }
public function apply(Lisphp_Scope $scope, Lisphp_List $arguments) { $call = new Lisphp_Scope($this->scope); $call->let('#scope', $scope); $call->let('#arguments', $arguments); foreach ($this->body as $form) { $retval = $form->evaluate($call); } if (isset($retval)) { return $retval; } }
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; }
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; }
protected function execute(array $arguments) { $local = new Lisphp_Scope($this->scope); foreach ($this->parameters as $i => $name) { if (!array_key_exists($i, $arguments)) { throw new InvalidArgumentException('too few arguments'); } $local->let($name, $arguments[$i]); } $local->let('#arguments', new Lisphp_List($arguments)); foreach ($this->body as $form) { $retval = $form->evaluate($local); } return $retval; }
public function testGetAttribute() { $attr = new Lisphp_Runtime_Object_GetAttribute(); $object = (object) array('abc' => 'value'); $object->ptr = $object; $object->lst = new Lisphp_List(); $scope = new Lisphp_Scope(); $scope->let('object', $object); $val = $attr->apply($scope, self::lst('object abc')); $this->assertEquals($object->abc, $val); $val = $attr->apply($scope, self::lst('object ptr ptr abc')); $this->assertEquals($object->ptr->ptr->abc, $val); $val = $attr->apply($scope, self::lst('object lst car')); $this->assertType('Lisphp_Runtime_PHPFunction', $val); $this->assertSame($object->lst, $val->callback[0]); $this->assertEquals('car', $val->callback[1]); try { $attr->apply($scope, self::lst('object lst a')); $this->fail(); } catch (RuntimeException $e) { # pass } }