]> gitweb.factorcode.org Git - factor.git/blob - basis/literals/literals-docs.factor
Delete empty unit tests files, remove 1- and 1+, reorder IN: lines in a lot of places...
[factor.git] / basis / literals / literals-docs.factor
1 ! Copyright (C) 2008 Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: help.markup help.syntax kernel multiline ;
4 IN: literals
5
6 HELP: $
7 { $syntax "$ word" }
8 { $description "Executes " { $snippet "word" } " at parse time and adds the result(s) to the parser accumulator." }
9 { $notes { $snippet "word" } "'s definition is looked up and " { $link call } "ed at parse time, so words that reference words in the current compilation unit cannot be used with " { $snippet "$" } "." }
10 { $examples
11
12     { $example <"
13 USING: kernel literals prettyprint ;
14 IN: scratchpad
15
16 CONSTANT: five 5
17 { $ five } .
18     "> "{ 5 }" }
19
20     { $example <"
21 USING: kernel literals prettyprint ;
22 IN: scratchpad
23
24 : seven-eleven ( -- a b ) 7 11 ;
25 { $ seven-eleven } .
26     "> "{ 7 11 }" }
27
28 } ;
29
30 HELP: $[
31 { $syntax "$[ code ]" }
32 { $description "Calls " { $snippet "code" } " at parse time and adds the result(s) to the parser accumulator." }
33 { $notes "Since " { $snippet "code" } " is " { $link call } "ed at parse time, it cannot reference any words defined in the same compilation unit." }
34 { $examples
35
36     { $example <"
37 USING: kernel literals math prettyprint ;
38 IN: scratchpad
39
40 << CONSTANT: five 5 >>
41 { $[ five dup 1 + dup 2 + ] } .
42     "> "{ 5 6 8 }" }
43
44 } ;
45
46 HELP: ${
47 { $syntax "${ code }" }
48 { $description "Outputs an array containing the results of executing " { $snippet "code" } " at parse time." }
49 { $notes { $snippet "code" } "'s definition is looked up and " { $link call } "ed at parse time, so words that reference words in the current compilation unit cannot be used with " { $snippet "$" } "." }
50 { $examples
51
52     { $example <"
53 USING: kernel literals math prettyprint ;
54 IN: scratchpad
55
56 CONSTANT: five 5
57 CONSTANT: six 6
58 ${ five six 7 } .
59     "> "{ 5 6 7 }"
60     }
61 } ;
62
63 { POSTPONE: $ POSTPONE: $[ POSTPONE: ${ } related-words
64
65 ARTICLE: "literals" "Interpolating code results into literal values"
66 "The " { $vocab-link "literals" } " vocabulary contains words to run code at parse time and insert the results into more complex literal values."
67 { $example <"
68 USE: literals
69 IN: scratchpad
70
71 CONSTANT: five 5
72 { $ five $[ five dup 1 + dup 2 + ] } .
73     "> "{ 5 5 6 8 }" }
74 { $subsection POSTPONE: $ }
75 { $subsection POSTPONE: $[ }
76 { $subsection POSTPONE: ${ }
77 ;
78
79 ABOUT: "literals"