1 ! Copyright (C) 2004 Chris Double.
2 ! See http://factorcode.org/license.txt for BSD license.
4 ! Updated by Matthew Willis, July 2006
5 ! Updated by Chris Double, September 2006
7 USING: arrays kernel sequences math vectors arrays namespaces
8 make quotations parser effects stack-checker words accessors ;
11 TUPLE: promise quot forced? value ;
13 : promise ( quot -- promise )
16 : promise-with ( value quot -- promise )
19 : promise-with2 ( value1 value2 quot -- promise )
22 : force ( promise -- value )
23 #! Force the given promise leaving the value of calling the
24 #! promises quotation on the stack. Re-forcing the promise
25 #! will return the same value and not recall the quotation.
27 dup quot>> call >>value
32 : stack-effect-in ( quot word -- n )
33 stack-effect [ ] [ infer ] ?if in>> length ;
35 : make-lazy-quot ( word quot -- quot )
38 swap stack-effect-in \ curry <repetition> %
45 make-lazy-quot define ; parsing