[ library(tentative) | Reference Manual | Alphabetic Index ]

register_for_notification(?X, +Tag, ?Receiver)

Constraint implementation: register for notification
A non-free term, usually a tentative variable
A user-defined term
A notification-receiver (input or output)


This is part of the interface for implementing tentative constraints. It sets up a receiver in the sense of lib(notify_ports), such that every time the tentative value of X changes, a message is sent to this receiver. The message has the form


where Tag is the parameter given here in the setup (e.g. the index of a variable within the constraint where it occurs), Old is the tentative value before the change, and New the tentative value after the change.

The same receiver can register for many variables. Messages from the different variables are distinguished by their Tag.

Such a receiver would typically be used by a demon that is woken up on tentative value change (tent_chg of tentative), to obtain precise information about the changes that caused the wakeup.


    tent_trace_array(Stream, Name, Xs) :-
	    ( foreacharg(X,Xs,I), param(Stream,Name) do
		register_for_notification(X, I, Receiver),
		suspend(tent_trace_demon(Stream, Name, Receiver, Susp),
			1, X->tent_chg, Susp)

	:- demon tent_trace_demon/4.
	tent_trace_demon(Stream, Name, Receiver, Susp) :-
		    I:Notification, [Stream, Name], Receiver, Status, (
		printf(Stream, "%w[%w]: %w%n", [Name,I,Notification])
	    ( Status = closed ->
		writeln(Stream, Name:Status),
	    ; true ).

See Also