Permalink
Browse files

Implemented do.

  • Loading branch information...
1 parent c582efc commit fcf80621ddda2929faee786db67a1481722f89a2 @dahlia dahlia committed Dec 17, 2009
Showing with 29 additions and 0 deletions.
  1. +1 −0 Lisphp/Environment.php
  2. +1 −0 Lisphp/Runtime.php
  3. +11 −0 Lisphp/Runtime/Do.php
  4. +1 −0 Lisphp/Test/EnvironmentTest.php
  5. +15 −0 Lisphp/Test/RuntimeTest.php
View
@@ -18,6 +18,7 @@ static function sandbox() {
$scope['macro'] = new Lisphp_Runtime_Macro;
$scope['lambda'] = new Lisphp_Runtime_Lambda;
$scope['apply'] = new Lisphp_Runtime_Apply;
+ $scope['do'] = new Lisphp_Runtime_Do;
$scope['dict'] = new Lisphp_Runtime_Dict;
$scope['array'] = new Lisphp_Runtime_Array;
$scope['list'] = new Lisphp_Runtime_List;
View
@@ -8,6 +8,7 @@
require_once 'Runtime/Macro.php';
require_once 'Runtime/Lambda.php';
require_once 'Runtime/Apply.php';
+require_once 'Runtime/Do.php';
require_once 'Runtime/Dict.php';
require_once 'Runtime/Array.php';
require_once 'Runtime/Logical.php';
View
@@ -0,0 +1,11 @@
+<?php
+require_once 'Lisphp/Applicable.php';
+require_once 'Lisphp/List.php';
+require_once 'Lisphp/Scope.php';
+
+final class Lisphp_Runtime_Do extends Lisphp_Runtime_BuiltinFunction {
+ protected function execute(array $arguments) {
+ return $arguments[count($arguments) - 1];
+ }
+}
+
@@ -24,6 +24,7 @@ function testSandbox($scope = null) {
$this->assertType('Lisphp_Runtime_Macro', $scope['macro']);
$this->assertType('Lisphp_Runtime_Lambda', $scope['lambda']);
$this->assertType('Lisphp_Runtime_Apply', $scope['apply']);
+ $this->assertType('Lisphp_Runtime_Do', $scope['do']);
$this->assertType('Lisphp_Runtime_Dict', $scope['dict']);
$this->assertType('Lisphp_Runtime_Array', $scope['array']);
$this->assertType('Lisphp_Runtime_List', $scope['list']);
@@ -123,6 +123,21 @@ function testLambda() {
$this->assertEquals($args->cdr(), $func->body);
}
+ function testDo() {
+ $do = new Lisphp_Runtime_Do;
+ $scope = new Lisphp_Scope(Lisphp_Environment::sandbox());
+ $scope['a'] = new Lisphp_List;
+ $args = Lisphp_Parser::parseForm('{
+ (set-at! a "first")
+ (set-at! a "second")
+ (set-at! a "third")
+ }', $_);
+ $retval = $do->apply($scope, $args);
+ $this->assertEquals('third', $retval);
+ $this->assertEquals(new Lisphp_List(array('first', 'second', 'third')),
+ $scope['a']);
+ }
+
function testIf() {
$if = new Lisphp_Runtime_Logical_If;
$scope = new Lisphp_Scope;

0 comments on commit fcf8062

Please sign in to comment.