2009-02-09 00:06:03 -05:00
|
|
|
! Copyright (C) 2004, 2006 Chris Double, Matthew Willis.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-05-18 13:27:04 -04:00
|
|
|
USING: accessors arrays effects fry generalizations kernel math
|
|
|
|
namespaces parser sequences words ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: promises
|
|
|
|
|
|
|
|
TUPLE: promise quot forced? value ;
|
|
|
|
|
2009-03-22 22:42:01 -04:00
|
|
|
: promise ( quot -- promise ) f f \ promise boa ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: force ( promise -- value )
|
2008-08-29 02:53:34 -04:00
|
|
|
dup forced?>> [
|
2009-02-09 00:06:03 -05:00
|
|
|
dup quot>> call( -- value ) >>value
|
2008-08-29 02:53:34 -04:00
|
|
|
t >>forced?
|
2007-09-20 18:09:08 -04:00
|
|
|
] unless
|
2008-08-29 02:53:34 -04:00
|
|
|
value>> ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-03-22 22:42:01 -04:00
|
|
|
: make-lazy-quot ( quot effect -- quot )
|
|
|
|
in>> length '[ _ _ ncurry promise ] ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-03-21 02:27:50 -04:00
|
|
|
SYNTAX: LAZY:
|
2009-03-22 22:42:01 -04:00
|
|
|
(:) [ make-lazy-quot ] [ 2nip ] 3bi define-declared ;
|