]> gitweb.factorcode.org Git - factor.git/commitdiff
generalizations: fix funny mnapply/nspread* bug for n > 3.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sun, 17 Mar 2019 02:58:07 +0000 (19:58 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 17 Mar 2019 02:58:07 +0000 (19:58 -0700)
It accidentally worked for n <= 3, now it purposefully works.

basis/generalizations/generalizations-tests.factor
basis/generalizations/generalizations.factor

index 360c3e5dbee2265559069a954f87cd2d99e3302c..c083dc5c21efa7d0b669c674e2561cdc2c5999e2 100644 (file)
@@ -99,6 +99,12 @@ IN: generalizations.tests
 { { 1 2 } { 3 4 } { 5 6 } }
 [ 1 2 3 4 5 6 [ 2array ] 2 3 mnapply ] unit-test
 
+{ 1 4 9 16 }
+[ 1 1 2 2 3 3 4 4 [ * ] 2 4 mnapply ] unit-test
+
+{ 1 8 27 64 125 }
+[ 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 [ * * ] 3 5 mnapply ] unit-test
+
 { { 1 2 3 } { 4 5 6 } }
 [ 1 2 3 4 5 6 [ 3array ] 3 2 mnapply ] unit-test
 
index b45ce527855ce058784ac453221b85fd02637b2d..34bccc727ea79e3ab9a532de0771041d4a6b2f85 100644 (file)
@@ -92,10 +92,10 @@ MACRO: nspread* ( m n -- quot )
     [ drop [ ] ] [
         [ * 0 ] [ drop neg ] 2bi
         <range> rest >array dup length <iota> <reversed>
-        [
-            '[ [ [ _ ndip ] curry ] _ ndip ]
-        ] 2map dup rest-slice [ [ compose ] compose ] map! drop
-        [ ] concat-as [ call ] compose
+        [ '[ [ [ _ ndip ] curry ] _ ndip ] ] 2map
+        [ [ ] concat-as ]
+        [ length 1 - [ compose ] <array> concat append ] bi
+        [ call ] compose
     ] if-zero ;
 
 MACRO: cleave* ( n -- quot )