1 ! Copyright (C) 2004, 2006 Chris Double, Matthew Willis.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays kernel sequences math vectors arrays namespaces call
4 make quotations parser effects stack-checker words accessors ;
7 TUPLE: promise quot forced? value ;
9 : promise ( quot -- promise )
12 : promise-with ( value quot -- promise )
15 : promise-with2 ( value1 value2 quot -- promise )
18 : force ( promise -- value )
19 #! Force the given promise leaving the value of calling the
20 #! promises quotation on the stack. Re-forcing the promise
21 #! will return the same value and not recall the quotation.
23 dup quot>> call( -- value ) >>value
28 : stack-effect-in ( quot word -- n )
29 stack-effect [ ] [ infer ] ?if in>> length ;
31 : make-lazy-quot ( word quot -- quot )
34 swap stack-effect-in \ curry <repetition> %
41 make-lazy-quot define ; parsing