1 USING: help.markup help.syntax ;
\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 { $subsection POSTPONE: VALUE: }
\r
7 "To get the value, just call the word. The following words manipulate values:"
\r
8 { $subsection get-value }
\r
9 { $subsection set-value }
\r
10 { $subsection POSTPONE: to: }
\r
11 { $subsection change-value } ;
\r
16 { $syntax "VALUE: word" }
\r
17 { $values { "word" "a word to be created" } }
\r
18 { $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 "USING: values math prettyprint ;"
\r
31 { $values { "word" "a value word" } { "value" "the contents" } }
\r
32 { $description "Gets a value. This should not normally be used, unless the word is not known until runtime." } ;
\r
35 { $values { "value" "a new value" } { "word" "a value word" } }
\r
36 { $description "Sets a value word." } ;
\r
39 { $syntax "... to: value" }
\r
40 { $values { "word" "a value word" } }
\r
41 { $description "Sets a value word." }
\r
44 { $code "foo to: value" }
\r
46 { $code "foo \\ value set-value" }
\r
50 { $values { "word" "a value word" } { "quot" { $quotation "( oldvalue -- newvalue )" } } }
\r
51 { $description "Changes the value using the given quotation." } ;
\r