Next: Relation Definitions, Previous: Complex Conjunctions, Up: Programs [Contents][Index]
An Action Sequence can be entered as an interpreter command. It has the form
{}
(the empty action sequence)
or
ActOrQuery1 ; ActOrQuery12 ; ... ; ActOrQueryn, n>=1
with each ActOrQueryi one of:
(...)
bracketed SimpleConj, both preceded by the operator ?
- find at most one solution to a relation query and throws an exception if no solution exists.
do
A, A a variable
forall
):
forall UVars exists EVars1 SimpleConj ~> exists EVars1 SimpleActSeq)
fork
ActCall as Name
wait Query watch Depends after Time do Act
where Query is a simple conjunction, Depends is a list of ++
and --
dynamic relation names, Time is a number of seconds and Act is a simple action sequence.
to
Handle
from
HandlePtn
receive { MessPtn1 from HandlePtn1 :: Test1 ~> Act1 ... ... MessPtnk from HandlePtnk :: Test1k ~> Actk timeout T ~> DefaultAct }
where k>=1 and each Acti and DefaultAct is a Simple Action Sequence and each Test1i is a simple conjunction. The timeout
rule is optional.
A Simple Action Sequence is an Action Sequence which does not contain any forall
, receive
or wait
actions.
When a blocking receive
is executed by a QuLog thread the message buffer
of the thread is searched from the oldest message to the most recent to see if there is a message term
that is an instance of one of the message patterns MessPtni from a sender with handle that is an instance of
HandlePtni. The receive patterns are tried in their given before/after order.
If a message is found that satisfies the two constraints
of the ith rule it is removed, the Acti simple action sequence is executed and the receive is exited. Should the end message buffer be reached with no acceptable message found the thread will suspend until a new message arrives. Each new message is tested for acceptability. If there is a timeout
rule
this will be fired when T seconds have elapsed since the thread started its search for an acceptable message.
DefaultAct is executed and the receive
is exited. If there is no timeout
rule the receive action will block indefinitely waiting for an acceptable message.
The action rules handle_messages
defines a non-terminating message receive behaviour that will process request
and ask
messages of the allowd form from agents allowed to send such messages. It removes all messages not
satisfying either test. There is no action when a messages is discarded.
act handle_messages() handle_messages() receive { request(TaskCall) from Agent :: can_request(Agent,TaskCall) ~> {fork TaskCall as TaskId; remember(taskfor(Agent,TaskId,Task)} ask(Id,Ans,Query) from Agent :: can_ask(Agent,Query) ~> {eval(Query); ans(Id,Ans) to Agent} _ from _ ~> {} }; handle_messages()
An alternative is to send some reply when a message is discarded as in:
handle_messages() receive { request(TaskCall) from Agent :: can_request(Agent,TaskCall) ~> {fork TaskCall as TaskId; remember(taskfor(Agent,TaskId,Task)} request(TaskCall) from Agent ~> cannot_request(TaskCall) to Agent ask(Id,Ans,Query) from Agent :: can_ask(Agent,Query) ~> {eval(Query); ans(Id,Ans) to Agent} ask(Id,Ans,Query) from Agent ~> cannot_ask(Query) to Agent discard Mess from Agent ~> invalid_message(Mess) to Agent }; handle_messages()
Here the second and fourth rules send suitable messages when the tests of the first and third rules have failed for request
and ask
messages, and the last messagesends and invalid_message
response for all other messages.
Next: Relation Definitions, Previous: Complex Conjunctions, Up: Programs [Contents][Index]