]> gitweb.factorcode.org Git - factor.git/blob - core/syntax/syntax-docs.factor
The use of factor.com does not fix the issue with missing stdout on Github
[factor.git] / core / syntax / syntax-docs.factor
1 USING: arrays assocs classes.algebra.private classes.maybe
2 classes.tuple combinators command-line effects generic
3 generic.math generic.single help.markup help.syntax io.pathnames
4 kernel math parser sequences vocabs.loader vocabs.parser words
5 words.alias words.constant words.symbol ;
6 IN: syntax
7
8 ARTICLE: "parser-algorithm" "Parser algorithm"
9 "At the most abstract level, Factor syntax consists of whitespace-separated tokens. The parser tokenizes the input on whitespace boundaries. The parser is case-sensitive and whitespace between tokens is significant, so the following three expressions tokenize differently:"
10 { $code "2X+\n2 X +\n2 x +" }
11 "As the parser reads tokens it makes a distinction between numbers, ordinary words, and parsing words. Tokens are appended to the parse tree, the top level of which is a quotation returned by the original parser invocation. Nested levels of the parse tree are created by parsing words."
12 $nl
13 "The parser iterates through the input text, checking each character in turn. Here is the parser algorithm in more detail -- some of the concepts therein will be defined shortly:"
14 { $list
15     { "If the current character is a double-quote (\"), the " { $link POSTPONE: " } " parsing word is executed, causing a string to be read." }
16     {
17         "Otherwise, the next token is taken from the input. The parser searches for a word named by the token in the currently used set of vocabularies. If the word is found, one of the following two actions is taken:"
18         { $list
19             "If the word is an ordinary word, it is appended to the parse tree."
20             "If the word is a parsing word, it is executed."
21         }
22     }
23     "Otherwise if the token does not represent a known word, the parser attempts to parse it as a number. If the token is a number, the number object is added to the parse tree. Otherwise, an error is raised and parsing halts."
24 }
25 "Parsing words play a key role in parsing; while ordinary words and numbers are simply added to the parse tree, parsing words execute in the context of the parser, and can do their own parsing and create nested data structures in the parse tree. Parsing words are also able to define new words."
26 $nl
27 "While parsing words supporting arbitrary syntax can be defined, the default set is found in the " { $vocab-link "syntax" } " vocabulary and provides the basis for all further syntactic interaction with Factor." ;
28
29 ARTICLE: "syntax-immediate" "Parse time evaluation"
30 "Code can be evaluated at parse time. This is a rarely-used feature; one use-case is " { $link "loading-libs" } ", where you want to execute some code before the words in a source file are compiled."
31 { $subsections
32     POSTPONE: <<
33     POSTPONE: >>
34 } ;
35
36 ARTICLE: "syntax-integers" "Integer syntax"
37 "The printed representation of an integer consists of a sequence of digits, optionally prefixed by a sign and arbitrarily separated by commas or underscores."
38 { $code
39     "123456"
40     "-10"
41     "2,432,902,008,176,640,000"
42     "1_000_000"
43 }
44 "Integers are entered in base 10 unless prefixed with a base-changing prefix. " { $snippet "0x" } " begins a hexadecimal literal, " { $snippet "0o" } " an octal literal, and " { $snippet "0b" } " a binary literal. A sign, if any, goes before the base prefix."
45 { $example
46     "USE: prettyprint"
47     "10 ."
48     "0b10 ."
49     "-0o10 ."
50     "0x10 ."
51     "10\n2\n-8\n16"
52 }
53 "More information on integers can be found in " { $link "integers" } "." ;
54
55 ARTICLE: "syntax-ratios" "Ratio syntax"
56 "The printed representation of a ratio is a pair of integers separated by a slash (" { $snippet "/" } "). A ratio can also be written as a proper fraction by following an integer part with " { $snippet "+" } " or " { $snippet "-" } " (matching the sign of the integer) and a ratio. No intermediate whitespace is permitted within a ratio literal. Here are some examples:"
57 { $code
58     "75/33"
59     "1/10"
60     "1+1/3"
61     "-10-1/7"
62 }
63 "More information on ratios can be found in " { $link "rationals" } "." ;
64
65 ARTICLE: "syntax-floats" "Float syntax"
66 "Floating point literals are specified when a literal number contains a decimal point or exponent. Exponents are marked by an " { $snippet "e" } " or " { $snippet "E" } ":"
67 { $code
68     "10.5"
69     "-3.1456"
70     "7e13"
71     "1.0e-5"
72     "1.0E+5"
73 }
74 "Literal numbers without a decimal point or an exponent always parse as integers:"
75 { $example
76     "1 float? ."
77     "f"
78 }
79 { $example
80     "1. float? ."
81     "t"
82 }
83 { $example
84     "1e0 float? ."
85     "t"
86 }
87 "Literal floating point approximations of ratios can also be input by placing a decimal point in the denominator:"
88 { $example
89     "1/2. ."
90     "0.5"
91 }
92 { $example
93     "1/3. ."
94     "0.3333333333333333"
95 }
96 { $example
97     "1/0.5 ."
98     "2.0"
99 }
100 { $example
101     "1/2.5 ."
102     "0.4"
103 }
104 { $example
105     "1+1/2. ."
106     "1.5"
107 }
108 { $example
109     "1+1/2.5 ."
110     "1.4"
111 }
112 "The special float values have their own syntax:"
113 { $table
114 { "Positive infinity" { $snippet "1/0." } }
115 { "Negative infinity" { $snippet "-1/0." } }
116 { "Not-a-number (positive)" { $snippet "0/0." } }
117 { "Not-a-number (negative)" { $snippet "-0/0." } }
118 }
119 "A Not-a-number literal with an arbitrary payload can also be input:"
120 { $subsections POSTPONE: NAN: }
121 "To see the 64 bit value of " { $snippet "0/0." } " on your platform, execute the following code :"
122 { $code
123      "USING: io math math.parser ;"
124      "\"NAN: \" write 0/0. double>bits >hex print"
125 }
126 "Hexadecimal, octal and binary float literals are also supported. These consist of a hexadecimal, octal or binary literal with a decimal point and a mandatory base-two exponent expressed as a decimal number after " { $snippet "p" } " or " { $snippet "P" } ":"
127 { $example
128     "8.0 0x1.0p3 = ."
129     "t"
130 }
131 { $example
132     "-1024.0 -0x1.0P10 = ."
133     "t"
134 }
135 { $example
136     "10.125 0x1.44p3 = ."
137     "t"
138 }
139 { $example
140     "10.125 0b1.010001p3 = ."
141     "t"
142 }
143 { $example
144     "10.125 0o1.21p3 = ."
145     "t"
146 }
147 "The normalized hex form " { $snippet "±0x1.MMMMMMMMMMMMMp±EEEE" } " allows any floating-point number to be specified precisely. The values of MMMMMMMMMMMMM and EEEE map directly to the mantissa and exponent fields of the binary IEEE 754 representation."
148 $nl
149 "More information on floats can be found in " { $link "floats" } "." ;
150
151 ARTICLE: "syntax-complex-numbers" "Complex number syntax"
152 "A complex number is given by two components, a “real” part and “imaginary” part. The components must either be integers, ratios or floats."
153 { $code
154     "C{ 1/2 1/3 }   ! the complex number 1/2+1/3i"
155     "C{ 0 1 }       ! the imaginary unit"
156 }
157 { $subsections POSTPONE: C{ }
158 "More information on complex numbers can be found in " { $link "complex-numbers" } "." ;
159
160 ARTICLE: "syntax-numbers" "Number syntax"
161 "If a vocabulary lookup of a token fails, the parser attempts to parse it as a number."
162 { $subsections
163     "syntax-integers"
164     "syntax-ratios"
165     "syntax-floats"
166     "syntax-complex-numbers"
167 } ;
168
169 ARTICLE: "syntax-words" "Word syntax"
170 "A word occurring inside a quotation is executed when the quotation is called. Sometimes a word needs to be pushed on the data stack instead. The canonical use case for this is passing the word to the " { $link execute } " combinator, or alternatively, reflectively accessing word properties (" { $link "word-props" } ")."
171 { $subsections
172     POSTPONE: \
173     POSTPONE: POSTPONE:
174 }
175 "The implementation of the " { $link POSTPONE: \ } " word is discussed in detail in " { $link "reading-ahead" } ". Words are documented in " { $link "words" } "." ;
176
177 ARTICLE: "escape" "Character escape codes"
178 { $table
179     { { $strong "Escape code" } { $strong "Meaning" } }
180     { { $snippet "\\\\" } { $snippet "\\" } }
181     { { $snippet "\\s" } "a space" }
182     { { $snippet "\\t" } "a tab" }
183     { { $snippet "\\n" } "a newline" }
184     { { $snippet "\\r" } "a carriage return" }
185     { { $snippet "\\b" } "a backspace (ASCII 8)" }
186     { { $snippet "\\v" } "a vertical tab (ASCII 11)" }
187     { { $snippet "\\f" } "a form feed (ASCII 12)" }
188     { { $snippet "\\0" } "a null byte (ASCII 0)" }
189     { { $snippet "\\e" } "escape (ASCII 27)" }
190     { { $snippet "\\\"" } { $snippet "\"" } }
191     { { $snippet "\\x" { $emphasis "xx" } } { "The Unicode code point with hexadecimal number " { $snippet { $emphasis "xx" } } } }
192     { { $snippet "\\u" { $emphasis "xxxxxx" } } { "The Unicode code point with hexadecimal number " { $snippet { $emphasis "xxxxxx" } } } }
193     { { $snippet "\\u{" { $emphasis "xx" } "}" } { "The Unicode code point with hexadecimal number " { $snippet { $emphasis "xx" } } } }
194     { { $snippet "\\u{" { $emphasis "name" } "}" } { "The Unicode code point named " { $snippet { $emphasis "name" } } } }
195     { { $snippet "\\xxx" } "an octal escape specified by one, two, or three octal digits" }
196 } ;
197
198 ARTICLE: "syntax-strings" "Character and string syntax"
199 "Factor has no distinct character type. Integers representing Unicode code points can be read by specifying a literal character, or an escaped representation thereof."
200 { $subsections
201     POSTPONE: CHAR:
202     POSTPONE: "
203     "escape"
204 }
205 "Strings are documented in " { $link "strings" } "." ;
206
207 ARTICLE: "syntax-sbufs" "String buffer syntax"
208 { $subsections POSTPONE: SBUF" }
209 "String buffers are documented in " { $link "sbufs" } "." ;
210
211 ARTICLE: "syntax-arrays" "Array syntax"
212 { $subsections
213     POSTPONE: {
214     POSTPONE: }
215 }
216 "Arrays are documented in " { $link "arrays" } "." ;
217
218 ARTICLE: "syntax-vectors" "Vector syntax"
219 { $subsections POSTPONE: V{ }
220 "Vectors are documented in " { $link "vectors" } "." ;
221
222 ARTICLE: "syntax-hashtables" "Hashtable syntax"
223 { $subsections POSTPONE: H{ }
224 { $subsections POSTPONE: IH{ }
225 "Hashtables are documented in " { $link "hashtables" } " and " { $vocab-link "hashtables.identity" } "." ;
226
227 ARTICLE: "syntax-hash-sets" "Hash set syntax"
228 { $subsections POSTPONE: HS{ }
229 "Hash sets are documented in " { $link "hash-sets" } " and " { $vocab-link "hash-sets.identity" } "." ;
230
231 ARTICLE: "syntax-tuples" "Tuple syntax"
232 { $subsections POSTPONE: T{ }
233 "Tuples are documented in " { $link "tuples" } "." ;
234
235 ARTICLE: "syntax-quots" "Quotation syntax"
236 { $subsections
237     POSTPONE: [
238     POSTPONE: ]
239 }
240 "Quotations are documented in " { $link "quotations" } "." ;
241
242 ARTICLE: "syntax-byte-arrays" "Byte array syntax"
243 { $subsections POSTPONE: B{ }
244 "Byte arrays are documented in " { $link "byte-arrays" } "." ;
245
246 ARTICLE: "syntax-pathnames" "Pathname syntax"
247 { $subsections POSTPONE: P" }
248 "Pathnames are documented in " { $link "io.pathnames" } "." ;
249
250 ARTICLE: "syntax-effects" "Stack effect syntax"
251 "Note that this is " { $emphasis "not" } " syntax to declare stack effects of words. This pushes an " { $link effect } " instance on the stack for reflection, for use with words such as " { $link define-declared } ", " { $link call-effect } " and " { $link execute-effect } "."
252 { $subsections POSTPONE: ( }
253 { $see-also "effects" "inference" "tools.inference" } ;
254
255 ARTICLE: "syntax-literals" "Literals"
256 "Many different types of objects can be constructed at parse time via literal syntax. Numbers are a special case since support for reading them is built-in to the parser. All other literals are constructed via parsing words."
257 $nl
258 "If a quotation contains a literal object, the same literal object instance is used each time the quotation executes; that is, literals are “live”."
259 $nl
260 "Using mutable object literals in word definitions requires care, since if those objects are mutated, the actual word definition will be changed, which is in most cases not what you would expect. Literals should be " { $link clone } "d before being passed to a word which may potentially mutate them."
261 { $subsections
262     "syntax-numbers"
263     "syntax-words"
264     "syntax-quots"
265     "syntax-arrays"
266     "syntax-strings"
267     "syntax-byte-arrays"
268     "syntax-vectors"
269     "syntax-sbufs"
270     "syntax-hashtables"
271     "syntax-hash-sets"
272     "syntax-tuples"
273     "syntax-pathnames"
274     "syntax-effects"
275 } ;
276
277 ARTICLE: "syntax" "Syntax"
278 "Factor has two main forms of syntax: " { $emphasis "definition" } " syntax and " { $emphasis "literal" } " syntax. Code is data, so the syntax for code is a special case of object literal syntax. This section documents literal syntax. Definition syntax is covered in " { $link "words" } ". Extending the parser is the main topic of " { $link "parser" } "."
279 { $subsections
280     "parser-algorithm"
281     "word-search"
282     "top-level-forms"
283     "syntax-literals"
284     "syntax-immediate"
285 } ;
286
287 ABOUT: "syntax"
288
289 HELP: delimiter
290 { $syntax ": foo ... ; delimiter" }
291 { $description "Declares the most recently defined word as a delimiter. Delimiters are words which are only ever valid as the end of a nested block to be read by " { $link parse-until } ". An unpaired occurrence of a delimiter is a parse error." } ;
292
293 HELP: deprecated
294 { $syntax ": foo ... ; deprecated" }
295 { $description "Declares the most recently defined word as deprecated. If the " { $vocab-link "tools.deprecation" } " vocabulary is loaded, usages of deprecated words will be noted by the " { $link "tools.errors" } " system." }
296 { $notes "Code that uses deprecated words continues to function normally; the errors are purely informational. However, code that uses deprecated words should be updated, for the deprecated words are intended to be removed soon." } ;
297
298 HELP: SYNTAX:
299 { $syntax "SYNTAX: foo ... ;" }
300 { $description "Defines a parsing word." }
301 { $examples "In the below example, the " { $snippet "world" } " word is never called, however its body references a parsing word which executes immediately:" { $example "USE: io" "IN: scratchpad" "<< SYNTAX: HELLO \"Hello parser!\" print ; >>\n: world ( -- ) HELLO ;" "Hello parser!" } } ;
302
303 HELP: inline
304 { $syntax ": foo ... ; inline" }
305 { $description
306     "Declares the most recently defined word as an inline word. The optimizing compiler copies definitions of inline words when compiling calls to them."
307     $nl
308     "Combinators must be inlined in order to compile with the optimizing compiler - see " { $link "inference-combinators" } ". For any other word, inlining is merely an optimization. Note that inlined words that can be compiled stand-alone are also, themselves, compiled by the optimizing compiler."
309     $nl
310     "The non-optimizing quotation compiler ignores inlining declarations."
311 } ;
312
313 HELP: recursive
314 { $syntax ": foo ... ; recursive" }
315 { $description "Declares the most recently defined word as a recursive word." }
316 { $notes "This declaration is only required for " { $link POSTPONE: inline } " words which call themselves. See " { $link "inference-recursive-combinators" } "." } ;
317
318 HELP: foldable
319 { $syntax ": foo ... ; foldable" }
320 { $description
321     "Declares that the most recently defined word may be evaluated at compile-time if all inputs are literal. Foldable words must satisfy a very strong contract:"
322     { $list
323         "foldable words must not have any observable side effects,"
324         "foldable words must halt - for example, a word computing a series until it coverges should not be foldable, since compilation will not halt in the event the series does not converge."
325         "both inputs and outputs of foldable words must be immutable."
326     }
327     "The last restriction ensures that words such as " { $link clone } " do not satisfy the foldable word contract. Indeed, " { $link clone } " will output a mutable object if its input is mutable, and so it is undesirable to evaluate it at compile-time, since doing so would give incorrect semantics for code that clones mutable objects and proceeds to mutate them."
328 }
329 { $notes
330     "Folding optimizations are not applied if the call site of a word is in the same source file as the word. This is a side-effect of the compilation unit system; see " { $link "compilation-units" } "."
331 }
332 { $examples "Most operations on numbers are foldable. For example, " { $snippet "2 2 +" } " compiles to a literal 4, since " { $link + } " is declared foldable." } ;
333
334 HELP: flushable
335 { $syntax ": foo ... ; flushable" }
336 { $description
337     "Declares that the most recently defined word has no side effects, and thus calls to this word may be pruned by the compiler if the outputs are not used."
338     $nl
339     "Note that many words are flushable but not foldable, for example " { $link clone } " and " { $link <array> } "."
340 } ;
341
342 HELP: t
343 { $syntax "t" }
344 { $values { "t" "the canonical truth value" } }
345 { $class-description "The canonical truth value, which is an instance of itself." } ;
346
347 HELP: f
348 { $syntax "f" }
349 { $values { "f" "the singleton false value" } }
350 { $description "The " { $link f } " parsing word adds the " { $link f } " object to the parse tree, and is also the class whose sole instance is the " { $link f } " object. The " { $link f } " object is the singleton false value, the only object that is not true. The " { $link f } " object is not equal to the " { $link f } " class word, which can be pushed on the stack using word wrapper syntax:"
351 { $code "f    ! the singleton f object denoting falsity\n\\ f  ! the f class word" } } ;
352
353 HELP: [
354 { $syntax "[ elements... ]" }
355 { $description "Marks the beginning of a literal quotation." }
356 { $examples { $code "[ 1 2 3 ]" } } ;
357
358 { POSTPONE: [ POSTPONE: ] } related-words
359
360 HELP: ]
361 { $syntax "]" }
362 { $description "Marks the end of a literal quotation."
363 $nl
364 "Parsing words can use this word as a generic end delimiter." } ;
365
366 HELP: }
367 { $syntax "}" }
368 { $description "Marks the end of an array, vector, hashtable, complex number, tuple, or wrapper."
369 $nl
370 "Parsing words can use this word as a generic end delimiter." } ;
371
372 { POSTPONE: { POSTPONE: V{ POSTPONE: H{ POSTPONE: HS{ POSTPONE: C{ POSTPONE: T{ POSTPONE: W{ POSTPONE: } } related-words
373
374 HELP: {
375 { $syntax "{ elements... }" }
376 { $values { "elements" "a list of objects" } }
377 { $description "Marks the beginning of a literal array. Literal arrays are terminated by " { $link POSTPONE: } } "." }
378 { $examples { $code "{ 1 2 3 }" } } ;
379
380 HELP: V{
381 { $syntax "V{ elements... }" }
382 { $values { "elements" "a list of objects" } }
383 { $description "Marks the beginning of a literal vector. Literal vectors are terminated by " { $link POSTPONE: } } "." }
384 { $examples { $code "V{ 1 2 3 }" } } ;
385
386 HELP: B{
387 { $syntax "B{ elements... }" }
388 { $values { "elements" "a list of integers" } }
389 { $description "Marks the beginning of a literal byte array. Literal byte arrays are terminated by " { $link POSTPONE: } } "." }
390 { $examples { $code "B{ 1 2 3 }" } } ;
391
392 HELP: intersection{
393 { $syntax "intersection{ elements... }" }
394 { $values { "elements" "a list of classoids" } }
395 { $description "Marks the beginning of a literal " { $link anonymous-intersection } " class." } ;
396
397 HELP: maybe{
398 { $syntax "maybe{ elements... }" }
399 { $values { "elements" "a list of classoids" } }
400 { $description "Marks the beginning of a literal " { $link maybe } " class." } ;
401
402 HELP: not{
403 { $syntax "not{ elements... }" }
404 { $values { "elements" "a list of classoids" } }
405 { $description "Marks the beginning of a literal " { $link anonymous-complement } " class." } ;
406
407 HELP: union{
408 { $syntax "union{ elements... }" }
409 { $values { "elements" "a list of classoids" } }
410 { $description "Marks the beginning of a literal " { $link anonymous-union } " class." } ;
411
412 { POSTPONE: intersection{ POSTPONE: union{ POSTPONE: not{ POSTPONE: maybe{ } related-words
413
414 HELP: H{
415 { $syntax "H{ { key value }... }" }
416 { $values { "key" object } { "value" object } }
417 { $description "Marks the beginning of a literal hashtable, given as a list of two-element arrays holding key/value pairs. Literal hashtables are terminated by " { $link POSTPONE: } } "." }
418 { $examples { $code "H{ { \"tuna\" \"fish\" } { \"jalapeno\" \"vegetable\" } }" } } ;
419
420 HELP: HS{
421 { $syntax "HS{ members ... }" }
422 { $values { "members" "a list of objects" } }
423 { $description "Marks the beginning of a literal hash set, given as a list of its members. Literal hashtables are terminated by " { $link POSTPONE: } } "." }
424 { $examples { $code "HS{ 3 \"foo\" }" } } ;
425
426 HELP: IH{
427 { $syntax "IH{ { key value }... }" }
428 { $values { "key" object } { "value" object } }
429 { $description "Marks the beginning of a literal identity hashtable, given as a list of two-element arrays holding key/value pairs. Literal identity hashtables are terminated by " { $link POSTPONE: } } "." }
430 { $examples { $code "IH{ { \"tuna\" \"fish\" } { \"jalapeno\" \"vegetable\" } }" } } ;
431
432 HELP: C{
433 { $syntax "C{ real-part imaginary-part }" }
434 { $values { "real-part" "a real number" } { "imaginary-part" "a real number" } }
435 { $description "Parses a complex number given in rectangular form as a pair of real numbers. Literal complex numbers are terminated by " { $link POSTPONE: } } "." } ;
436
437 HELP: T{
438 { $syntax "T{ class }" "T{ class f slot-values... }" "T{ class { slot-name slot-value } ... }" }
439 { $values { "class" "a tuple class word" } { "slots" "slot values" } }
440 { $description "Marks the beginning of a literal tuple."
441 $nl
442 "Three literal syntax forms are recognized:"
443 { $list
444     { "empty tuple form: if no slot values are specified, then the literal tuple will have all slots set to their initial values (see " { $link "slot-initial-values" } ")." }
445     { "BOA-form: if the first element of " { $snippet "slots" } " is " { $snippet "f" } ", then the remaining elements are slot values corresponding to slots in the order in which they are defined in the " { $link POSTPONE: TUPLE: } " form." }
446     { "assoc-form: otherwise, " { $snippet "slots" } " is interpreted as a sequence of " { $snippet "{ slot-name value }" } " pairs. The " { $snippet "slot-name" } " should not be quoted." }
447 }
448 "BOA form is more concise, whereas assoc form is more readable for larger tuples with many slots, or if only a few slots are to be specified."
449 $nl
450 "With BOA form, specifying an insufficient number of values is given after the class word, the remaining slots of the tuple are set to their initial values (see " { $link "slot-initial-values" } "). If too many values are given, an error will be raised." }
451 { $examples
452 "An empty tuple; since vectors have their own literal syntax, the above is equivalent to " { $snippet "V{ }" } ""
453 { $code "T{ vector }" }
454 "A BOA-form tuple:"
455 { $code
456     "USE: colors"
457     "T{ rgba f 1.0 0.0 0.5 }"
458 }
459 "An assoc-form tuple equal to the above:"
460 { $code
461     "USE: colors"
462     "T{ rgba { red 1.0 } { green 0.0 } { blue 0.5 } }"
463 } } ;
464
465 HELP: W{
466 { $syntax "W{ object }" }
467 { $values { "object" object } }
468 { $description "Marks the beginning of a literal wrapper. Literal wrappers are terminated by " { $link POSTPONE: } } "." } ;
469
470 HELP: POSTPONE:
471 { $syntax "POSTPONE: word" }
472 { $values { "word" word } }
473 { $description "Reads the next word from the input string and appends the word to the parse tree, even if it is a parsing word." }
474 { $examples "For an ordinary word " { $snippet "foo" } ", " { $snippet "foo" } " and " { $snippet "POSTPONE: foo" } " are equivalent; however, if " { $snippet "foo" } " is a parsing word, the former will execute it at parse time, while the latter will execute it at runtime." }
475 { $notes "This word is used inside parsing words to delegate further action to another parsing word, and to refer to parsing words literally from literal arrays and such." } ;
476
477 HELP: :
478 { $syntax ": word ( stack -- effect ) definition... ;" }
479 { $values { "word" "a new word to define" } { "definition" "a word definition" } }
480 { $description "Defines a word with the given stack effect in the current vocabulary." }
481 { $examples { $code ": ask-name ( -- name )\n    \"What is your name? \" write readln ;\n: greet ( name -- )\n    \"Greetings, \" write print ;\n: friend ( -- )\n    ask-name greet ;" } } ;
482
483 { POSTPONE: : POSTPONE: ; define } related-words
484
485 HELP: ;
486 { $syntax ";" }
487 { $description
488     "Marks the end of a definition."
489     $nl
490     "Parsing words can use this word as a generic end delimiter."
491 } ;
492
493 HELP: SYMBOL:
494 { $syntax "SYMBOL: word" }
495 { $values { "word" "a new word to define" } }
496 { $description "Defines a new symbol word in the current vocabulary. Symbols push themselves on the stack when executed, and are used to identify variables (see " { $link "namespaces" } ") as well as for storing crufties in word properties (see " { $link "word-props" } ")." }
497 { $examples { $example "USE: prettyprint" "IN: scratchpad" "SYMBOL: foo\nfoo ." "foo" } } ;
498
499 { define-symbol POSTPONE: SYMBOL: POSTPONE: SYMBOLS: } related-words
500
501 HELP: SYMBOLS:
502 { $syntax "SYMBOLS: words... ;" }
503 { $values { "words" { $sequence "new words to define" } } }
504 { $description "Creates a new symbol for every token until the " { $snippet ";" } "." }
505 { $examples { $example "USING: prettyprint ;" "IN: scratchpad" "SYMBOLS: foo bar baz ;\nfoo . bar . baz ." "foo\nbar\nbaz" } } ;
506
507 HELP: INITIALIZE:
508 { $syntax "INITIALIZE: word ... ;"  }
509 { $description "If " { $snippet "word" } " does not have a value in the global namespace, calls the definition and assigns the result to " { $snippet "word" } " in the global namespace." }
510 { $examples
511     { $unchecked-example
512         "USING: math namespaces prettyprint ;"
513         "SYMBOL: foo"
514         "INITIALIZE: foo 15 sq ;"
515         "foo get-global ."
516         "225" }
517     { $unchecked-example
518         "USING: math namespaces prettyprint ;"
519         "SYMBOL: foo"
520         "1234 foo set-global"
521         "INITIALIZE: foo 15 sq ;"
522         "foo get-global ."
523         "1234" }
524 } ;
525
526 HELP: SINGLETON:
527 { $syntax "SINGLETON: class" }
528 { $values
529     { "class" "a new singleton to define" }
530 }
531 { $description
532     "Defines a new singleton class. The class word itself is the sole instance of the singleton class."
533 }
534 { $examples
535     { $example "USING: classes.singleton kernel io ;" "IN: singleton-demo" "USE: prettyprint\nSINGLETON: foo\nGENERIC: bar ( obj -- )\nM: foo bar drop \"a foo!\" print ;\nfoo bar" "a foo!" }
536 } ;
537
538 HELP: SINGLETONS:
539 { $syntax "SINGLETONS: words... ;" }
540 { $values { "words" { $sequence "new words to define" } } }
541 { $description "Creates a new singleton for every token until the " { $snippet ";" } "." } ;
542
543 HELP: ALIAS:
544 { $syntax "ALIAS: new-word existing-word" }
545 { $values { "new-word" word } { "existing-word" word } }
546 { $description "Creates a new inlined word that calls the existing word." }
547 { $examples
548     { $example "USING: prettyprint sequences ;"
549                "IN: alias.test"
550                "ALIAS: sequence-nth nth"
551                "0 { 10 20 30 } sequence-nth ."
552                "10"
553     }
554 } ;
555
556 { define-alias POSTPONE: ALIAS: } related-words
557
558 HELP: CONSTANT:
559 { $syntax "CONSTANT: word value" }
560 { $values { "word" word } { "value" object } }
561 { $description "Creates a word which pushes a value on the stack." }
562 { $examples { $code "CONSTANT: magic 1" "CONSTANT: science 0xff0f" } } ;
563
564 { define-constant POSTPONE: CONSTANT: } related-words
565
566 HELP: \
567 { $syntax "\\ word" }
568 { $values { "word" word } }
569 { $description "Reads the next word from the input and appends a wrapper holding the word to the parse tree. When the evaluator encounters a wrapper, it pushes the wrapped word literally on the data stack." }
570 { $examples "The following two lines are equivalent:" { $code "0 \\ <vector> execute\n0 <vector>" } "If " { $snippet "foo" } " is a symbol, the following two lines are equivalent:" { $code "foo" "\\ foo" } } ;
571
572 HELP: DEFER:
573 { $syntax "DEFER: word" }
574 { $values { "word" "a new word to define" } }
575 { $description "Create a word in the current vocabulary that simply raises an error when executed. Usually, the word will be replaced with a real definition later." }
576 { $notes "Due to the way the parser works, words cannot be referenced before they are defined; that is, source files must order definitions in a strictly bottom-up fashion. Mutually-recursive pairs of words can be implemented by " { $emphasis "deferring" } " one of the words in the pair allowing the second word in the pair to parse, then by defining the first word." }
577 { $examples { $code "DEFER: foe\n: fie ... foe ... ;\n: foe ... fie ... ;" } } ;
578
579 HELP: FORGET:
580 { $syntax "FORGET: word" }
581 { $values { "word" word } }
582 { $description "Removes the word from its vocabulary, or does nothing if no such word exists. Existing definitions that reference forgotten words will continue to work, but new occurrences of the word will not parse." } ;
583
584 HELP: USE:
585 { $syntax "USE: vocabulary" }
586 { $values { "vocabulary" "a vocabulary name" } }
587 { $description "Adds a new vocabulary to the search path, loading it first if necessary." }
588 { $notes "If adding the vocabulary introduces ambiguity, referencing the ambiguous names will throw an " { $link ambiguous-use-error } ". You can disambiguate the names by prefixing them with their vocabulary name and a colon: " { $snippet "vocabulary:word" } "." }
589 { $errors "Throws an error if the vocabulary does not exist or could not be loaded." }
590 { $examples "The following two code snippets are equivalent."
591     { $example
592     "USE: math USE: prettyprint"
593     "1 2 + ."
594     "3" }
595     { $example
596     "USE: math USE: prettyprint"
597     "1 2 math:+ prettyprint:."
598     "3" }
599 }
600 { $see-also \ USING: \ QUALIFIED: } ;
601
602 HELP: UNUSE:
603 { $syntax "UNUSE: vocabulary" }
604 { $values { "vocabulary" "a vocabulary name" } }
605 { $description "Removes a vocabulary from the search path." } ;
606
607 HELP: USING:
608 { $syntax "USING: vocabularies... ;" }
609 { $values { "vocabularies" "a list of vocabulary names" } }
610 { $description "Adds a list of vocabularies to the search path." }
611 { $notes "If adding the vocabulary introduces ambiguity, referencing the ambiguous names will throw an " { $link ambiguous-use-error } ". You can disambiguate the names by prefixing them with their vocabulary name and a colon: " { $snippet "vocabulary:word" } "." }
612 { $errors "Throws an error if one of the vocabularies does not exist." }
613 { $examples "The following two code snippets are equivalent."
614     { $example
615     "USING: math prettyprint ;"
616     "1 2 + ."
617     "3" }
618     { $example
619     "USING: math prettyprint ;"
620     "1 2 math:+ prettyprint:."
621     "3" }
622 }
623 { $see-also \ USE: \ QUALIFIED: } ;
624
625 HELP: QUALIFIED:
626 { $syntax "QUALIFIED: vocab" }
627 { $description "Adds the vocabulary's words, prefixed with the vocabulary name, to the search path." }
628 { $notes "If adding a vocabulary introduces ambiguity, the vocabulary will take precedence when resolving any ambiguous names. This is a rare case; for example, suppose a vocabulary " { $snippet "fish" } " defines a word named " { $snippet "go:fishing" } ", and a vocabulary named " { $snippet "go" } " defines a word named " { $snippet "fishing" } ". Then, the following will call the latter word:"
629   { $code
630   "USE: fish"
631   "QUALIFIED: go"
632   "go:fishing"
633   }
634 }
635 { $examples { $example
636     "USING: prettyprint ;"
637     "QUALIFIED: math"
638     "1 2 math:+ ."
639     "3"
640 } } ;
641
642 HELP: QUALIFIED-WITH:
643 { $syntax "QUALIFIED-WITH: vocab word-prefix" }
644 { $description "Like " { $link POSTPONE: QUALIFIED: } " but uses " { $snippet "word-prefix" } " as prefix." }
645 { $examples { $example
646     "USING: prettyprint ;"
647     "QUALIFIED-WITH: math m"
648     "1 2 m:+ ."
649     "3"
650 } } ;
651
652 HELP: FROM:
653 { $syntax "FROM: vocab => words ... ;" }
654 { $description "Adds " { $snippet "words" } " from " { $snippet "vocab" } " to the search path." }
655 { $notes "If adding the words introduces ambiguity, the words will take precedence when resolving any ambiguous names." }
656 { $examples
657   "Both the " { $vocab-link "vocabs.parser" } " and " { $vocab-link "binary-search" } " vocabularies define a word named " { $snippet "search" } ". The following will throw an " { $link ambiguous-use-error } ":"
658   { $code "USING: vocabs.parser binary-search ;" "... search ..." }
659   "Because " { $link POSTPONE: FROM: } " takes precedence over a " { $link POSTPONE: USING: } ", the ambiguity can be resolved explicitly. Suppose you wanted the " { $vocab-link "binary-search" } " vocabulary's " { $snippet "search" } " word:"
660   { $code "USING: vocabs.parser binary-search ;" "FROM: binary-search => search ;" "... search ..." }
661  } ;
662
663 HELP: EXCLUDE:
664 { $syntax "EXCLUDE: vocab => words ... ;" }
665 { $description "Adds all words except for " { $snippet "words" } " from " { $snippet "vocab" } " to the search path." }
666 { $examples { $code
667     "EXCLUDE: math.parser => bin> hex> ;" "! imports everything but bin> and hex>" } } ;
668
669 HELP: RENAME:
670 { $syntax "RENAME: word vocab => new-name" }
671 { $description "Imports " { $snippet "word" } " from " { $snippet "vocab" } ", but renamed to " { $snippet "new-name" } "." }
672 { $notes "If adding the words introduces ambiguity, the words will take precedence when resolving any ambiguous names." }
673 { $examples { $example
674     "USING: prettyprint ;"
675     "RENAME: + math => -"
676     "2 3 - ."
677     "5"
678 } } ;
679
680 HELP: IN:
681 { $syntax "IN: vocabulary" }
682 { $values { "vocabulary" "a new vocabulary name" } }
683 { $description "Sets the current vocabulary where new words will be defined, creating the vocabulary first if it does not exist. After the vocabulary has been created, it can be listed in " { $link POSTPONE: USE: } " and " { $link POSTPONE: USING: } " declarations." } ;
684
685 HELP: CHAR:
686 { $syntax "CHAR: token" }
687 { $values { "token" "a literal character, escape code, or Unicode code point name" } }
688 { $description "Adds a Unicode code point to the parse tree." }
689 { $examples
690     { $code
691         "CHAR: x"
692         "CHAR: \\x32"
693         "CHAR: \\u000032"
694         "CHAR: \\u{32}"
695         "CHAR: \\u{exclamation-mark}"
696         "CHAR: exclamation-mark"
697         "CHAR: ugaritic-letter-samka"
698     }
699 } ;
700
701 HELP: "
702 { $syntax "\"string...\"" }
703 { $values { "string" "literal and escaped characters" } }
704 { $description "Reads from the input string until the next occurrence of " { $snippet "\"" } ", and appends the resulting string to the parse tree. String literals can span multiple lines. Various special characters can be read by inserting " { $link "escape" } "." }
705 { $examples
706     "A string with an escaped newline in it:"
707     { $example "USE: io" "\"Hello\\nworld\" print" "Hello\nworld" }
708     "A string with an actual newline in it:"
709     { $example "USE: io" "\"Hello\nworld\" print" "Hello\nworld" }
710     "A string with a named Unicode code point:"
711     { $example "USE: io" "\"\\u{greek-capital-letter-sigma}\" print" "\u{greek-capital-letter-sigma}" }
712 } ;
713
714 HELP: SBUF"
715 { $syntax "SBUF\" string... \"" }
716 { $values { "string" "literal and escaped characters" } }
717 { $description "Reads from the input string until the next occurrence of " { $link POSTPONE: " } ", converts the string to a string buffer, and appends it to the parse tree." }
718 { $examples { $example "USING: io strings ;" "SBUF\" Hello world\" >string print" "Hello world" } } ;
719
720 HELP: P"
721 { $syntax "P\" pathname\"" }
722 { $values { "pathname" "a pathname string" } }
723 { $description "Reads from the input string until the next occurrence of " { $link POSTPONE: " } ", creates a new " { $link pathname } ", and appends it to the parse tree. Pathnames presented in the UI are clickable, which opens them in a text editor configured with " { $link "editor" } "." }
724 { $examples { $example "USING: accessors io io.files ;" "P\" foo.txt\" string>> print" "foo.txt" } } ;
725
726 HELP: (
727 { $syntax "( inputs -- outputs )" }
728 { $values { "inputs" "a list of tokens" } { "outputs" "a list of tokens" } }
729 { $description "Literal stack effect syntax. Also used by syntax words (such as " { $link POSTPONE: : } "), typically declaring the stack effect of the word definition which follows." }
730 { $notes "Useful for meta-programming with " { $link define-declared } "." }
731 { $examples
732     { $example
733         "USING: compiler.units kernel math prettyprint random words ;"
734         "IN: scratchpad"
735         ""
736         "SYMBOL: my-dynamic-word"
737         ""
738         "["
739         "    my-dynamic-word 2 { [ + ] [ * ] } random curry"
740         "    ( x -- y ) define-declared"
741         "] with-compilation-unit"
742         ""
743         "2 my-dynamic-word ."
744         "4"
745     }
746 }
747 { $see-also "effects" }
748 ;
749
750 HELP: NAN:
751 { $syntax "NAN: payload" }
752 { $values { "payload" "64-bit hexadecimal integer" } }
753 { $description "Adds a floating point Not-a-Number literal to the parse tree." }
754 { $examples
755     { $example
756         "USE: prettyprint"
757         "NAN: 80000deadbeef ."
758         "NAN: 80000deadbeef"
759     }
760 } ;
761
762 HELP: GENERIC:
763 { $syntax "GENERIC: word ( stack -- effect )" }
764 { $values { "word" "a new word to define" } }
765 { $description "Defines a new generic word in the current vocabulary. The word dispatches on the topmost stack element. Initially it contains no methods, and thus will throw a " { $link no-method } " error when called." } ;
766
767 HELP: GENERIC#:
768 { $syntax "GENERIC#: word n ( stack -- effect )" }
769 { $values { "word" "a new word to define" } { "n" "the stack position to dispatch on" } }
770 { $description "Defines a new generic word in the current vocabulary. The word dispatches on the " { $snippet "n" } "th element from the top of the stack. Initially it contains no methods, and thus will throw a " { $link no-method } " error when called." }
771 { $notes
772     "The following two definitions are equivalent:"
773     { $code "GENERIC: foo ( x y z obj -- )" }
774     { $code "GENERIC#: foo 0 ( x y z obj -- )" }
775 } ;
776
777 HELP: MATH:
778 { $syntax "MATH: word" }
779 { $values { "word" "a new word to define" } }
780 { $description "Defines a new generic word which uses the " { $link math-combination } " method combination." } ;
781
782 HELP: HOOK:
783 { $syntax "HOOK: word variable ( stack -- effect )" }
784 { $values { "word" "a new word to define" } { "variable" word } }
785 { $description "Defines a new hook word in the current vocabulary. Hook words are generic words which dispatch on the value of a variable, so methods are defined with " { $link POSTPONE: M: } ". Hook words differ from other generic words in that the dispatch value is removed from the stack before the chosen method is called." }
786 { $examples
787     { $example
788         "USING: io namespaces ;"
789         "IN: scratchpad"
790         "SYMBOL: transport"
791         "TUPLE: land-transport ;"
792         "TUPLE: air-transport ;"
793         "HOOK: deliver transport ( destination -- )"
794         "M: land-transport deliver \"Land delivery to \" write print ;"
795         "M: air-transport deliver \"Air delivery to \" write print ;"
796         "T{ air-transport } transport set"
797         "\"New York City\" deliver"
798         "Air delivery to New York City"
799     }
800 }
801 { $notes
802     "Hook words are really just generic words with a custom method combination (see " { $link "method-combination" } ")."
803 } ;
804
805 HELP: M:
806 { $syntax "M: class generic definition... ;" }
807 { $values { "class" "a class word" } { "generic" "a generic word" } { "definition" "a method definition" } }
808 { $description "Defines a method, that is, a behavior for the generic word specialized on instances of the class." } ;
809
810 HELP: UNION:
811 { $syntax "UNION: class members... ;" }
812 { $values { "class" "a new class word to define" } { "members" "a list of class words separated by whitespace" } }
813 { $description "Defines a union class. An object is an instance of a union class if it is an instance of one of its members." } ;
814
815 HELP: INTERSECTION:
816 { $syntax "INTERSECTION: class participants... ;" }
817 { $values { "class" "a new class word to define" } { "participants" "a list of class words separated by whitespace" } }
818 { $description "Defines an intersection class. An object is an instance of an intersection class if it is an instance of all of its participants." } ;
819
820 HELP: MIXIN:
821 { $syntax "MIXIN: class" }
822 { $values { "class" "a new class word to define" } }
823 { $description "Defines a mixin class. A mixin is similar to a union class, except it has no members initially, and new members can be added with the " { $link POSTPONE: INSTANCE: } " word." }
824 { $examples "The " { $link sequence } " and " { $link assoc } " mixin classes." } ;
825
826 HELP: INSTANCE:
827 { $syntax "INSTANCE: instance mixin" }
828 { $values { "instance" "a class word" } { "mixin" "a mixin class word" } }
829 { $description "Makes " { $snippet "instance" } " an instance of " { $snippet "mixin" } "." } ;
830
831 HELP: PREDICATE:
832 { $syntax "PREDICATE: class < superclass predicate... ;" }
833 { $values { "class" "a new class word to define" } { "superclass" "an existing class word" } { "predicate" "membership test with stack effect " { $snippet "( superclass -- ? )" } } }
834 { $description
835     "Defines a predicate class deriving from " { $snippet "superclass" } "."
836     $nl
837     "An object is an instance of a predicate class if two conditions hold:"
838     { $list
839         "it is an instance of the predicate's superclass,"
840         "it satisfies the predicate"
841     }
842     "Each predicate must be defined as a subclass of some other class. This ensures that predicates inheriting from disjoint classes do not need to be exhaustively tested during method dispatch."
843 }
844 { $examples
845     { $code "USING: math ;" "PREDICATE: positive < integer 0 > ;" }
846 } ;
847
848 HELP: TUPLE:
849 { $syntax "TUPLE: class slots... ;" "TUPLE: class < superclass slots ... ;" }
850 { $values { "class" "a new tuple class to define" } { "slots" "a list of slot specifiers" } }
851 { $description "Defines a new tuple class."
852 $nl
853 "The superclass is optional; if left unspecified, it defaults to " { $link tuple } "."
854 $nl
855 "Slot specifiers take one of the following three forms:"
856 { $list
857     { { $snippet "name" } " - a slot which can hold any object, with no attributes" }
858     { { $snippet "{ name attributes... }" } " - a slot which can hold any object, with optional attributes" }
859     { { $snippet "{ name class attributes... }" } " - a slot specialized to a specific class, with optional attributes" }
860 }
861 "Slot attributes are lists of slot attribute specifiers followed by values; a slot attribute specifier is one of " { $link initial: } " or " { $link read-only } ". See " { $link "tuple-declarations" } " for details." }
862 { $examples
863     "A simple tuple class:"
864     { $code "TUPLE: color red green blue ;" }
865     "Declaring slots to be integer-valued:"
866     { $code "TUPLE: color" "{ red integer }" "{ green integer }" "{ blue integer } ;" }
867     "An example mixing short and long slot specifiers:"
868     { $code "TUPLE: person" "{ age integer initial: 0 }" "{ department string initial: \"Marketing\" }" "manager ;" }
869 } ;
870
871 HELP: final
872 { $syntax "TUPLE: ... ; final" }
873 { $description "Declares the most recently defined word as a final tuple class which cannot be subclassed. Attempting to subclass a final class raises a " { $link bad-superclass } " error." } ;
874
875 HELP: initial:
876 { $syntax "TUPLE: ... { slot initial: value } ... ;" }
877 { $values { "slot" "a slot name" } { "value" "any literal" } }
878 { $description "Specifies an initial value for a tuple slot." } ;
879
880 HELP: read-only
881 { $syntax "TUPLE: ... { slot read-only } ... ;" }
882 { $values { "slot" "a slot name" } }
883 { $description "Defines a tuple slot to be read-only. If a tuple has read-only slots, instances of the tuple should only be created by calling " { $link boa } ", instead of " { $link new } ". Using " { $link boa } " is the only way to set the value of a read-only slot." } ;
884
885 { initial: read-only } related-words
886
887 HELP: SLOT:
888 { $syntax "SLOT: name" }
889 { $values { "name" "a slot name" } }
890 { $description "Defines a protocol slot; that is, defines the accessor words for a slot named " { $snippet "slot" } " without associating it with any specific tuple." } ;
891
892 HELP: ERROR:
893 { $syntax "ERROR: class slots... ;" }
894 { $values { "class" "a new tuple class to define" } { "slots" "a list of slot names" } }
895 { $description "Defines a new tuple class and a word " { $snippet "classname" } " that throws a new instance of the error." }
896 { $notes
897     "The following two snippets are equivalent:"
898     { $code
899         "ERROR: invalid-values x y ;"
900         ""
901         "TUPLE: invalid-values x y ;"
902         ": invalid-values ( x y -- * )"
903         "    \\ invalid-values boa throw ;"
904     }
905 } ;
906
907 HELP: C:
908 { $syntax "C: constructor class" }
909 { $values { "constructor" "a new word to define" } { "class" tuple-class } }
910 { $description "Define a constructor word for a tuple class which simply performs BOA (by order of arguments) construction using " { $link boa } "." }
911 { $examples
912     "Suppose the following tuple has been defined:"
913     { $code "TUPLE: color red green blue ;" }
914     "The following two lines are equivalent:"
915     { $code
916         "C: <color> color"
917         ": <color> ( red green blue -- color ) color boa ;"
918     }
919     "In both cases, a word " { $snippet "<color>" } " is defined, which reads three values from the stack and creates a " { $snippet "color" } " instance having these values in the " { $snippet "red" } ", " { $snippet "green" } " and " { $snippet "blue" } " slots, respectively."
920 } ;
921
922 HELP: MAIN:
923 { $syntax "MAIN: word" }
924 { $values { "word" word } }
925 { $description "Defines the main entry point for the current vocabulary and source file. This word will be executed when this vocabulary is passed to " { $link run } " or the source file is run as a script." } ;
926
927 HELP: <PRIVATE
928 { $syntax "<PRIVATE ... PRIVATE>" }
929 { $description "Begins a block of private word definitions. Private word definitions are placed in the current vocabulary name, suffixed with " { $snippet ".private" } "." }
930 { $notes
931     "The following is an example of usage:"
932     { $code
933         "IN: factorial"
934         ""
935         "<PRIVATE"
936         ""
937         ": (fac) ( accum n -- n! )"
938         "    dup 1 <= [ drop ] [ [ * ] keep 1 - (fac) ] if ;"
939         ""
940         "PRIVATE>"
941         ""
942         ": fac ( n -- n! ) 1 swap (fac) ;"
943     }
944     "The above is equivalent to:"
945     { $code
946         "IN: factorial.private"
947         ""
948         ": (fac) ( accum n -- n! )"
949         "    dup 1 <= [ drop ] [ [ * ] keep 1 - (fac) ] if ;"
950         ""
951         "IN: factorial"
952         ""
953         ": fac ( n -- n! ) 1 swap (fac) ;"
954     }
955 } ;
956
957 HELP: PRIVATE>
958 { $syntax "<PRIVATE ... PRIVATE>" }
959 { $description "Ends a block of private word definitions." } ;
960
961 { POSTPONE: <PRIVATE POSTPONE: PRIVATE> } related-words
962
963 HELP: <<
964 { $syntax "<< ... >>" }
965 { $description "Evaluates some code at parse time." }
966 { $notes "Calling words defined in the same source file at parse time is prohibited; see compilation unit as where it was defined; see " { $link "compilation-units" } "." } ;
967
968 HELP: >>
969 { $syntax ">>" }
970 { $description "Marks the end of a parse time code block." } ;
971
972 HELP: call-next-method
973 { $syntax "call-next-method" }
974 { $description "Calls the next applicable method. Only valid inside a method definition. The values at the top of the stack are passed on to the next method, and they must be compatible with that method's class specializer." }
975 { $notes "This word looks like an ordinary word but it is a parsing word. It cannot be factored out of a method definition, since the code expansion references the current method object directly." }
976 { $errors
977     "Throws a " { $link no-next-method } " error if this is the least specific method, and throws an " { $link inconsistent-next-method } " error if the values at the top of the stack are not compatible with the current method's specializer."
978 } ;
979
980 { POSTPONE: call-next-method (call-next-method) next-method } related-words
981
982 { POSTPONE: << POSTPONE: >> } related-words
983
984 HELP: call(
985 { $syntax "call( stack -- effect )" }
986 { $description "Calls the quotation on the top of the stack, asserting that it has the given stack effect. The quotation does not need to be known at compile time." }
987 { $examples
988   { $code
989     "TUPLE: action name quot ;"
990     ": perform-action ( action -- )"
991     "    [ name>> print ] [ quot>> call( -- ) ] bi ;"
992   }
993 } ;
994
995 HELP: execute(
996 { $syntax "execute( stack -- effect )" }
997 { $description "Calls the word on the top of the stack, asserting that it has the given stack effect. The word does not need to be known at compile time." }
998 { $examples
999   { $code
1000     "IN: scratchpad"
1001     ""
1002     ": eat ( -- ) ; : sleep ( -- ) ; : hack ( -- ) ;"
1003     "{ eat sleep hack } [ execute( -- ) ] each"
1004   }
1005 } ;
1006
1007 { POSTPONE: call( POSTPONE: execute( } related-words
1008
1009 HELP: BUILTIN:
1010 { $syntax "BUILTIN: class slots ... ;" }
1011 { $values { "class" "a builtin class" } { "definition" "a word definition" } }
1012 { $description "A representation of a builtin class from the VM. This word cannot define new builtins but is meant to provide a paper trail to which vocabularies define the builtins. To define new builtins requires adding them to the VM." } ;
1013
1014 HELP: PRIMITIVE:
1015 { $syntax "PRIMITIVE: word ( stack -- effect )" }
1016 { $description "A reference to a primitive word of from the VM. This word cannot define new primitives but is meant to provide a paper trail to which vocabularies define the primitives. To define new primitves requires adding them to the VM." } ;
1017
1018 HELP: MEMO:
1019 { $syntax "MEMO: word ( stack -- effect ) definition... ;" }
1020 { $values { "word" "a new word to define" } { "definition" "a word definition" } }
1021 { $description "Defines the given word at parse time as one which memoizes its output given a particular input. The stack effect is mandatory." } ;
1022
1023 HELP: IDENTITY-MEMO:
1024 { $syntax "IDENTITY-MEMO: word ( stack -- effect ) definition... ;" }
1025 { $values { "word" "a new word to define" } { "definition" "a word definition" } }
1026 { $description "Defines the given word at parse time as one which memoizes its output given a particular input which is identical to another input. The stack effect is mandatory." } ;
1027
1028 HELP: IDENTITY-MEMO::
1029 { $syntax "IDENTITY-MEMO:: word ( stack -- effect ) definition... ;" }
1030 { $values { "word" "a new word to define" } { "definition" "a word definition" } }
1031 { $description "Defines the given word at parse time as one which memoizes its output given a particular input with locals which is identical to another input. The stack effect is mandatory." } ;
1032
1033 HELP: STARTUP-HOOK:
1034 { $syntax "STARTUP-HOOK: word/quotation" }
1035 { $description "Parses a word or a quotation and sets it as the startup hook for the current vocabulary." } ;
1036
1037 HELP: SHUTDOWN-HOOK:
1038 { $syntax "SHUTDOWN-HOOK: word/quotation" }
1039 { $description "Parses a word or a quotation and sets it as the shutdown hook for the current vocabulary." } ;