[ Advanced Control and Suspensions | Reference Manual | Alphabetic Index ]

suspend(+Goal, +Prio, +CondList, -Susp)

Suspend the Goal and wake it with priority Prio as soon as one of the conditions in CondList occurs.
Goal
A callable term.
Prio
An integer.
CondList
A term of the form Vars->Cond or trigger(Atom) or a list of such terms.
Susp
A free variable used to return the created suspension.

Description

The specified goal Goal is suspended, subject to the given trigger conditions and priority, as with suspend/3. The only difference to suspend/3 is that the Susp argument returns a handle for the created suspension. This handle can, for example, be passed as an argument to the suspended goal itself, which is useful for demon goals which need to kill their own suspension under certain circumstances.

See suspend/3 for details of arguments and operation.

Modes and Determinism

Modules

This predicate is sensitive to its module context (tool predicate, see @/2).

Exceptions

(6) out of range
CondList is ill-formed.

Examples

[eclipse]: suspend(writeln(hello), 2, X->inst, Susp),
        get_suspension_data(Susp, goal, Goal),
        get_suspension_data(Susp, module, Module).

X = X
Goal = writeln(hello)
Susp = 'SUSP-_321-susp'
Module = eclipse

Delayed goals:
        writeln(hello)
yes.


[eclipse]: suspend(writeln(hello), 2, X->inst, Susp),
        kill_suspension(Susp),     % killed before woken
	X=1.

Susp = 'SUSP-_308-dead'
X = 1
yes.



% A demon that wakes whenever X becomes more constrained
report(X) :-
      suspend(report(X, Susp), 1, X->constrained, Susp).

:- demon(report/2).
report(X, Susp) :-
      ( var(X) ->
          writeln(constrained(X))   % implicitly re-suspend
      ;
          writeln(instantiated(X)),
          kill_suspension(Susp)     % remove from the resolvent
      ).

See Also

demon / 1, make_suspension / 3, insert_suspension / 3, suspend / 3, attach_suspensions / 2