Next: , Previous: , Up: Programs   [Contents][Index]


3.10.5 Action Definitions

An action definition consists of a sequence of rules of the form

Head :: Commit ~>> Body

where Head is an atom or simple compound term, Commit is a conjunct of goals, and Body is a sequence of goals and actions. The elements of the sequence are separated by ;. Both the :: Commit and <= Body parts of the rule are optional. The heads of each rule of an action have the same functor and arity.

The semantics of action definitions is the same as for relation definitions. The difference is that at least one of the elements of the Body sequence is an action which typically has a side effect such as writing, reading, sending a message or updating the database.

As examples, the definitions of the actions ask_query and handle_response are given below.

ask_query: (atom,  term?, [term ?], handle)
ask_query(QId,Ans,QList,Ag) ~>>
    ask(QId,Ans,QList) to Ag; Reply from Ag; 
    handle_response(QId,Ag,Reply,Ans)

handle_response: (atom,handle, term?, term?)
handle_response(QId,_,tell(QId,ans(Ans)),Ans) :: true
handle_response(QId,Ag,tell(QId,Reply),_) ~>> 
     writeLine(['Agent ',Ag,' responded ',Reply,' to query ',QId]); fail