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): unifiesXwitha. -
.nth(2,[a,b,c],X): unifiesXwithc. -
.nth(2,"abc",X): unifiesXwithc. -
.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): unifiesXwith0(and3if it backtracks).
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckArguments(Term[] args) static InternalActioncreate()execute(TransitionSystem ts, Unifier un, Term[] args) Executes the internal action.intintMethods inherited from class jason.asSemantics.DefaultInternalAction
canBeUsedInContext, destroy, prepareArguments, suspendIntention
-
Constructor Details
-
nth
public nth()
-
-
Method Details
-
create
-
getMinArgs
public int getMinArgs()- Overrides:
getMinArgsin classDefaultInternalAction
-
getMaxArgs
public int getMaxArgs()- Overrides:
getMaxArgsin classDefaultInternalAction
-
checkArguments
- Overrides:
checkArgumentsin classDefaultInternalAction- Throws:
JasonException
-
execute
Description copied from interface:InternalActionExecutes 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:
executein interfaceInternalAction- Overrides:
executein classDefaultInternalAction- Throws:
Exception
-