clean up now-inappropriate uses of "..." in generalizations stack effects
parent
a3033e885a
commit
ff2a53e1b8
|
@ -252,17 +252,17 @@ HELP: spread*
|
||||||
{ $notes "This word can be used with " { $link apply-curry } " to generalize the " { $snippet "bi-curry@ bi*" } " or " { $snippet "tri-curry@ tri*" } " dataflow patterns." } ;
|
{ $notes "This word can be used with " { $link apply-curry } " to generalize the " { $snippet "bi-curry@ bi*" } " or " { $snippet "tri-curry@ tri*" } " dataflow patterns." } ;
|
||||||
|
|
||||||
HELP: apply-curry
|
HELP: apply-curry
|
||||||
{ $values { "...a" { $snippet "n" } " values on the datastack" } { "quot" quotation } { "n" integer } }
|
{ $values { "a..." { $snippet "n" } " values on the datastack" } { "quot" quotation } { "n" integer } }
|
||||||
{ $description "Curries each of the top " { $snippet "n" } " items of the datastack onto " { $snippet "quot" } ", leaving " { $snippet "n" } " quotations on the datastack. A generalization of " { $link bi-curry@ } " and " { $link tri-curry@ } "." }
|
{ $description "Curries each of the top " { $snippet "n" } " items of the datastack onto " { $snippet "quot" } ", leaving " { $snippet "n" } " quotations on the datastack. A generalization of " { $link bi-curry@ } " and " { $link tri-curry@ } "." }
|
||||||
{ $notes "This word can be used with " { $link cleave* } " and " { $link spread* } " to generalize dataflow patterns such as " { $snippet "bi-curry@ bi" } ", " { $snippet "tri-curry@ tri" } ", " { $snippet "bi-curry@ bi*" } ", and " { $snippet "tri-curry@ tri*" } "." } ;
|
{ $notes "This word can be used with " { $link cleave* } " and " { $link spread* } " to generalize dataflow patterns such as " { $snippet "bi-curry@ bi" } ", " { $snippet "tri-curry@ tri" } ", " { $snippet "bi-curry@ bi*" } ", and " { $snippet "tri-curry@ tri*" } "." } ;
|
||||||
|
|
||||||
HELP: cleave-curry
|
HELP: cleave-curry
|
||||||
{ $values { "a" object } { "...quot" { $snippet "n" } " quotations on the datastack" } { "n" integer } }
|
{ $values { "a" object } { "quot..." { $snippet "n" } " quotations on the datastack" } { "n" integer } }
|
||||||
{ $description "Curries " { $snippet "a" } " onto the " { $snippet "n" } " quotations on the top of the datastack. A generalization of " { $link bi-curry } " and " { $link tri-curry } "." }
|
{ $description "Curries " { $snippet "a" } " onto the " { $snippet "n" } " quotations on the top of the datastack. A generalization of " { $link bi-curry } " and " { $link tri-curry } "." }
|
||||||
{ $notes "This word can be used with " { $link cleave* } " and " { $link spread* } " to generalize dataflow patterns such as " { $snippet "bi-curry bi" } ", " { $snippet "tri-curry tri" } ", " { $snippet "bi-curry bi*" } ", and " { $snippet "tri-curry tri*" } "." } ;
|
{ $notes "This word can be used with " { $link cleave* } " and " { $link spread* } " to generalize dataflow patterns such as " { $snippet "bi-curry bi" } ", " { $snippet "tri-curry tri" } ", " { $snippet "bi-curry bi*" } ", and " { $snippet "tri-curry tri*" } "." } ;
|
||||||
|
|
||||||
HELP: spread-curry
|
HELP: spread-curry
|
||||||
{ $values { "...a" { $snippet "n" } " objects on the datastack" } { "...quot" { $snippet "n" } " quotations on the datastack" } { "n" integer } }
|
{ $values { "a..." { $snippet "n" } " objects on the datastack" } { "quot..." { $snippet "n" } " quotations on the datastack" } { "n" integer } }
|
||||||
{ $description "Curries the " { $snippet "n" } " quotations on the top of the datastack with the " { $snippet "n" } " values just below them. A generalization of " { $link bi-curry* } " and " { $link tri-curry* } "." }
|
{ $description "Curries the " { $snippet "n" } " quotations on the top of the datastack with the " { $snippet "n" } " values just below them. A generalization of " { $link bi-curry* } " and " { $link tri-curry* } "." }
|
||||||
{ $notes "This word can be used with " { $link cleave* } " and " { $link spread* } " to generalize dataflow patterns such as " { $snippet "bi-curry* bi" } ", " { $snippet "tri-curry* tri" } ", " { $snippet "bi-curry* bi*" } ", and " { $snippet "tri-curry* tri*" } "." } ;
|
{ $notes "This word can be used with " { $link cleave* } " and " { $link spread* } " to generalize dataflow patterns such as " { $snippet "bi-curry* bi" } ", " { $snippet "tri-curry* tri" } ", " { $snippet "bi-curry* bi*" } ", and " { $snippet "tri-curry* tri*" } "." } ;
|
||||||
|
|
||||||
|
|
|
@ -125,13 +125,13 @@ MACRO: cleave* ( n -- )
|
||||||
: mnapply ( quot m n -- )
|
: mnapply ( quot m n -- )
|
||||||
[ nip dupn ] [ nspread* ] 2bi ; inline
|
[ nip dupn ] [ nspread* ] 2bi ; inline
|
||||||
|
|
||||||
: apply-curry ( ...a quot n -- )
|
: apply-curry ( a... quot n -- )
|
||||||
[ [curry] ] dip napply ; inline
|
[ [curry] ] dip napply ; inline
|
||||||
|
|
||||||
: cleave-curry ( a ...quot n -- )
|
: cleave-curry ( a quot... n -- )
|
||||||
[ [curry] ] swap [ napply ] [ cleave* ] bi ; inline
|
[ [curry] ] swap [ napply ] [ cleave* ] bi ; inline
|
||||||
|
|
||||||
: spread-curry ( ...a ...quot n -- )
|
: spread-curry ( a... quot... n -- )
|
||||||
[ [curry] ] swap [ napply ] [ spread* ] bi ; inline
|
[ [curry] ] swap [ napply ] [ spread* ] bi ; inline
|
||||||
|
|
||||||
MACRO: mnswap ( m n -- )
|
MACRO: mnswap ( m n -- )
|
||||||
|
|
|
@ -4,15 +4,15 @@ math arrays combinators ;
|
||||||
IN: sequences.generalizations
|
IN: sequences.generalizations
|
||||||
|
|
||||||
HELP: neach
|
HELP: neach
|
||||||
{ $values { "...seq" { $snippet "n" } " sequences on the datastack" } { "quot" "a quotation with stack effect " { $snippet "( ...element -- )" } } { "n" integer } }
|
{ $values { "seq..." { $snippet "n" } " sequences on the datastack" } { "quot" "a quotation with stack effect " { $snippet "( element... -- )" } } { "n" integer } }
|
||||||
{ $description "A generalization of " { $link each } ", " { $link 2each } ", and " { $link 3each } " that can iterate over any number of sequences in parallel." } ;
|
{ $description "A generalization of " { $link each } ", " { $link 2each } ", and " { $link 3each } " that can iterate over any number of sequences in parallel." } ;
|
||||||
|
|
||||||
HELP: nmap
|
HELP: nmap
|
||||||
{ $values { "...seq" { $snippet "n" } " sequences on the datastack" } { "quot" "a quotation with stack effect " { $snippet "( ...element -- result )" } } { "n" integer } { "result" "a sequence of the same type as the first " { $snippet "seq" } } }
|
{ $values { "seq..." { $snippet "n" } " sequences on the datastack" } { "quot" "a quotation with stack effect " { $snippet "( element... -- result )" } } { "n" integer } { "result" "a sequence of the same type as the first " { $snippet "seq" } } }
|
||||||
{ $description "A generalization of " { $link map } ", " { $link 2map } ", and " { $link 3map } " that can map over any number of sequences in parallel." } ;
|
{ $description "A generalization of " { $link map } ", " { $link 2map } ", and " { $link 3map } " that can map over any number of sequences in parallel." } ;
|
||||||
|
|
||||||
HELP: nmap-as
|
HELP: nmap-as
|
||||||
{ $values { "...seq" { $snippet "n" } " sequences on the datastack" } { "quot" "a quotation with stack effect " { $snippet "( ...element -- result )" } } { "exemplar" sequence } { "n" integer } { "result" "a sequence of the same type as " { $snippet "exemplar" } } }
|
{ $values { "seq..." { $snippet "n" } " sequences on the datastack" } { "quot" "a quotation with stack effect " { $snippet "( element... -- result )" } } { "exemplar" sequence } { "n" integer } { "result" "a sequence of the same type as " { $snippet "exemplar" } } }
|
||||||
{ $description "A generalization of " { $link map-as } ", " { $link 2map-as } ", and " { $link 3map-as } " that can map over any number of sequences in parallel." } ;
|
{ $description "A generalization of " { $link map-as } ", " { $link 2map-as } ", and " { $link 3map-as } " that can map over any number of sequences in parallel." } ;
|
||||||
|
|
||||||
HELP: mnmap
|
HELP: mnmap
|
||||||
|
@ -28,7 +28,7 @@ HELP: nproduce
|
||||||
{ $description "A generalization of " { $link produce } " that generates " { $snippet "n" } " arrays in parallel by calling " { $snippet "quot" } " repeatedly until " { $snippet "pred" } " outputs false." } ;
|
{ $description "A generalization of " { $link produce } " that generates " { $snippet "n" } " arrays in parallel by calling " { $snippet "quot" } " repeatedly until " { $snippet "pred" } " outputs false." } ;
|
||||||
|
|
||||||
HELP: nproduce-as
|
HELP: nproduce-as
|
||||||
{ $values { "pred" { $quotation "( -- ? )" } } { "quot" { $quotation "( -- obj1 obj2 ... objn )" } } { "...exemplar" { $snippet "n" } " sequences on the datastack" } { "n" integer } { "seq..." { $snippet "n" } " sequences on the datastack of the same types as the " { $snippet "exemplar" } "s" } }
|
{ $values { "pred" { $quotation "( -- ? )" } } { "quot" { $quotation "( -- obj1 obj2 ... objn )" } } { "exemplar..." { $snippet "n" } " sequences on the datastack" } { "n" integer } { "seq..." { $snippet "n" } " sequences on the datastack of the same types as the " { $snippet "exemplar" } "s" } }
|
||||||
{ $description "A generalization of " { $link produce-as } " that generates " { $snippet "n" } " sequences in parallel by calling " { $snippet "quot" } " repeatedly until " { $snippet "pred" } " outputs false." } ;
|
{ $description "A generalization of " { $link produce-as } " that generates " { $snippet "n" } " sequences in parallel by calling " { $snippet "quot" } " repeatedly until " { $snippet "pred" } " outputs false." } ;
|
||||||
|
|
||||||
ARTICLE: "sequences.generalizations" "Generalized sequence iteration combinators"
|
ARTICLE: "sequences.generalizations" "Generalized sequence iteration combinators"
|
||||||
|
|
|
@ -8,31 +8,31 @@ MACRO: nmin-length ( n -- )
|
||||||
dup 1 - [ min ] n*quot
|
dup 1 - [ min ] n*quot
|
||||||
'[ [ length ] _ napply @ ] ;
|
'[ [ length ] _ napply @ ] ;
|
||||||
|
|
||||||
: nnth-unsafe ( n ...seq n -- )
|
: nnth-unsafe ( n seq... n -- )
|
||||||
[ nth-unsafe ] swap [ apply-curry ] [ cleave* ] bi ; inline
|
[ nth-unsafe ] swap [ apply-curry ] [ cleave* ] bi ; inline
|
||||||
MACRO: nset-nth-unsafe ( n -- )
|
MACRO: nset-nth-unsafe ( n -- )
|
||||||
[ [ drop ] ]
|
[ [ drop ] ]
|
||||||
[ '[ [ set-nth-unsafe ] _ [ apply-curry ] [ cleave-curry ] [ spread* ] tri ] ]
|
[ '[ [ set-nth-unsafe ] _ [ apply-curry ] [ cleave-curry ] [ spread* ] tri ] ]
|
||||||
if-zero ;
|
if-zero ;
|
||||||
|
|
||||||
: (neach) ( ...seq quot n -- len quot' )
|
: (neach) ( seq... quot n -- len quot' )
|
||||||
dup dup dup
|
dup dup dup
|
||||||
'[ [ _ nmin-length ] _ nkeep [ _ nnth-unsafe ] _ ncurry ] dip compose ; inline
|
'[ [ _ nmin-length ] _ nkeep [ _ nnth-unsafe ] _ ncurry ] dip compose ; inline
|
||||||
|
|
||||||
: neach ( ...seq quot n -- )
|
: neach ( seq... quot n -- )
|
||||||
(neach) each-integer ; inline
|
(neach) each-integer ; inline
|
||||||
|
|
||||||
: nmap-as ( ...seq quot exemplar n -- result )
|
: nmap-as ( seq... quot exemplar n -- result )
|
||||||
'[ _ (neach) ] dip map-integers ; inline
|
'[ _ (neach) ] dip map-integers ; inline
|
||||||
|
|
||||||
: nmap ( ...seq quot n -- result )
|
: nmap ( seq... quot n -- result )
|
||||||
dup '[ [ _ npick ] dip swap ] dip nmap-as ; inline
|
dup '[ [ _ npick ] dip swap ] dip nmap-as ; inline
|
||||||
|
|
||||||
MACRO: nnew-sequence ( n -- )
|
MACRO: nnew-sequence ( n -- )
|
||||||
[ [ drop ] ]
|
[ [ drop ] ]
|
||||||
[ dup '[ [ new-sequence ] _ apply-curry _ cleave* ] ] if-zero ;
|
[ dup '[ [ new-sequence ] _ apply-curry _ cleave* ] ] if-zero ;
|
||||||
|
|
||||||
: nnew-like ( len ...exemplar quot n -- result... )
|
: nnew-like ( len exemplar... quot n -- result... )
|
||||||
5 dupn '[
|
5 dupn '[
|
||||||
_ nover
|
_ nover
|
||||||
[ [ _ nnew-sequence ] dip call ]
|
[ [ _ nnew-sequence ] dip call ]
|
||||||
|
@ -45,10 +45,10 @@ MACRO: (ncollect) ( n -- )
|
||||||
3 dupn 1 +
|
3 dupn 1 +
|
||||||
'[ [ [ keep ] _ ndip _ nset-nth-unsafe ] _ ncurry ] ;
|
'[ [ [ keep ] _ ndip _ nset-nth-unsafe ] _ ncurry ] ;
|
||||||
|
|
||||||
: ncollect ( len quot ...into n -- )
|
: ncollect ( len quot into... n -- )
|
||||||
(ncollect) each-integer ; inline
|
(ncollect) each-integer ; inline
|
||||||
|
|
||||||
: nmap-integers ( len quot ...exemplar n -- result... )
|
: nmap-integers ( len quot exemplar... n -- result... )
|
||||||
4 dupn
|
4 dupn
|
||||||
'[ [ over ] _ ndip [ [ _ ncollect ] _ nkeep ] _ nnew-like ] call ; inline
|
'[ [ over ] _ ndip [ [ _ ncollect ] _ nkeep ] _ nnew-like ] call ; inline
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ MACRO: (ncollect) ( n -- )
|
||||||
: mnmap ( m*seq quot m n -- result*n )
|
: mnmap ( m*seq quot m n -- result*n )
|
||||||
2dup '[ [ _ npick ] dip swap _ dupn ] 2dip mnmap-as ; inline
|
2dup '[ [ _ npick ] dip swap _ dupn ] 2dip mnmap-as ; inline
|
||||||
|
|
||||||
: ncollector-for ( quot ...exemplar n -- quot' vec... )
|
: ncollector-for ( quot exemplar... n -- quot' vec... )
|
||||||
5 dupn '[
|
5 dupn '[
|
||||||
[ [ length ] keep new-resizable ] _ napply
|
[ [ length ] keep new-resizable ] _ napply
|
||||||
[ [ [ push ] _ apply-curry _ spread* ] _ ncurry compose ] _ nkeep
|
[ [ [ push ] _ apply-curry _ spread* ] _ ncurry compose ] _ nkeep
|
||||||
|
@ -67,7 +67,7 @@ MACRO: (ncollect) ( n -- )
|
||||||
: ncollector ( quot n -- quot' vec... )
|
: ncollector ( quot n -- quot' vec... )
|
||||||
[ V{ } swap dupn ] keep ncollector-for ; inline
|
[ V{ } swap dupn ] keep ncollector-for ; inline
|
||||||
|
|
||||||
: nproduce-as ( pred quot ...exemplar n -- seq... )
|
: nproduce-as ( pred quot exemplar... n -- seq... )
|
||||||
7 dupn '[
|
7 dupn '[
|
||||||
_ ndup
|
_ ndup
|
||||||
[ _ ncollector-for [ while ] _ ndip ]
|
[ _ ncollector-for [ while ] _ ndip ]
|
||||||
|
|
Loading…
Reference in New Issue