]> gitweb.factorcode.org Git - factor.git/blob - basis/sequences/generalizations/generalizations-docs.factor
5ecebe44d48c227e91fc9bb28fcdb149bfade707
[factor.git] / basis / sequences / generalizations / generalizations-docs.factor
1 ! (c)2009 Joe Groff bsd license
2 USING: help.syntax help.markup kernel sequences quotations
3 math arrays combinators ;
4 IN: sequences.generalizations
5
6 HELP: nsequence
7 { $values { "n" integer } { "seq" "an exemplar" } }
8 { $description "A generalization of " { $link 2sequence } ", "
9 { $link 3sequence } ", and " { $link 4sequence } " "
10 "that constructs a sequence from the top " { $snippet "n" } " elements of the stack."
11 }
12 { $examples
13     { $example "USING: prettyprint sequences.generalizations ;" "CHAR: f CHAR: i CHAR: s CHAR: h 4 \"\" nsequence ." "\"fish\"" }
14 } ;
15
16 HELP: narray
17 { $values { "n" integer } }
18 { $description "A generalization of " { $link 1array } ", "
19 { $link 2array } ", " { $link 3array } " and " { $link 4array } " "
20 "that constructs an array from the top " { $snippet "n" } " elements of the stack."
21 }
22 { $examples
23     "Some core words expressed in terms of " { $link narray } ":"
24     { $table
25         { { $link 1array } { $snippet "1 narray" } }
26         { { $link 2array } { $snippet "2 narray" } }
27         { { $link 3array } { $snippet "3 narray" } }
28         { { $link 4array } { $snippet "4 narray" } }
29     }
30 } ;
31
32 { nsequence narray } related-words
33
34 HELP: firstn
35 { $values { "n" integer } }
36 { $description "A generalization of " { $link first } ", "
37 { $link first2 } ", " { $link first3 } " and " { $link first4 } " "
38 "that pushes the first " { $snippet "n" } " elements of a sequence on the stack."
39 }
40 { $examples
41     "Some core words expressed in terms of " { $link firstn } ":"
42     { $table
43         { { $link first } { $snippet "1 firstn" } }
44         { { $link first2 } { $snippet "2 firstn" } }
45         { { $link first3 } { $snippet "3 firstn" } }
46         { { $link first4 } { $snippet "4 firstn" } }
47     }
48 } ;
49
50 HELP: set-firstn
51 { $values { "n" integer } }
52 { $description "A generalization of " { $link set-first } " "
53 "that sets the first " { $snippet "n" } " elements of a sequence from the top " { $snippet "n" } " elements of the stack." } ;
54
55 HELP: nappend
56 { $values
57      { "n" integer }
58      { "seq" sequence }
59 }
60 { $description "Outputs a new sequence consisting of the elements of the top " { $snippet "n" } " sequences from the datastack in turn." }
61 { $errors "Throws an error if any of the sequences contain elements that are not permitted in the sequence type of the first sequence." }
62 { $examples
63     { $example "USING: math prettyprint sequences.generalizations ;"
64                "{ 1 2 } { 3 4 } { 5 6 } { 7 8 } 4 nappend ."
65                "{ 1 2 3 4 5 6 7 8 }"
66     }
67 } ;
68
69 HELP: nappend-as
70 { $values
71      { "n" integer } { "exemplar" sequence }
72      { "seq" sequence }
73 }
74 { $description "Outputs a new sequence of type " { $snippet "exemplar" } " consisting of the elements of the top " { $snippet "n" } " sequences from the datastack in turn." }
75 { $errors "Throws an error if any of the sequences contain elements that are not permitted in the sequence type of the first sequence." }
76 { $examples
77     { $example "USING: math prettyprint sequences.generalizations ;"
78                "{ 1 2 } { 3 4 } { 5 6 } { 7 8 } 4 V{ } nappend-as ."
79                "V{ 1 2 3 4 5 6 7 8 }"
80     }
81 } ;
82
83 { nappend nappend-as } related-words
84
85 HELP: neach
86 { $values { "seq..." { $snippet "n" } " sequences on the datastack" } { "quot" { $quotation ( element... -- ) } } { "n" integer } }
87 { $description "A generalization of " { $link each } ", " { $link 2each } ", and " { $link 3each } " that can iterate over any number of sequences in parallel." } ;
88
89 HELP: nmap
90 { $values { "seq..." { $snippet "n" } " sequences on the datastack" } { "quot" { $quotation ( element... -- result ) } } { "n" integer } { "result" "a sequence of the same type as the first " { $snippet "seq" } } }
91 { $description "A generalization of " { $link map } ", " { $link 2map } ", and " { $link 3map } " that can map over any number of sequences in parallel." } ;
92
93 HELP: nmap-as
94 { $values { "seq..." { $snippet "n" } " sequences on the datastack" } { "quot" { $quotation ( element... -- result ) } } { "exemplar" sequence } { "n" integer } { "result" "a sequence of the same type as " { $snippet "exemplar" } } }
95 { $description "A generalization of " { $link map-as } ", " { $link 2map-as } ", and " { $link 3map-as } " that can map over any number of sequences in parallel." } ;
96
97 HELP: mnmap
98 { $values { "m*seq" { $snippet "m" } " sequences on the datastack" } { "quot" { $quotation ( m*element -- result*n ) } } { "m" integer } { "n" integer } { "result*n" { $snippet "n" } " sequences of the same type as the first " { $snippet "seq" } } }
99 { $description "A generalization of " { $link map } ", " { $link 2map } ", and " { $link 3map } " that can map over any number of sequences in parallel and provide any number of output sequences." } ;
100
101 HELP: mnmap-as
102 { $values { "m*seq" { $snippet "m" } " sequences on the datastack" } { "quot" { $quotation ( m*element -- result*n ) } } { "n*exemplar" { $snippet "n" } " sequences on the datastack" } { "m" integer } { "n" integer } { "result*n" { $snippet "n" } " sequences on the datastack of the same types as the " { $snippet "exemplar" } "s" } }
103 { $description "A generalization of " { $link map-as } ", " { $link 2map-as } ", and " { $link 3map-as } " that can map over any number of sequences in parallel and provide any number of output sequences of distinct types." } ;
104
105 HELP: nproduce
106 { $values { "pred" { $quotation ( -- ? ) } } { "quot" { $quotation "( -- obj1 obj2 ... objn )" } } { "n" integer } { "seq..." { $snippet "n" } " arrays on the datastack" } }
107 { $description "A generalization of " { $link produce } " that generates " { $snippet "n" } " arrays in parallel by calling " { $snippet "quot" } " repeatedly until " { $snippet "pred" } " outputs false." } ;
108
109 HELP: nproduce-as
110 { $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" } }
111 { $description "A generalization of " { $link produce-as } " that generates " { $snippet "n" } " sequences in parallel by calling " { $snippet "quot" } " repeatedly until " { $snippet "pred" } " outputs false." } ;
112
113 HELP: nmap-reduce
114 { $values { "map-quot" { $quotation ( element... -- intermediate ) } } { "reduce-quot" { $quotation ( prev intermediate -- next ) } } { "n" integer } }
115 { $description "A generalization of " { $link map-reduce } " that can be applied to any number of sequences." } ;
116
117 HELP: nall?
118 { $values { "seqs..." { $snippet "n" } " sequences on the datastack" } { "quot" { $quotation ( element... -- ? ) } } { "n" integer } { "?" boolean } }
119 { $description "A generalization of " { $link all? } " that can be applied to any number of sequences." } ;
120
121 HELP: nfind
122 { $values { "seqs..." { $snippet "n" } " sequences on the datastack" } { "quot" { $quotation ( element... -- ? ) } } { "n" integer } { "i" integer } { "elts..." { $snippet "n" } " elements on the datastack" } }
123 { $description "A generalization of " { $link find } " that can be applied to any number of sequences." } ;
124
125 HELP: nany?
126 { $values { "seqs..." { $snippet "n" } " sequences on the datastack" } { "quot" { $quotation ( element... -- ? ) } } { "n" integer } { "?" boolean } }
127 { $description "A generalization of " { $link any? } " that can be applied to any number of sequences." } ;
128
129 ARTICLE: "sequences.generalizations" "Generalized sequence words"
130 "The " { $vocab-link "sequences.generalizations" } " vocabulary defines generalized versions of various sequence operations."
131 { $subsections
132     narray
133     nsequence
134     firstn
135     set-firstn
136     nappend
137     nappend-as
138 }
139 "Generalized " { $link "sequences-combinators" } ":"
140 { $subsections
141     neach
142     nmap
143     nmap-as
144     mnmap
145     mnmap-as
146     nproduce
147     nproduce-as
148 } ;
149
150 ABOUT: "sequences.generalizations"