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