Package jason.stdlib
Class nth
java.lang.Object
jason.asSemantics.DefaultInternalAction
jason.stdlib.nth
- All Implemented Interfaces:
InternalAction
,java.io.Serializable
@Manual(literal=".nth(index,list,term)", hint="gets the nth term of a list", argsHint={"the position of the term (the first term is at position 0)","the list where to get the term from","the term at referred position of the list."}, argsType={"integer","list","term"}, examples={".nth(0,[a,b,c],X): unifies X with a",".nth(2,[a,b,c],X): unifies X with c",".nth(0,[a,b,c],d): false",".nth(0,[a,b,c],a): true",".nth(5,[a,b,c],X): error",".nth(X,[a,b,c,a,e],a): unifies X with 0 (and 3 if it backtracks)"}, seeAlso={"jason.stdlib.concat","jason.stdlib.delete","jason.stdlib.length","jason.stdlib.member","jason.stdlib.sort","jason.stdlib.max","jason.stdlib.min","jason.stdlib.reverse","jason.stdlib.difference","jason.stdlib.intersection","jason.stdlib.union"}) public class nth extends DefaultInternalAction
Internal action: .nth
.
Description: gets the nth term of a list.
Parameters:
- -/+ index (integer): the position of the term (the first term is at position 0)
- + list (list or string): the list/string where to get the term from.
- -/+ term (term): the term at position index in the list.
Examples:
-
.nth(0,[a,b,c],X)
: unifiesX
witha
. -
.nth(2,[a,b,c],X)
: unifiesX
withc
. -
.nth(2,"abc",X)
: unifiesX
withc
. -
.nth(0,[a,b,c],d)
: false. -
.nth(0,[a,b,c],a)
: true. -
.nth(5,[a,b,c],X)
: error. -
.nth(X,[a,b,c,a,e],a)
: unifiesX
with0
(and3
if it backtracks).
- See Also:
concat
,delete
,length
,member
,sort
,max
,min
,reverse
,difference
,intersection
,union
, Serialized Form
-
Field Summary
Fields Modifier and Type Field Description private static InternalAction
singleton
-
Constructor Summary
Constructors Constructor Description nth()
-
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
-
nth
public nth()
-
-
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
-