generalizations: fix funny mnapply/nspread* bug for n > 3.

It accidentally worked for n <= 3, now it purposefully works.
windows-drag
John Benediktsson 2019-03-16 19:58:07 -07:00
parent d4fc53f10e
commit ada81e77f5
2 changed files with 10 additions and 4 deletions

View 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

View 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 )