Package jason.stdlib
Class nth
java.lang.Object
jason.asSemantics.DefaultInternalAction
jason.stdlib.nth
- All Implemented Interfaces:
InternalAction
,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:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
checkArguments
(Term[] args) static InternalAction
create()
execute
(TransitionSystem ts, Unifier un, Term[] args) Executes the internal action.int
int
Methods inherited from class jason.asSemantics.DefaultInternalAction
canBeUsedInContext, destroy, prepareArguments, suspendIntention
-
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
Description 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:
Exception
-