When executed, a when
object tests the condition and then evaluates either the then- or
else-function, returning its result. This construct is similar to C and
similar languages Condition ? Then : Else.
The example below illustrates how a method number<-absolute
could be attached to class number
to return its absolute value:
?- send(class(number), get_method,
get_method(absolute, int, new(vector),
when(@receiver < 0,
-(@receiver),
@receiver?value))).
?- new(N, number(-4)),
get(N, absolute, V). ==> V = 4.
<-then
or when<-else
branch is evaluated.|function<-then
or when<-else
is evaluated depending on the result of testing when<-condition.
If this slot contains a function, this function is evaluated and the
result returned. Otherwise the plain value is returned.|function-else
|function, else=any|function