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 { $subsections POSTPONE: VALUE: }
\r
7 "To get the value, just call the word. The following words manipulate values:"
\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
23 "USING: values math prettyprint ;"
\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
37 { $values { "value" "a new value" } { "word" "a value word" } }
\r
38 { $description "Sets a value word." } ;
\r
41 { $syntax "... to: value" }
\r
42 { $values { "word" "a value word" } }
\r
43 { $description "Sets a value word." }
\r
46 { $code "foo to: value" }
\r
48 { $code "foo \\ value set-value" }
\r
52 { $values { "word" "a value word" } { "quot" { $quotation "( oldvalue -- newvalue )" } } }
\r
53 { $description "Changes the value using the given quotation." } ;
\r