diff --git a/basis/generalizations/generalizations-docs.factor b/basis/generalizations/generalizations-docs.factor index 5b869f138e..d21b2b022c 100644 --- a/basis/generalizations/generalizations-docs.factor +++ b/basis/generalizations/generalizations-docs.factor @@ -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." } ; 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@ } "." } { $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 -{ $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 } "." } { $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 -{ $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* } "." } { $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*" } "." } ; diff --git a/basis/generalizations/generalizations.factor b/basis/generalizations/generalizations.factor index dd0665b534..ac5ff3dee0 100644 --- a/basis/generalizations/generalizations.factor +++ b/basis/generalizations/generalizations.factor @@ -125,13 +125,13 @@ MACRO: cleave* ( n -- ) : mnapply ( quot m n -- ) [ nip dupn ] [ nspread* ] 2bi ; inline -: apply-curry ( ...a quot n -- ) +: apply-curry ( a... quot n -- ) [ [curry] ] dip napply ; inline -: cleave-curry ( a ...quot n -- ) +: cleave-curry ( a quot... n -- ) [ [curry] ] swap [ napply ] [ cleave* ] bi ; inline -: spread-curry ( ...a ...quot n -- ) +: spread-curry ( a... quot... n -- ) [ [curry] ] swap [ napply ] [ spread* ] bi ; inline MACRO: mnswap ( m n -- ) diff --git a/basis/sequences/generalizations/generalizations-docs.factor b/basis/sequences/generalizations/generalizations-docs.factor index 7940427e69..30ad1ea628 100644 --- a/basis/sequences/generalizations/generalizations-docs.factor +++ b/basis/sequences/generalizations/generalizations-docs.factor @@ -4,15 +4,15 @@ math arrays combinators ; IN: sequences.generalizations 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." } ; 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." } ; 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." } ; 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." } ; 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." } ; ARTICLE: "sequences.generalizations" "Generalized sequence iteration combinators" diff --git a/basis/sequences/generalizations/generalizations.factor b/basis/sequences/generalizations/generalizations.factor index f49dc8a4e7..60b1a8a011 100644 --- a/basis/sequences/generalizations/generalizations.factor +++ b/basis/sequences/generalizations/generalizations.factor @@ -8,31 +8,31 @@ MACRO: nmin-length ( n -- ) dup 1 - [ min ] n*quot '[ [ length ] _ napply @ ] ; -: nnth-unsafe ( n ...seq n -- ) +: nnth-unsafe ( n seq... n -- ) [ nth-unsafe ] swap [ apply-curry ] [ cleave* ] bi ; inline MACRO: nset-nth-unsafe ( n -- ) [ [ drop ] ] [ '[ [ set-nth-unsafe ] _ [ apply-curry ] [ cleave-curry ] [ spread* ] tri ] ] if-zero ; -: (neach) ( ...seq quot n -- len quot' ) +: (neach) ( seq... quot n -- len quot' ) dup dup dup '[ [ _ nmin-length ] _ nkeep [ _ nnth-unsafe ] _ ncurry ] dip compose ; inline -: neach ( ...seq quot n -- ) +: neach ( seq... quot n -- ) (neach) each-integer ; inline -: nmap-as ( ...seq quot exemplar n -- result ) +: nmap-as ( seq... quot exemplar n -- result ) '[ _ (neach) ] dip map-integers ; inline -: nmap ( ...seq quot n -- result ) +: nmap ( seq... quot n -- result ) dup '[ [ _ npick ] dip swap ] dip nmap-as ; inline MACRO: nnew-sequence ( n -- ) [ [ drop ] ] [ dup '[ [ new-sequence ] _ apply-curry _ cleave* ] ] if-zero ; -: nnew-like ( len ...exemplar quot n -- result... ) +: nnew-like ( len exemplar... quot n -- result... ) 5 dupn '[ _ nover [ [ _ nnew-sequence ] dip call ] @@ -45,10 +45,10 @@ MACRO: (ncollect) ( n -- ) 3 dupn 1 + '[ [ [ keep ] _ ndip _ nset-nth-unsafe ] _ ncurry ] ; -: ncollect ( len quot ...into n -- ) +: ncollect ( len quot into... n -- ) (ncollect) each-integer ; inline -: nmap-integers ( len quot ...exemplar n -- result... ) +: nmap-integers ( len quot exemplar... n -- result... ) 4 dupn '[ [ over ] _ ndip [ [ _ ncollect ] _ nkeep ] _ nnew-like ] call ; inline @@ -58,7 +58,7 @@ MACRO: (ncollect) ( n -- ) : mnmap ( m*seq quot m n -- result*n ) 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 '[ [ [ length ] keep new-resizable ] _ napply [ [ [ push ] _ apply-curry _ spread* ] _ ncurry compose ] _ nkeep @@ -67,7 +67,7 @@ MACRO: (ncollect) ( n -- ) : ncollector ( quot n -- quot' vec... ) [ V{ } swap dupn ] keep ncollector-for ; inline -: nproduce-as ( pred quot ...exemplar n -- seq... ) +: nproduce-as ( pred quot exemplar... n -- seq... ) 7 dupn '[ _ ndup [ _ ncollector-for [ while ] _ ndip ]