1 USING: help.syntax help.markup kernel sequences quotations
\r
2 math arrays combinators ;
\r
6 { $values { "n" integer } }
\r
7 { $description "Adds the top " { $snippet "n" } " stack values." } ;
\r
10 { $values { "n" integer } }
\r
11 { $description "A generalization of " { $link dup } ", "
\r
12 { $link over } " and " { $link pick } " that can work "
\r
13 "for any stack depth. The nth item down the stack will be copied and "
\r
14 "placed on the top of the stack."
\r
18 "USING: kernel generalizations prettyprint"
\r
19 "sequences.generalizations ;"
\r
21 "1 2 3 4 4 npick 5 narray ."
\r
24 "Some core words expressed in terms of " { $link npick } ":"
\r
26 { { $link dup } { $snippet "1 npick" } }
\r
27 { { $link over } { $snippet "2 npick" } }
\r
28 { { $link pick } { $snippet "3 npick" } }
\r
33 { $values { "n" integer } }
\r
34 { $description "A generalization of " { $link dup } ", "
\r
35 { $link 2dup } " and " { $link 3dup } " that can work "
\r
36 "for any number of items. The n topmost items on the stack will be copied and "
\r
37 "placed on the top of the stack."
\r
41 "USING: prettyprint generalizations kernel"
\r
42 "sequences.generalizations ;"
\r
44 "1 2 3 4 4 ndup 8 narray ."
\r
45 "{ 1 2 3 4 1 2 3 4 }"
\r
47 "Some core words expressed in terms of " { $link ndup } ":"
\r
49 { { $link dup } { $snippet "1 ndup" } }
\r
50 { { $link 2dup } { $snippet "2 ndup" } }
\r
51 { { $link 3dup } { $snippet "3 ndup" } }
\r
56 { $values { "n" integer } }
\r
57 { $description "Calls " { $link dup } " enough times that " { $snippet "n" } " references to the element at the top of the stack before " { $snippet "dupn" } " is called are on the top of the stack." }
\r
58 { $notes { $snippet "2 dupn" } " is equivalent to " { $link dup } ". " { $snippet "1 dupn" } " is a no-op. " { $snippet "0 dupn" } " is equivalent to " { $link drop } "." } ;
\r
61 { $values { "n" integer } }
\r
62 { $description "A generalization of " { $link nip } " and " { $link 2nip }
\r
64 "for any number of items."
\r
67 { $example "USING: prettyprint generalizations kernel ;" "1 2 3 4 3 nnip ." "4" }
\r
68 "Some core words expressed in terms of " { $link nnip } ":"
\r
70 { { $link nip } { $snippet "1 nnip" } }
\r
71 { { $link 2nip } { $snippet "2 nnip" } }
\r
76 { $values { "n" integer } }
\r
77 { $description "A generalization of " { $link drop }
\r
79 "for any number of items."
\r
82 { $example "USING: prettyprint generalizations kernel ;" "1 2 3 4 3 ndrop ." "1" }
\r
83 "Some core words expressed in terms of " { $link ndrop } ":"
\r
85 { { $link drop } { $snippet "1 ndrop" } }
\r
86 { { $link 2drop } { $snippet "2 ndrop" } }
\r
87 { { $link 3drop } { $snippet "3 ndrop" } }
\r
92 { $values { "n" integer } }
\r
93 { $description "A generalization of " { $link rot } " that works for any "
\r
94 "number of items on the stack. "
\r
97 { $example "USING: arrays generalizations kernel prettyprint ;" "1 2 3 4 4 nrot 4array ." "{ 2 3 4 1 }" }
\r
98 "Some core words expressed in terms of " { $link nrot } ":"
\r
100 { { $link swap } { $snippet "2 nrot" } }
\r
101 { { $link rot } { $snippet "3 nrot" } }
\r
106 { $values { "n" integer } }
\r
107 { $description "A generalization of " { $link -rot } " that works for any "
\r
108 "number of items on the stack. "
\r
111 { $example "USING: arrays generalizations kernel prettyprint ;" "1 2 3 4 4 -nrot 4array ." "{ 4 1 2 3 }" }
\r
112 "Some core words expressed in terms of " { $link -nrot } ":"
\r
114 { { $link swap } { $snippet "2 -nrot" } }
\r
115 { { $link -rot } { $snippet "3 -nrot" } }
\r
120 { $values { "n" integer } }
\r
121 { $description "A generalization of " { $link dip } " that can work "
\r
122 "for any stack depth. The quotation will be called with a stack that "
\r
123 "has 'n' items removed first. The 'n' items are then put back on the "
\r
124 "stack. The quotation can consume and produce any number of items."
\r
127 { $example "USING: arrays generalizations kernel prettyprint ;" "1 2 [ dup ] 1 ndip 3array ." "{ 1 1 2 }" }
\r
128 { $example "USING: arrays generalizations kernel prettyprint ;" "1 2 3 [ drop ] 2 ndip 2array ." "{ 2 3 }" }
\r
129 "Some core words expressed in terms of " { $link ndip } ":"
\r
131 { { $link dip } { $snippet "1 ndip" } }
\r
132 { { $link 2dip } { $snippet "2 ndip" } }
\r
133 { { $link 3dip } { $snippet "3 ndip" } }
\r
138 { $values { "n" integer } }
\r
139 { $description "A generalization of " { $link keep } " that can work "
\r
140 "for any stack depth. The first " { $snippet "n" } " items after the quotation will be "
\r
141 "saved, the quotation called, and the items restored."
\r
145 "USING: generalizations kernel prettyprint"
\r
146 "sequences.generalizations ;"
\r
148 "1 2 3 4 5 [ drop drop drop drop drop 99 ] 5 nkeep 6 narray ."
\r
151 "Some core words expressed in terms of " { $link nkeep } ":"
\r
153 { { $link keep } { $snippet "1 nkeep" } }
\r
154 { { $link 2keep } { $snippet "2 nkeep" } }
\r
155 { { $link 3keep } { $snippet "3 nkeep" } }
\r
160 { $values { "n" integer } }
\r
161 { $description "A generalization of " { $link curry } " that can work for any stack depth."
\r
164 "Some core words expressed in terms of " { $link ncurry } ":"
\r
166 { { $link curry } { $snippet "1 ncurry" } }
\r
167 { { $link 2curry } { $snippet "2 ncurry" } }
\r
168 { { $link 3curry } { $snippet "3 ncurry" } }
\r
173 { $values { "n" integer } }
\r
174 { $description "A generalization of " { $link with } " that can work for any stack depth."
\r
177 "Some core words expressed in terms of " { $link nwith } ":"
\r
179 { { $link with } { $snippet "1 nwith" } }
\r
184 { $values { "quot" quotation } { "n" integer } }
\r
185 { $description "A generalization of " { $link bi@ } " and " { $link tri@ } " that can work for any stack depth."
\r
188 "Some core words expressed in terms of " { $link napply } ":"
\r
190 { { $link call } { $snippet "1 napply" } }
\r
191 { { $link bi@ } { $snippet "2 napply" } }
\r
192 { { $link tri@ } { $snippet "3 napply" } }
\r
197 { $values { "quots" "a sequence of quotations" } { "n" integer } }
\r
198 { $description "A generalization of " { $link cleave } " and " { $link 2cleave } " that can work for any quotation arity."
\r
201 "Some core words expressed in terms of " { $link ncleave } ":"
\r
203 { { $link cleave } { $snippet "1 ncleave" } }
\r
204 { { $link 2cleave } { $snippet "2 ncleave" } }
\r
209 { $values { "quots" "a sequence of quotations" } { "n" integer } }
\r
210 { $description "A generalization of " { $link spread } " that can work for any quotation arity."
\r
214 { $values { "n" integer } }
\r
215 { $description "Like " { $link cleave } ", but instead of taking a single array of quotations, cleaves using quotations taken from the top " { $snippet "n" } " elements of the datastack." }
\r
216 { $notes "This word can be used with " { $link apply-curry } " to generalize the " { $snippet "bi-curry@ bi" } " or " { $snippet "tri-curry@ tri" } " dataflow patterns." } ;
\r
219 { $values { "n" integer } }
\r
220 { $description "Like " { $link spread } ", but instead of taking a single array of quotations, spreads using quotations taken from the top " { $snippet "n" } " elements of the datastack." }
\r
221 { $notes "This word can be used with " { $link apply-curry } " to generalize the " { $snippet "bi-curry@ bi*" } " or " { $snippet "tri-curry@ tri*" } " dataflow patterns." } ;
\r
224 { $values { "a..." { $snippet "n" } " values on the datastack" } { "quot" quotation } { "n" integer } }
\r
225 { $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@ } "." }
\r
226 { $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*" } "." } ;
\r
229 { $values { "a" object } { "quot..." { $snippet "n" } " quotations on the datastack" } { "n" integer } }
\r
230 { $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 } "." }
\r
231 { $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*" } "." } ;
\r
234 { $values { "a..." { $snippet "n" } " objects on the datastack" } { "quot..." { $snippet "n" } " quotations on the datastack" } { "n" integer } }
\r
235 { $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* } "." }
\r
236 { $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*" } "." } ;
\r
239 { $values { "m" integer } { "n" integer } }
\r
240 { $description "Swaps the top " { $snippet "m" } " stack elements with the " { $snippet "n" } " elements directly underneath." }
\r
242 "Some core words expressed in terms of " { $link mnswap } ":"
\r
244 { { $link swap } { $snippet "1 1 mnswap" } }
\r
245 { { $link rot } { $snippet "2 1 mnswap" } }
\r
246 { { $link -rot } { $snippet "1 2 mnswap" } }
\r
251 { $values { "n" integer } }
\r
252 { $description "Copies the top " { $snippet "n" } " stack elements underneath each one of the " { $snippet "n" } " elements below." }
\r
255 "USING: arrays kernel generalizations prettyprint ;"
\r
256 "\"e1\" \"e2\" \"o1\" \"o2\" 2 nweave [ 3array ] 3dip 3array 2array ."
\r
257 "{ { \"e1\" \"o1\" \"o2\" } { \"e2\" \"o1\" \"o2\" } }"
\r
263 { "n" integer } { "quot" quotation }
\r
264 { "quotquot" quotation }
\r
267 { $example "USING: generalizations prettyprint math ;"
\r
272 { $description "Construct a quotation containing the contents of " { $snippet "seq" } " repeated " { $snippet "n"} " times." } ;
\r
274 ARTICLE: "shuffle-generalizations" "Generalized shuffle words"
\r
287 ARTICLE: "combinator-generalizations" "Generalized combinators"
\r
301 ARTICLE: "other-generalizations" "Additional generalizations"
\r
308 ARTICLE: "generalizations" "Generalized shuffle words and combinators"
\r
309 "The " { $vocab-link "generalizations" } " vocabulary defines a number of stack shuffling words and combinators for use in "
\r
310 "macros where the arity of the input quotations depends on an "
\r
313 "shuffle-generalizations"
\r
314 "combinator-generalizations"
\r
315 "other-generalizations"
\r
317 "Also see the " { $vocab-link "sequences.generalizations" } " vocabulary for generalized sequence operations." ;
\r
319 ABOUT: "generalizations"
\r