]> gitweb.factorcode.org Git - factor.git/blob - basis/promises/promises-docs.factor
Create basis vocab root
[factor.git] / basis / promises / promises-docs.factor
1 ! Copyright (C) 2006 Chris Double.
2 ! See http://factorcode.org/license.txt for BSD license.
3
4 USING: help.markup help.syntax ;
5 IN: promises
6
7 HELP: promise 
8 { $values { "quot" "a quotation with stack effect ( -- X )" } { "promise" "a promise object" } }
9 { $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." } 
10 { $see-also force promise-with promise-with2 } ;
11
12 HELP: promise-with
13 { $values { "value" "an object" } { "quot" "a quotation with stack effect ( value -- X )" } { "promise" "a promise object" } }
14 { $description "Creates a promise to return a value. When forced this quotation is called with the given value on the stack and the result returned. The value is memorised so that calling " { $link force } " again does not call the quotation again, instead the previous value is returned directly." } 
15 { $see-also force promise promise-with2 } ;
16
17 HELP: promise-with2
18 { $values { "value1" "an object" } { "value2" "an object" } { "quot" "a quotation with stack effect ( value1 value2 -- X )" } { "promise" "a promise object" } }
19 { $description "Creates a promise to return a value. When forced this quotation is called with the given values on the stack and the result returned. The value is memorised so that calling " { $link force } " again does not call the quotation again, instead the previous value is returned directly." } 
20 { $see-also force promise promise-with2 } ;
21
22 HELP: force
23 { $values { "promise" "a promise object" } { "value" "a factor object" } }
24 { $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." } 
25 { $see-also promise promise-with promise-with2 } ;
26
27 HELP: LAZY:
28 { $syntax "LAZY: word definition... ;" } 
29 { $values { "word" "a new word to define" } { "definition" "a word definition" } }
30 { $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." } 
31 { $examples
32   { $example "USING: arrays sequences prettyprint promises ;" "IN: scratchpad" "LAZY: zeroes ( -- pair ) 0 zeroes 2array ;" "zeroes force second force first ." "0" }
33 }
34 { $see-also force promise-with promise-with2 } ;