Package jason.stdlib
Class prefix
java.lang.Object
jason.asSemantics.DefaultInternalAction
jason.stdlib.prefix
- All Implemented Interfaces:
InternalAction
,java.io.Serializable
@Manual(literal=".prefix(prefix,list)", hint="checks if some list is a prefix of other list, backtracking all free variables", argsHint={"the prefix to be checked","the list where the prefix is from"}, argsType={"list","list"}, examples={".prefix([a],[a,b,c]): true",".prefix([a,b],[a,b,c]): true",".prefix([b,c],[a,b,c]): false",".prefix(X,[a,b,c]): unifies X with any prefix of the list, i.e., [a,b,c], [a,b], [a], and [] in this order"}, seeAlso={"jason.stdlib.concat","jason.stdlib.length","jason.stdlib.sublist","jason.stdlib.sort","jason.stdlib.shuffle","jason.stdlib.suffix","jason.stdlib.nth","jason.stdlib.max","jason.stdlib.min","jason.stdlib.reverse","jason.stdlib.difference","jason.stdlib.intersection","jason.stdlib.union"}) public class prefix extends DefaultInternalAction
Internal action: .prefix(P,L)
.
Description: checks if some list/string P is a prefix of list/stringL. If P has free variables, this internal action backtracks all possible values for P.
Parameters:
- +/- prefix (list or string): the prefix to be checked.
- + list (list or string): the list where the prefix is from.
Examples:
-
.prefix([a],[a,b,c])
: true. -
.prefix([a,b],[a,b,c])
: true. -
.prefix([b,c],[a,b,c])
: false. -
.prefix(X,[a,b,c])
: unifies X with any prefix of the list, i.e., [a,b,c], [a,b], [a], and [] in this order; note that this is different from what its usual implementation in logic programming would result, where the various prefixes are returned in increasing lengths instead. -
.prefix("a","abc")
: true. -
.prefix("bc","abc")
: false. -
.prefix(X,"abc")
: unifies X with any prefix of the string, i.e., "abc", "ab", "a", and "" in this order.
- See Also:
concat
,length
,sort
,nth
,max
,min
,reverse
,suffix
,sublist
,difference
,intersection
,union
, Serialized Form
-
Field Summary
Fields Modifier and Type Field Description private static InternalAction
singleton
-
Constructor Summary
Constructors Constructor Description prefix()
-
Method Summary
Modifier and Type Method Description protected void
checkArguments(Term[] args)
static InternalAction
create()
java.lang.Object
execute(TransitionSystem ts, Unifier un, Term[] args)
Executes the internal action.int
getMaxArgs()
int
getMinArgs()
Methods inherited from class jason.asSemantics.DefaultInternalAction
canBeUsedInContext, destroy, prepareArguments, suspendIntention
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
singleton
-
-
Constructor Details
-
prefix
public prefix()
-
-
Method Details
-
create
-
getMinArgs
public int getMinArgs()- Overrides:
getMinArgs
in classDefaultInternalAction
-
getMaxArgs
public int getMaxArgs()- Overrides:
getMaxArgs
in classDefaultInternalAction
-
checkArguments
- Overrides:
checkArguments
in classDefaultInternalAction
- Throws:
JasonException
-
execute
public java.lang.Object execute(TransitionSystem ts, Unifier un, Term[] args) throws java.lang.ExceptionDescription copied from interface:InternalAction
Executes the internal action. It should return a Boolean or an Iterator. A true boolean return means that the IA was successfully executed. An Iterator result means that there is more than one answer for this IA (e.g. see member internal action). - Specified by:
execute
in interfaceInternalAction
- Overrides:
execute
in classDefaultInternalAction
- Throws:
java.lang.Exception
-