Occurs

Description

Occurs in

Source: The Art of Prolog

Download

Program source code: occurs.pl

Listing

/*
 
   occurs_in(Sub,Term) :- 
 
	Sub is a subterm of the (possibly non-ground term) Term.
 
*/
 
% a:  Using ==
 
 
 
   occurs_in(X,Term) :- subterm(Sub,Term), X == Sub.
 
 
 
% b:  Using freeze    $$$$  freeze is not in Standard Prolog
 
 
 
   occurs_in(X,_) :- freeze(X,Xf), freeze(_,Termf), subterm(Xf,Termf).
 
 
 
/*
 
   subterm(Sub,Term) :- Sub is a subterm of the ground term Term.
 
*/
 
     subterm(Term,Term).
 
     subterm(Sub,Term) :- 
 
        compound(Term), functor(Term,_,N), subterm(N,Sub,Term).
 
 
 
     subterm(N,Sub,Term) :- 
 
        arg(N,Term,Arg), subterm(Sub,Arg).
 
     subterm(N,Sub,Term) :- 
 
        N > 1, N1 is N-1, subterm(N1,Sub,Term).
 
 
 
%  Program 
 
0.7    Occurs in

Comments

pl/prolog/pllib/occurs.txt · ostatnio zmienione: 2017/07/17 08:08 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0