public interface Lazy<V>
Lazy<V> designates a possibly lazy value that can be evaluated to give a proper value of type V.
This interface is implemented by all classes that are proper frege values. Hence, every x of type X can be passed or returned where a Lazy<X> is expected, but the inverse is not true.
Note that a variable or argument of type Lazy<Value
> is assignment
compatible with every frege value.
Actual lazy values are introduced when a unary function (see Lambda
)
is applied to a value (see Lambda.apply(frege.rt.Lazy<frege.rt.FV>)
).
(Because application of a n-ary function to a value results in a (n-1)-ary
function for n>1, this will happen everytime a
n-ary function is applied to n arguments.)
Such an application will never evaluate the
value, but rather construct an object of a subclass of Unknown
that
knows how to evaluate the actual value by running the method that implements
the function.
It is suggested to subclass Unknown
to make custom lazy values. In the
case of values whose definition is self-referential, the compiler will
generate code that does just that.
V _e()
Evaluates the lazy value.
Non-lazy values evaluate to themselves by returning this.
Lazy<V> _v()
Performs a single evaluation step.
This function must be implemented in subclasses of Unknown
to do
the real evaluation work. It is invoked by Unknown._e()
, which is itself
final and thus cannot be overridden.
Objects of classes that are not subclasses of Unknown
just
return this.
boolean _u()
Tells if this is a yet unevaluated value.
Unknown
and false in all other cases.
This function helps to avoid instanceof and explicit type conversions.
It is used by Unknown._e()
to decide if another invokation
of Unknown._v()
is needed.
Non-lazy values just return false.