]> gitweb.factorcode.org Git - factor.git/blob - basis/promises/promises-docs.factor
9c26923114a8c8d6f17a415a5f98f2e7a5d33a6b
[factor.git] / basis / promises / promises-docs.factor
1 ! Copyright (C) 2006 Chris Double.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: help.markup help.syntax ;
4 IN: promises
5
6 HELP: <promise>
7 { $values { "quot" { $quotation ( -- x ) } } { "promise" "a promise object" } }
8 { $description "Creates a promise to return a value. When forced this quotation is called and the value returned. The value is memorised so that calling " { $link force } " again does not call the quotation again, instead the previous value is returned directly." } ;
9
10 HELP: force
11 { $values { "promise" "a promise object" } { "value" "a factor object" } }
12 { $description "Calls the quotation associated with the promise if it has not been called before, and returns the value. If the promise has been forced previously, returns the value from the previous call." } ;
13
14 HELP: LAZY:
15 { $syntax "LAZY: word ( stack -- effect ) definition... ;" }
16 { $values { "word" "a new word to define" } { "definition" "a word definition" } }
17 { $description "Creates a lazy word in the current vocabulary. When executed the word will return a " { $link promise } " that when forced, executes the word definition. Any values on the stack that are required by the word definition are captured along with the promise." }
18 { $examples
19   { $example "USING: arrays sequences prettyprint promises ;" "IN: scratchpad" "LAZY: zeroes ( -- pair ) 0 zeroes 2array ;" "zeroes force second force first ." "0" }
20 } ;