Handbook
Glossary
force ( lazy -- value )
Vocabulary
lazy
Inputs
lazy
a
lazy
Outputs
value
an
object
Word description
Calls the quotation associated with the lazy if it has not been called before, and returns the value. If the lazy has been forced previously, returns the value from the previous call.
Definition
USING:
accessors
combinators
continuations
kernel
;
IN:
lazy
:
force
( lazy -- value )
dup
status>>
{
{
+error+
[
value>>
throw
]
}
{
+value+
[
value>>
]
}
{
+unforced+
[
[
f
]
change-quot
swap
[
( -- value )
call-effect
[
>>value
+value+
swap
status<<
]
keep
]
curry
[
[
>>value
+error+
swap
status<<
]
keep
throw
]
recover
]
}
}
case
;