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