/*
myground(Term) :- Term is a ground term.
*/
myground(Term) :-
nonvar(Term),
constant(Term).
myground(Term) :-
nonvar(Term),
compound(Term),
functor(Term,F,N),
myground(N,Term).
myground(N,Term) :-
N > 0,
arg(N,Term,Arg),
myground(Arg),
N1 is N-1,
myground(N1,Term).
myground(0,Term).
% Program 10.4 Testing if a term is ground