projog

3.49. arg(N,T,A) - allows access to an argument of a structure.

arg(N,T,A) provides a mechanism for accessing a specific argument of a structure. arg(N,T,A) succeeds if the Nth argument of the structure T is, or can be assigned to, A.

Examples

?- arg(2, a(b,c(d)), X).
X = c(d)

yes

?- arg(1, a+(b+c), X ).
X = a

yes

?- arg(1, a+(b+c), b).

no

?- arg(2, [a,b,c], X).
X = [b,c]

yes

?- arg(3, [a,b,c], X).

Cannot get argument at position: 3 from: .(a, .(b, .(c, [])))