diff options
| author | Joel Martin <github@martintribe.org> | 2014-04-01 22:50:55 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-04-01 22:50:55 -0500 |
| commit | 9528bb145193159fa3e697da642e32a0877af5fb (patch) | |
| tree | 3375b4524d7c845ec33c7636fb7697ce3c1d6a42 /php/types.php | |
| parent | 950e3c765e30648de34cfc4f65fffdce06f0727f (diff) | |
| download | mal-9528bb145193159fa3e697da642e32a0877af5fb.tar.gz mal-9528bb145193159fa3e697da642e32a0877af5fb.zip | |
All: pass stepA tests, in particular with correct conj behavior.
Diffstat (limited to 'php/types.php')
| -rw-r--r-- | php/types.php | 13 |
1 files changed, 7 insertions, 6 deletions
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); } ); |
