From 9528bb145193159fa3e697da642e32a0877af5fb Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Tue, 1 Apr 2014 22:50:55 -0500 Subject: All: pass stepA tests, in particular with correct conj behavior. --- php/types.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'php/types.php') diff --git a/php/types.php b/php/types.php index 0c4ab33..4486a18 100644 --- a/php/types.php +++ b/php/types.php @@ -338,12 +338,11 @@ function concat() { function conj($src) { $args = array_slice(func_get_args(), 1); $tmp = $src->getArrayCopy(); - foreach ($args as $arg) { - $tmp[] = $arg; - } if (list_Q($src)) { + foreach ($args as $arg) { array_unshift($tmp, $arg); } $s = new ListClass(); } else { + foreach ($args as $arg) { $tmp[] = $arg; } $s = new VectorClass(); } $s->exchangeArray($tmp); @@ -368,8 +367,10 @@ function nth($seq, $idx) { return $seq[$idx]; } -function apply($f, $args) { - return $f->apply($args->getArrayCopy()); +function apply($f) { + $args = array_slice(func_get_args(), 1); + $last_arg = array_pop($args)->getArrayCopy(); + return $f->apply(array_merge($args, $last_arg)); } function map($f, $seq) { @@ -480,7 +481,7 @@ $types_ns = array( 'first'=> function ($a) { return first($a); }, 'rest'=> function ($a) { return rest($a); }, 'nth'=> function ($a, $b) { return nth($a, $b); }, - 'apply'=> function ($a, $b) { return apply($a, $b); }, + 'apply'=> function () { return call_user_func_array('apply', func_get_args()); }, 'map'=> function ($a, $b) { return map($a, $b); } ); -- cgit v1.2.3