|
From: <jom...@us...> - 2009-04-20 18:39:30
|
Revision: 1489
http://jason.svn.sourceforge.net/jason/?rev=1489&view=rev
Author: jomifred
Date: 2009-04-20 18:39:20 +0000 (Mon, 20 Apr 2009)
Log Message:
-----------
last changes for release 1.3
Modified Paths:
--------------
trunk/applications/jason-eclipse-plugin/build.xml
trunk/build.xml
trunk/doc/faq/faq.tex
trunk/doc/mini-tutorial/src/getting-started/exercise-answers.txt
trunk/release-notes.txt
trunk/src/jason/environment/Environment.java
trunk/src/jason/stdlib/prefix.java
trunk/src/jason/stdlib/puts.java
trunk/src/jason/stdlib/sublist.java
trunk/src/jason/stdlib/suffix.java
trunk/src/test/StdLibTest.java
Modified: trunk/applications/jason-eclipse-plugin/build.xml
===================================================================
--- trunk/applications/jason-eclipse-plugin/build.xml 2009-04-18 11:09:53 UTC (rev 1488)
+++ trunk/applications/jason-eclipse-plugin/build.xml 2009-04-20 18:39:20 UTC (rev 1489)
@@ -12,7 +12,7 @@
<property name="dist.properties" value="${basedir}/bin/dist.properties" />
<property name="version" value="1" />
- <property name="release" value="2" />
+ <property name="release" value="3" />
<property name="distDir" value="${basedir}/dist" />
<property name="distDirPlugins" value="${distDir}/plugins" />
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2009-04-18 11:09:53 UTC (rev 1488)
+++ trunk/build.xml 2009-04-20 18:39:20 UTC (rev 1489)
@@ -15,7 +15,7 @@
<property name="dist.properties" value="${basedir}/bin/dist.properties" />
<property name="version" value="1" />
- <property name="release" value="2.1" />
+ <property name="release" value="3" />
<property name="distDir" value="${env.HOME}/tmp/x/Jason-${version}.${release}" />
<property name="distFile" value="${env.HOME}/Jason-${version}.${release}" />
Modified: trunk/doc/faq/faq.tex
===================================================================
--- trunk/doc/faq/faq.tex 2009-04-18 11:09:53 UTC (rev 1488)
+++ trunk/doc/faq/faq.tex 2009-04-20 18:39:20 UTC (rev 1489)
@@ -17,7 +17,7 @@
\html{\begin{rawhtml}<h0><b><i>Jason</i></b> FAQ
- <br><font size="-1">(for version 1.2)</font></h0>
+ <br><font size="-1">(for version 1.3)</font></h0>
\end{rawhtml}}
\latex{\begin{center}{\Huge\jason FAQ}\end{center}}
Modified: trunk/doc/mini-tutorial/src/getting-started/exercise-answers.txt
===================================================================
--- trunk/doc/mini-tutorial/src/getting-started/exercise-answers.txt 2009-04-18 11:09:53 UTC (rev 1488)
+++ trunk/doc/mini-tutorial/src/getting-started/exercise-answers.txt 2009-04-20 18:39:20 UTC (rev 1489)
@@ -1,173 +1,173 @@
-There are several solutions for the code of the vacuum cleaner
-agent. Here we present and comment on some of them. We start from a very
-reactive solution and finish with a more goal-oriented version.
-
-
-
-1. First solution
-
-----------------------------------------
-+dirty <- suck.
-
-+pos(1) <- right.
-+pos(2) <- down.
-+pos(3) <- up.
-+pos(4) <- left.
-----------------------------------------
-
-* comments
-- this is a reactive agent, which is easy to implement with Jason,
- but note that the language is meant for cognitive agents
-- as a consequence, all plans have an empty context (normally used
- to check the situation currently believed by the agent)
-
-* problems
-- the robot may leave dirt behind, and you will get messages like
- [VCWorld] suck in a clean location!
-- reason: the events related to location ("+pos(...)") are
- selected before the "dirty" event, so the suck action is performed
- after the move action in a possibly clean location
-
-
-2. Second solution
-
-----------------------------------------
-// plans for dirty location
-+pos(1) : dirty <- suck; right.
-+pos(2) : dirty <- suck; down.
-+pos(3) : dirty <- suck; up.
-+pos(4) : dirty <- suck; left.
-
-// plans for clean location
-+pos(1) : clean <- right.
-+pos(2) : clean <- down.
-+pos(3) : clean <- up.
-+pos(4) : clean <- left.
-----------------------------------------
-
-* comments
-- again a rather reactive agent
-- the selection of plans is based on context (perceptual beliefs
- in this case)
-- it solves the problems of the previous solution
-
-* problems
-- the moving strategy is coded in two sets of plans, so to change
- the strategy we need change all plans
-- if you leave the agent running for a long time, it eventually stop.
- the reason is that sometimes the robot does not perceive neither
- dirty nor clean and thus no plan are selected. The following
- code solves that:
-
-----------------------------------------
-// plans for a dirty location
-+pos(1) : dirty <- suck; right.
-+pos(2) : dirty <- suck; down.
-+pos(3) : dirty <- suck; up.
-+pos(4) : dirty <- suck; left.
-
-// plans for other circumstances
-+pos(1) : true <- right.
-+pos(2) : true <- down.
-+pos(3) : true <- up.
-+pos(4) : true <- left.
-----------------------------------------
-
-
-3. Third solution
-
-----------------------------------------
-+pos(_) : dirty <- suck; !move.
-+pos(_) : true <- !move.
-
-// plans to move
-+!move : pos(1) <- right.
-+!move : pos(2) <- down.
-+!move : pos(3) <- up.
-+!move : pos(4) <- left.
-----------------------------------------
-
-* comments
-- the moving strategy is re-factored to use a (perform) goal
- (the goal '!move')
-- this agent reacts to the perception of its location, but the
- reaction creates a new goal (to move)
-- to change the moving strategy we only need to change the
- way the goal "move" is achieved (the plans for triggering
- event '+!move')
-
-* problem
-- suppose that actions may fail, in this case, after performing 'up',
- for example, the agent may remain in the same place and then no new
- location is perceived: the agent will stop moving
- (this is only conceptually a problem since the environment was not
- coded to simulate action failures, i.e., the environment model is
- deterministic).
-
-
-4. Fourth solution
-
-----------------------------------------
-!clean. // initial goal
-
-+!clean : clean <- !move; !!clean.
-+!clean : dirty <- suck; !move; !!clean.
--!clean <- !!clean.
-
-+!move : pos(1) <- right.
-+!move : pos(2) <- down.
-+!move : pos(3) <- up.
-+!move : pos(4) <- left.
-----------------------------------------
-
-* comments
-- this agent is not reactive at all; it has no behaviour which is
- triggered by an external event, that is, a perception of change
- in the environment (note however that BDI agents typically have
- both goal-directed and reactive behaviour)
-- instead, the agent has a *maintenance goal* (the '!clean' goal) and
- is blindly committed towards it (if it ever fails, the goal is just
- adopted again -- see below)
-- this goal is implemented by a form of infinite loop using recursive
- plans: all plans to achieve 'clean' finish by adding 'clean' itself
- as a new goal
-- if anything fails in an attempt to achieve the goal 'clean', the
- contingency plan (-!clean) reintroduces the goal again at all
- circumstances (note the empty plan context); this is what causes the
- "blind commitment" behaviour mentioned above
-- this agent is thus more 'robust' against action failures
-- '!!' is used in the recursions for efficiency, see
- http://jason.sourceforge.net/faq/faq.html#SECTION00075000000000000000
-
-- the use of goals also allows us to easily code plans that handle
- other goals. For instance, suppose we want to code the robot in a way
- that after 2 seconds of cleaning, it makes a break of 1 second. This
- behaviour can be easily code as follows:
-
-
-----------------------------------------
-!clean. // initial goal to clean
-!pause. // initial goal to break
-
-+!clean : clean <- !move; !!clean.
-+!clean : dirty <- suck; !move; !!clean.
--!clean <- !!clean.
-
-+!move : pos(1) <- right.
-+!move : pos(2) <- down.
-+!move : pos(3) <- up.
-+!move : pos(4) <- left.
-
-+!pause
- <- .wait(2000); // suspend this intention (the pause) for 2 seconds
- .suspend(clean); // suspend the clean intention
- .print("I'm having a break, alright.");
- .wait(1000); // suspend this intention again for 1 second
- .print(cleaning);
- .resume(clean); // resume the clean intention
- !!pause.
-----------------------------------------
-
-Just to see how flexible it is to program with goals, you might want
-to try and implement the break strategy for the first (purely reactive)
-solution.
+There are several solutions for the code of the vacuum cleaner
+agent. Here we present and comment on some of them. We start from a very
+reactive solution and finish with a more goal-oriented version.
+
+
+
+1. First solution
+
+----------------------------------------
++dirty <- suck.
+
++pos(1) <- right.
++pos(2) <- down.
++pos(3) <- up.
++pos(4) <- left.
+----------------------------------------
+
+* comments
+- this is a reactive agent, which is easy to implement with Jason,
+ but note that the language is meant for cognitive agents
+- as a consequence, all plans have an empty context (normally used
+ to check the situation currently believed by the agent)
+
+* problems
+- the robot may leave dirt behind, and you will get messages like
+ [VCWorld] suck in a clean location!
+- reason: the events related to location ("+pos(...)") are
+ selected before the "dirty" event, so the suck action is performed
+ after the move action in a possibly clean location
+
+
+2. Second solution
+
+----------------------------------------
+// plans for dirty location
++pos(1) : dirty <- suck; right.
++pos(2) : dirty <- suck; down.
++pos(3) : dirty <- suck; up.
++pos(4) : dirty <- suck; left.
+
+// plans for clean location
++pos(1) : clean <- right.
++pos(2) : clean <- down.
++pos(3) : clean <- up.
++pos(4) : clean <- left.
+----------------------------------------
+
+* comments
+- again a rather reactive agent
+- the selection of plans is based on context (perceptual beliefs
+ in this case)
+- it solves the problems of the previous solution
+
+* problems
+- the moving strategy is coded in two sets of plans, so to change
+ the strategy we need change all plans
+- if you leave the agent running for a long time, it eventually stop.
+ the reason is that sometimes the robot does not perceive neither
+ dirty nor clean and thus no plan are selected. The following
+ code solves that:
+
+----------------------------------------
+// plans for a dirty location
++pos(1) : dirty <- suck; right.
++pos(2) : dirty <- suck; down.
++pos(3) : dirty <- suck; up.
++pos(4) : dirty <- suck; left.
+
+// plans for other circumstances
++pos(1) : true <- right.
++pos(2) : true <- down.
++pos(3) : true <- up.
++pos(4) : true <- left.
+----------------------------------------
+
+
+3. Third solution
+
+----------------------------------------
++pos(_) : dirty <- suck; !move.
++pos(_) : true <- !move.
+
+// plans to move
++!move : pos(1) <- right.
++!move : pos(2) <- down.
++!move : pos(3) <- up.
++!move : pos(4) <- left.
+----------------------------------------
+
+* comments
+- the moving strategy is re-factored to use a (perform) goal
+ (the goal '!move')
+- this agent reacts to the perception of its location, but the
+ reaction creates a new goal (to move)
+- to change the moving strategy we only need to change the
+ way the goal "move" is achieved (the plans for triggering
+ event '+!move')
+
+* problem
+- suppose that actions may fail, in this case, after performing 'up',
+ for example, the agent may remain in the same place and then no new
+ location is perceived: the agent will stop moving
+ (this is only conceptually a problem since the environment was not
+ coded to simulate action failures, i.e., the environment model is
+ deterministic).
+
+
+4. Fourth solution
+
+----------------------------------------
+!clean. // initial goal
+
++!clean : clean <- !move; !!clean.
++!clean : dirty <- suck; !move; !!clean.
+-!clean <- !!clean.
+
++!move : pos(1) <- right.
++!move : pos(2) <- down.
++!move : pos(3) <- up.
++!move : pos(4) <- left.
+----------------------------------------
+
+* comments
+- this agent is not reactive at all; it has no behaviour which is
+ triggered by an external event, that is, a perception of change
+ in the environment (note however that BDI agents typically have
+ both goal-directed and reactive behaviour)
+- instead, the agent has a *maintenance goal* (the '!clean' goal) and
+ is blindly committed towards it (if it ever fails, the goal is just
+ adopted again -- see below)
+- this goal is implemented by a form of infinite loop using recursive
+ plans: all plans to achieve 'clean' finish by adding 'clean' itself
+ as a new goal
+- if anything fails in an attempt to achieve the goal 'clean', the
+ contingency plan (-!clean) reintroduces the goal again at all
+ circumstances (note the empty plan context); this is what causes the
+ "blind commitment" behaviour mentioned above
+- this agent is thus more 'robust' against action failures
+- '!!' is used in the recursions for efficiency, see
+ http://jason.sourceforge.net/faq/faq.html#SECTION00075000000000000000
+
+- the use of goals also allows us to easily code plans that handle
+ other goals. For instance, suppose we want to code the robot in a way
+ that after 2 seconds of cleaning, it makes a break of 1 second. This
+ behaviour can be easily code as follows:
+
+
+----------------------------------------
+!clean. // initial goal to clean
+!pause. // initial goal to break
+
++!clean : clean <- !move; !!clean.
++!clean : dirty <- suck; !move; !!clean.
+-!clean <- !!clean.
+
++!move : pos(1) <- right.
++!move : pos(2) <- down.
++!move : pos(3) <- up.
++!move : pos(4) <- left.
+
++!pause
+ <- .wait(2000); // suspend this intention (the pause) for 2 seconds
+ .suspend(clean); // suspend the clean intention
+ .print("I'm having a break, alright.");
+ .wait(1000); // suspend this intention again for 1 second
+ .print(cleaning);
+ .resume(clean); // resume the clean intention
+ !!pause.
+----------------------------------------
+
+Just to see how flexible it is to program with goals, you might want
+to try and implement the break strategy for the first (purely reactive)
+solution.
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt 2009-04-18 11:09:53 UTC (rev 1488)
+++ trunk/release-notes.txt 2009-04-20 18:39:20 UTC (rev 1489)
@@ -1,5 +1,7 @@
---------------------------
-version 1.2.1
+version 1.3
+
+revision 1489 on SVN
---------------------------
New features
Modified: trunk/src/jason/environment/Environment.java
===================================================================
--- trunk/src/jason/environment/Environment.java 2009-04-18 11:09:53 UTC (rev 1488)
+++ trunk/src/jason/environment/Environment.java 2009-04-20 18:39:20 UTC (rev 1489)
@@ -320,7 +320,7 @@
}
}
}
- });
+ });
}
/**
Modified: trunk/src/jason/stdlib/prefix.java
===================================================================
--- trunk/src/jason/stdlib/prefix.java 2009-04-18 11:09:53 UTC (rev 1488)
+++ trunk/src/jason/stdlib/prefix.java 2009-04-20 18:39:20 UTC (rev 1489)
@@ -54,8 +54,8 @@
*/
public class prefix extends DefaultInternalAction {
- private static final long serialVersionUID = -4736810884249871078L;
- private static InternalAction singleton = null;
+ private static final long serialVersionUID = -4736810884249871078L;
+ private static InternalAction singleton = null;
public static InternalAction create() {
if (singleton == null)
singleton = new prefix();
@@ -64,9 +64,9 @@
// Needs exactly 2 arguments
@Override public int getMinArgs() { return 2; }
- @Override public int getMaxArgs() { return 2; }
+ @Override public int getMaxArgs() { return 2; }
- // improve the check of the arguments to also check the type of the arguments
+ // improve the check of the arguments to also check the type of the arguments
@Override protected void checkArguments(Term[] args) throws JasonException {
super.checkArguments(args); // check number of arguments
if (!args[0].isList() && !args[0].isVar())
@@ -84,7 +84,7 @@
final Term sublist = args[0];
final List<Term> list = ((ListTerm)args[1]).getAsList(); // use a Java List for better performance in remove last
-
+
return new Iterator<Unifier>() {
Unifier c = null; // the current response (which is an unifier)
boolean triedEmpty = false;
@@ -109,14 +109,14 @@
c = un.clone();
if (c.unifiesNoUndo(sublist, candidate)) {
return; // found another sublist, c is the current response
- }
+ }
}
if (!triedEmpty) {
- triedEmpty = true;
- c = un.clone();
+ triedEmpty = true;
+ c = un.clone();
if (c.unifiesNoUndo(sublist, ASSyntax.createList())) {
return; // found another sublist, c is the current response
- }
+ }
}
c = null; // no more sublists found
}
Modified: trunk/src/jason/stdlib/puts.java
===================================================================
--- trunk/src/jason/stdlib/puts.java 2009-04-18 11:09:53 UTC (rev 1488)
+++ trunk/src/jason/stdlib/puts.java 2009-04-20 18:39:20 UTC (rev 1489)
@@ -1,130 +1,130 @@
-package jason.stdlib;
-
-import jason.asSemantics.DefaultInternalAction;
-import jason.asSemantics.InternalAction;
-import jason.asSemantics.TransitionSystem;
-import jason.asSemantics.Unifier;
-import jason.asSyntax.ASSyntax;
-import jason.asSyntax.StringTerm;
-import jason.asSyntax.StringTermImpl;
-import jason.asSyntax.Term;
-import jason.asSyntax.parser.ParseException;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * <p>
- * Internal action: <b><code>.puts</code></b>.
- *
- * <p>
- * Description: used for printing messages to the console where the system is
- * running, or unifying the message to a variable parameter. It receives one
- * string parameter, containing escaped variable names that are replaced by
- * their bindings in the current intention's unifier. Terms are made ground
- * according to the current unifying function before being printed out. No new
- * line is printed after the parameters. In this version a user can also
- * include any Jason expression (logical or arithmetic) that will be replaced
- * by it's evaluated value.
- *
- * <p>
- * The precise format and output device of the message is defined by the Java
- * logging configuration as defined in the <code>logging.properties</code>
- * file in the project directory.
- *
- * <p>
- * Parameters:
- * <ul>
- *
- * <li>+message (string): the string to be printed out.</li>
- * <li>-output (any variable [optional]): the variable to print the processed
- * result.</li>
- *
- * </ul>
- *
- * <p>
- * Example:
- * <ul>
- *
- * <li> <code>.puts("Testing variable #{A}")</code>: prints out to the
- * console the supplied string replacing #{A} with the value of variable A.</li>
- * <li> <code>.puts("Testing variable #{A}, into B", B)</code>: tries to unify
- * B with the supplied string replacing #{A} with the value of variable A.</li>
- * <li> <code>.puts("The value of the expression is #{X+2}")</code>: prints out
- * the result of the X+2 expression. Assuming X is unified to a numeric value,
- * the printed result will be the sum of X and two, if X is unified to any
- * other value, the original expression (X+2) will be printed.</li>
- *
- * </ul>
- *
- * @see act.puts
- * @author Felipe Meneguzzi (http://www.meneguzzi.eu/felipe)
- *
- */
-
-public class puts extends DefaultInternalAction {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- private static InternalAction singleton = null;
-
- public static InternalAction create() {
- if (singleton == null)
- singleton = new puts();
- return singleton;
- }
-
- //Pattern regex = Pattern.compile("#\\{\\p{Upper}\\p{Alnum}*\\}");
- Pattern regex = Pattern.compile("#\\{\\p{ASCII}+\\}");
-
- @Override
- public Object execute(TransitionSystem ts, Unifier un, Term[] args)
- throws Exception {
- if (!args[0].isString()) {
- return false;
- }
-
- StringBuffer sb = new StringBuffer();
- for (Term term : args) {
- if (!term.isString()) {
- continue;
- }
- StringTerm st = (StringTerm) term;
- Matcher matcher = regex.matcher(st.getString());
-
- while (matcher.find()) {
- /*
- * System.out.println("I found the text \""+matcher.group()+ "\"
- * starting at index "+matcher.start()+ " and ending at index
- * "+matcher.end());
- */
- String sVar = matcher.group();
- sVar = sVar.substring(2, sVar.length() - 1);
- try {
- Term t = ASSyntax.parseTerm(sVar);
- //We use t.apply to evaluate any logical or arithmetic expression in Jason
- t.apply(un);
- matcher.appendReplacement(sb, t.toString());
- } catch (ParseException pe) {
- // TODO: handle exception
- // TODO: Decide whether or not we should ignore the exception and print the call instead
- // Right now, if I get a parse error from ASSyntax, I just print the original escaped
- // sequence, so a user can see that his/her expression was problematic
- matcher.appendReplacement(sb, "#{"+sVar+"}");
- }
-
- }
- matcher.appendTail(sb);
- }
-
- if (args[args.length - 1].isVar()) {
- StringTerm stRes = new StringTermImpl(sb.toString());
- return un.unifies(stRes, args[args.length - 1]);
- } else {
- ts.getLogger().info(sb.toString());
- return true;
- }
- }
-}
+package jason.stdlib;
+
+import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.InternalAction;
+import jason.asSemantics.TransitionSystem;
+import jason.asSemantics.Unifier;
+import jason.asSyntax.ASSyntax;
+import jason.asSyntax.StringTerm;
+import jason.asSyntax.StringTermImpl;
+import jason.asSyntax.Term;
+import jason.asSyntax.parser.ParseException;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * <p>
+ * Internal action: <b><code>.puts</code></b>.
+ *
+ * <p>
+ * Description: used for printing messages to the console where the system is
+ * running, or unifying the message to a variable parameter. It receives one
+ * string parameter, containing escaped variable names that are replaced by
+ * their bindings in the current intention's unifier. Terms are made ground
+ * according to the current unifying function before being printed out. No new
+ * line is printed after the parameters. In this version a user can also
+ * include any Jason expression (logical or arithmetic) that will be replaced
+ * by it's evaluated value.
+ *
+ * <p>
+ * The precise format and output device of the message is defined by the Java
+ * logging configuration as defined in the <code>logging.properties</code>
+ * file in the project directory.
+ *
+ * <p>
+ * Parameters:
+ * <ul>
+ *
+ * <li>+message (string): the string to be printed out.</li>
+ * <li>-output (any variable [optional]): the variable to print the processed
+ * result.</li>
+ *
+ * </ul>
+ *
+ * <p>
+ * Example:
+ * <ul>
+ *
+ * <li> <code>.puts("Testing variable #{A}")</code>: prints out to the
+ * console the supplied string replacing #{A} with the value of variable A.</li>
+ * <li> <code>.puts("Testing variable #{A}, into B", B)</code>: tries to unify
+ * B with the supplied string replacing #{A} with the value of variable A.</li>
+ * <li> <code>.puts("The value of the expression is #{X+2}")</code>: prints out
+ * the result of the X+2 expression. Assuming X is unified to a numeric value,
+ * the printed result will be the sum of X and two, if X is unified to any
+ * other value, the original expression (X+2) will be printed.</li>
+ *
+ * </ul>
+ *
+ * @see act.puts
+ * @author Felipe Meneguzzi (http://www.meneguzzi.eu/felipe)
+ *
+ */
+
+public class puts extends DefaultInternalAction {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private static InternalAction singleton = null;
+
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new puts();
+ return singleton;
+ }
+
+ //Pattern regex = Pattern.compile("#\\{\\p{Upper}\\p{Alnum}*\\}");
+ Pattern regex = Pattern.compile("#\\{\\p{ASCII}+\\}");
+
+ @Override
+ public Object execute(TransitionSystem ts, Unifier un, Term[] args)
+ throws Exception {
+ if (!args[0].isString()) {
+ return false;
+ }
+
+ StringBuffer sb = new StringBuffer();
+ for (Term term : args) {
+ if (!term.isString()) {
+ continue;
+ }
+ StringTerm st = (StringTerm) term;
+ Matcher matcher = regex.matcher(st.getString());
+
+ while (matcher.find()) {
+ /*
+ * System.out.println("I found the text \""+matcher.group()+ "\"
+ * starting at index "+matcher.start()+ " and ending at index
+ * "+matcher.end());
+ */
+ String sVar = matcher.group();
+ sVar = sVar.substring(2, sVar.length() - 1);
+ try {
+ Term t = ASSyntax.parseTerm(sVar);
+ //We use t.apply to evaluate any logical or arithmetic expression in Jason
+ t.apply(un);
+ matcher.appendReplacement(sb, t.toString());
+ } catch (ParseException pe) {
+ // TODO: handle exception
+ // TODO: Decide whether or not we should ignore the exception and print the call instead
+ // Right now, if I get a parse error from ASSyntax, I just print the original escaped
+ // sequence, so a user can see that his/her expression was problematic
+ matcher.appendReplacement(sb, "#{"+sVar+"}");
+ }
+
+ }
+ matcher.appendTail(sb);
+ }
+
+ if (args[args.length - 1].isVar()) {
+ StringTerm stRes = new StringTermImpl(sb.toString());
+ return un.unifies(stRes, args[args.length - 1]);
+ } else {
+ ts.getLogger().info(sb.toString());
+ return true;
+ }
+ }
+}
Modified: trunk/src/jason/stdlib/sublist.java
===================================================================
--- trunk/src/jason/stdlib/sublist.java 2009-04-18 11:09:53 UTC (rev 1488)
+++ trunk/src/jason/stdlib/sublist.java 2009-04-20 18:39:20 UTC (rev 1489)
@@ -58,8 +58,8 @@
*/
public class sublist extends DefaultInternalAction {
- private static final long serialVersionUID = -1725808189703510112L;
- private static InternalAction singleton = null;
+ private static final long serialVersionUID = -1725808189703510112L;
+ private static InternalAction singleton = null;
public static InternalAction create() {
if (singleton == null)
singleton = new sublist();
@@ -68,9 +68,9 @@
// Needs exactly 2 arguments
@Override public int getMinArgs() { return 2; }
- @Override public int getMaxArgs() { return 2; }
+ @Override public int getMaxArgs() { return 2; }
- // improve the check of the arguments to also check the type of the arguments
+ // improve the check of the arguments to also check the type of the arguments
@Override protected void checkArguments(Term[] args) throws JasonException {
super.checkArguments(args); // check number of arguments
if (!args[0].isList() && !args[0].isVar())
@@ -83,7 +83,7 @@
public Object execute(TransitionSystem ts, final Unifier un, final Term[] args) throws Exception {
checkArguments(args);
final Term sublist = args[0];
-
+
return new Iterator<Unifier>() {
Unifier c = null; // the current response (which is an unifier)
ListTerm listOutter = ((ListTerm)args[1]);
@@ -109,21 +109,21 @@
ListTerm candidate = ASSyntax.createList(list);
list.remove(list.size()-1);
c = un.clone();
- if (c.unifiesNoUndo(sublist, candidate)) {
- return; // found another sublist, c is the current response
- }
- }
- listOutter = listOutter.getNext();
- if (listOutter == null || listOutter.isVar()) // the case of lists with tail
- break;
- list = listOutter.getAsList();
+ if (c.unifiesNoUndo(sublist, candidate)) {
+ return; // found another sublist, c is the current response
+ }
+ }
+ listOutter = listOutter.getNext();
+ if (listOutter == null || listOutter.isVar()) // the case of lists with tail
+ break;
+ list = listOutter.getAsList();
}
if (!triedEmpty) {
- triedEmpty = true;
- c = un.clone();
+ triedEmpty = true;
+ c = un.clone();
if (c.unifiesNoUndo(sublist, ASSyntax.createList())) {
return; // found another sublist, c is the current response
- }
+ }
}
c = null; // no more sublists found
}
Modified: trunk/src/jason/stdlib/suffix.java
===================================================================
--- trunk/src/jason/stdlib/suffix.java 2009-04-18 11:09:53 UTC (rev 1488)
+++ trunk/src/jason/stdlib/suffix.java 2009-04-20 18:39:20 UTC (rev 1489)
@@ -51,8 +51,8 @@
*/
public class suffix extends DefaultInternalAction {
- private static final long serialVersionUID = 2463927564326061873L;
- private static InternalAction singleton = null;
+ private static final long serialVersionUID = 2463927564326061873L;
+ private static InternalAction singleton = null;
public static InternalAction create() {
if (singleton == null)
singleton = new suffix();
@@ -61,9 +61,9 @@
// Needs exactly 2 arguments
@Override public int getMinArgs() { return 2; }
- @Override public int getMaxArgs() { return 2; }
+ @Override public int getMaxArgs() { return 2; }
- // improve the check of the arguments to also check the type of the arguments
+ // improve the check of the arguments to also check the type of the arguments
@Override protected void checkArguments(Term[] args) throws JasonException {
super.checkArguments(args); // check number of arguments
if (!args[0].isList() && !args[0].isVar())
@@ -81,7 +81,7 @@
final Term sublist = args[0];
final Iterator<ListTerm> list = ((ListTerm)args[1]).listTermIterator();
-
+
return new Iterator<Unifier>() {
Unifier c = null; // the current response (which is an unifier)
public boolean hasNext() {
@@ -106,7 +106,7 @@
c = un.clone();
if (c.unifiesNoUndo(sublist, ASSyntax.createList(l))) {
return; // found another sublist, c is the current response
- }
+ }
}
c = null; // no more sublists found
}
Modified: trunk/src/test/StdLibTest.java
===================================================================
--- trunk/src/test/StdLibTest.java 2009-04-18 11:09:53 UTC (rev 1488)
+++ trunk/src/test/StdLibTest.java 2009-04-20 18:39:20 UTC (rev 1489)
@@ -442,9 +442,9 @@
@SuppressWarnings("unchecked")
public void testSublist() throws Exception {
-
- /* As for prefix */
- //
+
+ /* As for prefix */
+ //
ListTerm l1 = ListTermImpl.parseList("[a,b,c]");
ListTerm l2 = ListTermImpl.parseList("[a,b]");
ListTerm l3 = ListTermImpl.parseList("[b,c]");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|