]> gitweb.factorcode.org Git - factor.git/blob - basis/values/values-docs.factor
docs: change $subsection to $subsections
[factor.git] / basis / values / values-docs.factor
1 USING: help.markup help.syntax ;\r
2 IN: values\r
3 \r
4 ARTICLE: "values" "Global values"\r
5 "Usually, dynamically-scoped variables subsume global variables and are sufficient for holding global data. But occasionally, for global information that's calculated just once and must be accessed more rapidly than a dynamic variable lookup can provide, it's useful to use the word mechanism instead, and set a word to the appropriate value just once. The " { $vocab-link "values" } " vocabulary implements " { $emphasis "values" } ", which abstract over this concept. To create a new word as a value, use the following syntax:"\r
6 { $subsections POSTPONE: VALUE: }\r
7 "To get the value, just call the word. The following words manipulate values:"\r
8 { $subsections\r
9     get-value\r
10     set-value\r
11     POSTPONE: to:\r
12     change-value\r
13 } ;\r
14 \r
15 ABOUT: "values"\r
16 \r
17 HELP: VALUE:\r
18 { $syntax "VALUE: word" }\r
19 { $values { "word" "a word to be created" } }\r
20 { $description "Creates a value on the given word, initializing it to hold " { $snippet "f" } ". To get the value, just run the word. To set it, use " { $link POSTPONE: to: } "." }\r
21 { $examples\r
22   { $example\r
23     "USING: values math prettyprint ;"\r
24     "IN: scratchpad"\r
25     "VALUE: x"\r
26     "2 2 + to: x"\r
27     "x ."\r
28     "4"\r
29   }\r
30 } ;\r
31 \r
32 HELP: get-value\r
33 { $values { "word" "a value word" } { "value" "the contents" } }\r
34 { $description "Gets a value. This should not normally be used, unless the word is not known until runtime." } ;\r
35 \r
36 HELP: set-value\r
37 { $values { "value" "a new value" } { "word" "a value word" } }\r
38 { $description "Sets a value word." } ;\r
39 \r
40 HELP: to:\r
41 { $syntax "... to: value" }\r
42 { $values { "word" "a value word" } }\r
43 { $description "Sets a value word." }\r
44 { $notes\r
45     "Note that"\r
46     { $code "foo to: value" }\r
47     "is just sugar for"\r
48     { $code "foo \\ value set-value" }\r
49 } ;\r
50 \r
51 HELP: change-value\r
52 { $values { "word" "a value word" } { "quot" { $quotation "( oldvalue -- newvalue )" } } }\r
53 { $description "Changes the value using the given quotation." } ;\r