factor/basis/promises/promises.factor

23 lines
613 B
Factor
Raw Normal View History

! 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.
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 ;
: 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?>> [
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
: make-lazy-quot ( quot effect -- quot )
in>> length '[ _ _ ncurry promise ] ;
2007-09-20 18:09:08 -04:00
SYNTAX: LAZY:
(:) [ make-lazy-quot ] [ 2nip ] 3bi define-declared ;