| 
     
      
      
      From: <jom...@us...> - 2009-03-11 08:46:57
      
     
   | 
Revision: 1464
          http://jason.svn.sourceforge.net/jason/?rev=1464&view=rev
Author:   jomifred
Date:     2009-03-11 08:46:55 +0000 (Wed, 11 Mar 2009)
Log Message:
-----------
internal action .wait uses the new syntax for trigger as term
(more details in the API doc of the internal action and release-notes)
Modified Paths:
--------------
    trunk/applications/jason-team/src/asl/dummy.asl
    trunk/applications/jason-team/src/asl/exploration.asl
    trunk/applications/jason-team/src/asl/gaucho.asl
    trunk/applications/jason-team/src/asl/goto.asl
    trunk/applications/jason-team/src/asl/herding.asl
    trunk/release-notes.txt
    trunk/src/jason/asSyntax/InternalActionLiteral.java
    trunk/src/jason/asSyntax/PlanBodyImpl.java
    trunk/src/jason/stdlib/add_plan.java
    trunk/src/jason/stdlib/list.java
    trunk/src/jason/stdlib/list_plans.java
    trunk/src/jason/stdlib/package.html
    trunk/src/jason/stdlib/wait.java
Modified: trunk/applications/jason-team/src/asl/dummy.asl
===================================================================
--- trunk/applications/jason-team/src/asl/dummy.asl	2009-03-10 17:14:12 UTC (rev 1463)
+++ trunk/applications/jason-team/src/asl/dummy.asl	2009-03-11 08:46:55 UTC (rev 1464)
@@ -57,7 +57,7 @@
 +!decide_target
    : not pos(_,_,_)
   <- .print("waiting my location....");
-     .wait("+pos(_,_,_)");
+     .wait({+pos(_,_,_)});
      !decide_target.
 
 +!decide_target                  
@@ -88,13 +88,13 @@
 +!move
     : not pos(_,_,_)
   <- .print("waiting my location....");
-     .wait("+pos(_,_,_)");
+     .wait({+pos(_,_,_)});
      !move.
 
 +!move
    : not target(_,_)
   <- .print("waiting my target....");
-     .wait("+target(_,_)");
+     .wait({+target(_,_)});
      !move.
 
 +!move 
Modified: trunk/applications/jason-team/src/asl/exploration.asl
===================================================================
--- trunk/applications/jason-team/src/asl/exploration.asl	2009-03-10 17:14:12 UTC (rev 1463)
+++ trunk/applications/jason-team/src/asl/exploration.asl	2009-03-11 08:46:55 UTC (rev 1464)
@@ -95,7 +95,7 @@
      // wait others pos
      while( .count(ally_pos(_,_,_), N) & N < 5 ) {
         .print("ooo waiting others pos ");
-        .wait("+ally_pos(_,_,_)", 500, _)
+        .wait({+ally_pos(_,_,_)}, 500, _)
      };
      
      // find distance to even agents
@@ -107,7 +107,7 @@
 +!find_scouter([ag_d(_,AgName)|_],GId)
   <- .print("ooo Ask ",AgName," to play scouter");
      .send(AgName, achieve, play_role(scouter,GId));
-     .wait("+play(AgName,scouter,GId)",2000).  
+     .wait({+play(AgName,scouter,GId)},2000).  
 -!find_scouter([_|LSOdd],GId) // in case the wait fails, try next agent
   <- .print("ooo find_scouter failure, try another agent.");
      !find_scouter(LSOdd,GId).  
@@ -127,8 +127,7 @@
      -+target(TargetX, TargetY).
 	 
 	 /* added by the pattern
-	 .wait("+at_target").
-     //.wait("+pos(_,_,_)"); // wait next cycle
+	 .wait({+at_target}).
      !!goto_near_unvisited[scheme(Sch),mission(Mission)]
 	 */
 	 
@@ -138,7 +137,7 @@
 -!goto_near_unvisited[scheme(Sch),mission(Mission)]
   <- .current_intention(I);
      .print("ooo Failure to goto_near_unvisited ",I);
-     .wait("+pos(_,_,_)"); // wait next cycle
+     .wait({+pos(_,_,_)}); // wait next cycle
      !!goto_near_unvisited[scheme(Sch),mission(Mission)].
 */  
 
Modified: trunk/applications/jason-team/src/asl/gaucho.asl
===================================================================
--- trunk/applications/jason-team/src/asl/gaucho.asl	2009-03-10 17:14:12 UTC (rev 1463)
+++ trunk/applications/jason-team/src/asl/gaucho.asl	2009-03-11 08:46:55 UTC (rev 1464)
@@ -31,10 +31,10 @@
 
 /* -- plans -- */
 
-+?pos(X, Y, S)       <- .wait("+pos(X,Y,S)").
++?pos(X, Y, S)       <- .wait({+pos(X,Y,S)}).
 //+?group_area(Id,G,A) <- .wait("+group_area(Id,G,A)").
-+?gsize(W,H)         <- .wait("+gsize(W,H)").
-+?group(team,G)      <- .wait("+group(team,G)", 500, _); ?group(team,G).
++?gsize(W,H)         <- .wait({+gsize(W,H)}).
++?group(team,G)      <- .wait({+group(team,G)}, 500, _); ?group(team,G).
 +?ally_pos(Name,X,Y) : .my_name(Name) <- ?pos(X,Y,_).
 
 +corral(UpperLeftX,UpperLeftY,DownRightX,DownRightY)
@@ -54,7 +54,7 @@
   <- .print("*** restart -- odd ***");
      ?random_pos(X,Y);
      +target(X,Y);
-     .wait("+at_target",1000,_);
+     .wait({+at_target},1000,_);
      !create_exploration_gr.
 +!restart
   <- .print("*** restart -- even ***"); 
Modified: trunk/applications/jason-team/src/asl/goto.asl
===================================================================
--- trunk/applications/jason-team/src/asl/goto.asl	2009-03-10 17:14:12 UTC (rev 1463)
+++ trunk/applications/jason-team/src/asl/goto.asl	2009-03-11 08:46:55 UTC (rev 1464)
@@ -27,7 +27,7 @@
 +!move
    : not target(_,_)
   <- .print("waiting my target....");
-     .wait("+target(_,_)");
+     .wait({+target(_,_)});
      !move.
 
 +!move 
Modified: trunk/applications/jason-team/src/asl/herding.asl
===================================================================
--- trunk/applications/jason-team/src/asl/herding.asl	2009-03-10 17:14:12 UTC (rev 1463)
+++ trunk/applications/jason-team/src/asl/herding.asl	2009-03-11 08:46:55 UTC (rev 1464)
@@ -126,8 +126,8 @@
          }
        }
      };
-     .wait("+pos(_,_,_)"); // wait an extra step before try to release agents again
-     .wait("+pos(_,_,_)").
+     .wait({+pos(_,_,_)}); // wait an extra step before try to release agents again
+     .wait({+pos(_,_,_)}).
 +!release_boys[scheme(Sch),mission(Mission),group(Gr)].
 
 { end }
@@ -212,8 +212,8 @@
    : not cow(_,_,_)
   <- .print("ooo I see no cow anymore");
      // wait two cycles to decide to change the formation (due to fault perception we may not see the cows)
-	 .wait("+pos(_,_,_)");
-	 .wait("+pos(_,_,_)");
+	 .wait({+pos(_,_,_)});
+	 .wait({+pos(_,_,_)});
 	 if (not cow(_,_,_)) {
 	    .findall(P, play(P,herdboy,Gr), ListBoys);
         !!create_exploration_gr;
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt	2009-03-10 17:14:12 UTC (rev 1463)
+++ trunk/release-notes.txt	2009-03-11 08:46:55 UTC (rev 1464)
@@ -2,6 +2,34 @@
 version 1.2.1
 ---------------------------
 
+New features
+- Plans and Triggers can be used as terms when enclosed by { and }
+  
+  It is used in the following internal actions
+  .relevant_plans
+      e.g.       .relevant_plans({ +!g(_) }, ListOfPlans)
+      instead of .relevant_plans( "+!g(_)" , ListOfPlans)
+  .add_plan
+  .at
+  .wait
+  
+  It is also used in send tellHow
+  .send(bob, tellHow, { +te : c <- a1 }).
+  
+  The advantage is that unification works
+       e.g. .at("now +1 m", {+stop(ID)})
+  and syntax errors are detected at compilation time
+  
+  More complex meta-programming is also possible:
+  .... !myadd( { .print(a); .print(b) } ) .... 
+       // pass the body of the plan as parameter to !myadd
+       
+  +!myadd(Action) <- .add_plan( {+!g : c & b <- Action} ).
+      // add a plan with a fixed event/context and body as the parameter
+      
+  The old style (with strings) continues to work.
+  
+  
 Changes in the GUI
 - When closing the window of MAS Console, the application is also
   stopped.
Modified: trunk/src/jason/asSyntax/InternalActionLiteral.java
===================================================================
--- trunk/src/jason/asSyntax/InternalActionLiteral.java	2009-03-10 17:14:12 UTC (rev 1463)
+++ trunk/src/jason/asSyntax/InternalActionLiteral.java	2009-03-11 08:46:55 UTC (rev 1464)
@@ -30,7 +30,6 @@
 import jason.stdlib.loop;
 
 import java.util.Iterator;
-import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -86,22 +85,6 @@
             return super.apply(u);
     }
     
-    @Override
-    public void countVars(Map<VarTerm, Integer> c) {
-        super.countVars(c);
-        if (this.ia != null && this.ia instanceof jason.stdlib.wait) {
-            // count the vars of first arg
-            if (getTerm(0).isString()) {
-                try {
-                    Trigger te = ASSyntax.parseTrigger( ((StringTerm)getTerm(0)).getString() );
-                    te.getLiteral().countVars(c);
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-            }
-        }
-    }
-    
     @SuppressWarnings("unchecked")
     public Iterator<Unifier> logicalConsequence(Agent ag, Unifier un) {
         if (ag.getTS().getUserAgArch().isRunning()) {
Modified: trunk/src/jason/asSyntax/PlanBodyImpl.java
===================================================================
--- trunk/src/jason/asSyntax/PlanBodyImpl.java	2009-03-10 17:14:12 UTC (rev 1463)
+++ trunk/src/jason/asSyntax/PlanBodyImpl.java	2009-03-11 08:46:55 UTC (rev 1464)
@@ -140,16 +140,22 @@
 
     @Override
     public boolean apply(Unifier u) {
-        // do not apply in next!
-        resetHashCodeCache();
+        // do not apply in next! (except in case this is a term)
+        boolean ok = false;
+        
         if (term != null && term.apply(u)) {
             if (term.isPlanBody()) { // we cannot have "inner" body literals
                 formType = ((PlanBody)term).getBodyType();
                 term     = ((PlanBody)term).getBodyTerm();
             }
-            return true;
+            ok = true;
         }
-        return false;
+        if (next != null && isTerm && next.apply(u))
+            ok = true;
+        
+        if (ok)
+            resetHashCodeCache();
+        return ok;
     }
 
     @Override
Modified: trunk/src/jason/stdlib/add_plan.java
===================================================================
--- trunk/src/jason/stdlib/add_plan.java	2009-03-10 17:14:12 UTC (rev 1463)
+++ trunk/src/jason/stdlib/add_plan.java	2009-03-11 08:46:55 UTC (rev 1464)
@@ -140,7 +140,6 @@
         } else {
             throw JasonException.createWrongArgument(this, "The term '"+t+"' ("+t.getClass().getSimpleName()+") can not be used as a plan for .add_plan.");
         }
-        
         return p;
     }
 }
Modified: trunk/src/jason/stdlib/list.java
===================================================================
--- trunk/src/jason/stdlib/list.java	2009-03-10 17:14:12 UTC (rev 1463)
+++ trunk/src/jason/stdlib/list.java	2009-03-11 08:46:55 UTC (rev 1464)
@@ -33,7 +33,6 @@
   @see jason.stdlib.ground
 
 */
-
 public class list extends DefaultInternalAction {
     
     private static InternalAction singleton = null;
Modified: trunk/src/jason/stdlib/list_plans.java
===================================================================
--- trunk/src/jason/stdlib/list_plans.java	2009-03-10 17:14:12 UTC (rev 1463)
+++ trunk/src/jason/stdlib/list_plans.java	2009-03-11 08:46:55 UTC (rev 1464)
@@ -7,7 +7,21 @@
 import jason.asSyntax.Term;
 import jason.asSyntax.Trigger;
 
-/** list all plans in PL */
+/**
+<p>Internal action: <b><code>.list_plans</code></b>.
+
+<p>Description: prints out the plans in the plan library. 
+
+<p>Parameter:<ul>
+<li>+ trigger (trigger term, [optional]): list only plan that unifies this parameter as trigger event.<br/>
+</ul>
+
+<p>Examples:<ul>
+<li> <code>.list_plans</code>
+<li> <code>.list_plans({ +g(_) })</code>
+</ul>
+
+*/
 public class list_plans extends DefaultInternalAction {
 
     @Override public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
Modified: trunk/src/jason/stdlib/package.html
===================================================================
--- trunk/src/jason/stdlib/package.html	2009-03-10 17:14:12 UTC (rev 1463)
+++ trunk/src/jason/stdlib/package.html	2009-03-11 08:46:55 UTC (rev 1464)
@@ -41,6 +41,7 @@
   <li>{@link jason.stdlib.remove_plan remove_plan}: remove a plan.</li>
   <li>{@link jason.stdlib.plan_label plan_label}: get the label of a plan.</li>
   <li>{@link jason.stdlib.relevant_plans relevant_plans}: get a list of plans.</li>
+  <li>{@link jason.stdlib.list_plans list_plans}: print out the plans in the current plan library.</li>
 </ul>
 
 
Modified: trunk/src/jason/stdlib/wait.java
===================================================================
--- trunk/src/jason/stdlib/wait.java	2009-03-10 17:14:12 UTC (rev 1463)
+++ trunk/src/jason/stdlib/wait.java	2009-03-11 08:46:55 UTC (rev 1464)
@@ -31,13 +31,11 @@
 import jason.asSemantics.Intention;
 import jason.asSemantics.TransitionSystem;
 import jason.asSemantics.Unifier;
-import jason.asSyntax.ASSyntax;
 import jason.asSyntax.InternalActionLiteral;
 import jason.asSyntax.NumberTerm;
 import jason.asSyntax.NumberTermImpl;
 import jason.asSyntax.PlanBody;
 import jason.asSyntax.PlanBodyImpl;
-import jason.asSyntax.StringTerm;
 import jason.asSyntax.Term;
 import jason.asSyntax.Trigger;
 import jason.asSyntax.PlanBody.BodyType;
@@ -49,16 +47,12 @@
   <p>Internal action: <b><code>.wait(<i>E</i>,<i>T</i>)</code></b>.
   
   <p>Description: suspend the intention for the time specified by <i>T</i> (in
-  milliseconds) or until some event <i>E</i> happens. The events are
-  strings in AgentSpeak syntax, e.g. <code>"+bel(33)"</code>,
-  <code>"+!go(X,Y)"</code>. 
+  milliseconds) or until some event <i>E</i> happens. The events follow the 
+  AgentSpeak syntax but are enclosed by { and }, e.g. <code>{+bel(33)}</code>,
+  <code>{+!go(X,Y)}</code>. 
   
-  Although the argument is a string, the variables
-  in the string will be unified with the event, i.e., the unifier might have
-  values for X and Y after the execution of <code>.wait("+!go(X,Y)")</code>.
-
   <p>Parameters:<ul>
-  <li><i>+ event</i> (string): the event to wait for.<br/>
+  <li><i>+ event</i> (trigger term): the event to wait for.<br/>
   <li>+ timeout (number).<br/>
   </ul>
   
@@ -66,18 +60,18 @@
   <p>Examples:<ul>
   <li> <code>.wait(1000)</code>: suspend the intention for 1 second.
 
-  <li> <code>.wait("+b(1)")</code>: suspend the intention until the belief
+  <li> <code>.wait({+b(1)})</code>: suspend the intention until the belief
   <code>b(1)</code> is added in the belief base.
 
-  <li> <code>.wait("+!g", 2000)</code>: suspend the intention until the goal
+  <li> <code>.wait({+!g}, 2000)</code>: suspend the intention until the goal
   <code>g</code> is triggered or 2 seconds have passed, whatever happens
   first. In case the event does not happens in two seconds, the internal action
   fails. 
 
-  <li> <code>.wait("+!g", 2000, EventTime)</code>: suspend the intention until the goal
+  <li> <code>.wait({+!g}, 2000, EventTime)</code>: suspend the intention until the goal
   <code>g</code> is triggered or 2 seconds have passed, whatever happens
   first. 
-  Hence this use of .wait has three arguments, in case the event does not happen in 
+  As this use of .wait has three arguments, in case the event does not happen in 
   two seconds, the internal action does not fail (as in the previous example).
   The third argument will be unified to the 
   elapsed time (in miliseconds) from the start of .wait until the event or timeout. </ul>
@@ -107,10 +101,10 @@
             // time in milliseconds
             NumberTerm time = (NumberTerm)args[0];
             timeout = (long) time.solve();
-        } else if (args[0].isString()) {
+        } else { // if (args[0].isString()) 
             // wait for event
-            te = ASSyntax.parseTrigger( ((StringTerm) args[0]).getString());
-            te.getLiteral().apply(un);
+            te = Trigger.tryToGetTrigger(args[0]); //ASSyntax.parseTrigger( ((StringTerm) args[0]).getString());
+                                                   //te.getLiteral().apply(un);
             
             if (args.length >= 2)
                 timeout = (long) ((NumberTerm) args[1]).solve();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 |