4.10.4 Action Sequences

An Action Sequence can be entered as an interpreter command. It has the form

{} (the empty action sequence)

or 

Act1 ; Act2 ; ... ; Actn, n>1

with each Acti one of:

  • an action call: ActExp(Exp1,...,Expk), k>=0, where each Expi is an expression - a term that may contain function calls - and ActExp is an expression returning a k-ary action a’.
  • a query action call: ?(Cond) - find at most one solution to the relation query Cond and raises an exception if no solution exists.
  • an iterated action (an action forall):
    forall UVars {exists EVars1 SimpleConj ~>
                  exists EVars2 SimpleActSeq}   
    

    The constraints on variables is the same as for the relational forall.

    This provides a form of action iteration. For example, if Agents is a given list of agent handles and Message is a message then

    forall A {A in Agents ~> Message to A}

    will sent the message to each agent in the list.

  • a try-except action for exception handling:
        try { Acts }
        except {
            ExceptionPattern1 :: Cond1 ~> Act1
            ...
            ExceptionPatternn :: Condn ~> Actk
            }
    

    Acts is executed and if no exceptions are raised execution continues after the try_except. If an exception is raised then the action corresponding to the first matching exception pattern for which the corresponding condition is true is excuted and execution continues after the try_except. If no exception patterns match then the exception will be handled by some enclosing try-except. Conditions can be elided if not required.

  • a case action (like a cascading if-then-else in Prolog):
        case {
            Test1  ~> Acts1
            ...
            Testk  ~> Actsk
            }
    

    This executes the first Actsi for which the corresponding guard Testi is true. If no guards are true an action_failure exception is raised.

  • a simple wait action:
    wait(Query)
    
  • a more general wait case action that is similar to case except that it blocks until one of the guards is true or until an optional timeout is reached.
        wait_case {
            Test1  ~> Act1
            ...
            Testk  ~> Actk
            timeout T ~> DefaultAct
            }
    
  • a repeat action:
         repeat Act until Condition
    

    Repeatedly execute Act until Condition is true. The condition is optional and if it’s not given it’s the same as repeat Act until false (like a repeat-fail loop in Prolog). This could be used to implement an interpreter or a linda tuple space server. An alternative is to write the code recursively but the repeat-until approach typically does not require garbage collection.

  • a non-blocking agent message send action: Mess to AgentHandle
  • a blocking single agent message receive action: Mess from AgentHandlePtn
  • a non-blocking thread message send action: Mess to_thread ThreadHandle
  • a blocking thread message receive action: Mess from_thread ThreadHandle
  • a remote query response action:
    respond_remote_query(ID, QueryString, ClientThread).
    
  • a blocking choice message receive action:
        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.

Examples of use and semantics are given in the semantics section.


On This Site