I have some trouble with an exercise that ask me to implement the classic arg predicate in Prolog.
arg(?Arg, +Term, ?Value)
Where Arg it is the index of the argument in the arguments list of a Term. Value it is the value of this argument.
For example:
arg(1, t(f(X),Y,a), Value)
Value = f(X).
Because f(x) it is the first argument in the arguments list of the t main functor.
So I am tryng to resolve the exercise using the univ =.. predicates in this way:
myArg(ArgIndex, Term, ArgValue) :- integer(ArgIndex),
Term =.. [_|ArgsList],
countArg(ArgsList, ArgIndex, ArgValue).
My idea is that: ArgIndex have to be an integer and I can decompose my Term into its main functor and the aguments list ArgsList and now I have to count the argument (in this list) untill ArgIndex is 0
but I can't count and take this value...