?- arg(1,fact(male(fred),23),F).The predicate arg/3 is used to access a specified argument for some Prolog term.
F = male(fred)
As an example we will provide a predicate that uses side-effects, while taking apart an arbitrary Prolog term, to print some information about the term. It uses type/2 as defined previously.
analyse(Term):-The predicate analyse/1 uses both functor/3 to find the arity of a term and then uses arg/3 to work through the various argument of the term one at a time. Note how we dive down into the substructure of a term before finishing the description of each of the arguments in the term. Lists, by the way, are not treated specially by analyse/1.
NewCounter is Counter +1,
write(' is of type '),