]> gitweb.factorcode.org Git - factor.git/blob - basis/literals/literals-docs.factor
Merge branch 'master' of ../factor-win/
[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 { POSTPONE: $ POSTPONE: $[ } related-words
47
48 ARTICLE: "literals" "Interpolating code results into literal values"
49 "The " { $vocab-link "literals" } " vocabulary contains words to run code at parse time and insert the results into more complex literal values."
50 { $example <"
51 USING: kernel literals math prettyprint ;
52 IN: scratchpad
53
54 << CONSTANT: five 5 >>
55 { $ five $[ five dup 1+ dup 2 + ] } .
56     "> "{ 5 5 6 8 }" }
57 { $subsection POSTPONE: $ }
58 { $subsection POSTPONE: $[ }
59 ;
60
61 ABOUT: "literals"