
register_for_notification(?X, +Tag, ?Receiver)

   Constraint implementation: register for notification

Arguments
   X                   A non-free term, usually a tentative variable
   Tag                 A user-defined term
   Receiver            A notification-receiver (input or output)

Type
   library(tentative)

Description

	
	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
	
		Tag:chg(Old,New)
	
	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.
	
    

Examples
   
    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) :-
	    foreachnotification(tent_trace_demon,
		    I:Notification, [Stream, Name], Receiver, Status, (
		printf(Stream, "%w[%w]: %w%n", [Name,I,Notification])
	    )),
	    ( Status = closed ->
		writeln(Stream, Name:Status),
		kill_suspension(Susp)
	    ; true ).
    

See Also
   library(notify_ports)
