Subterm

Description

Finding subterms of a term

Source: The Art of Prolog

Download

Program source code: subterm.pl

Listing

/*
   subterm(Sub,Term) :- Sub is a subterm of the ground term Term.
*/
     subterm(Term,Term).
     subterm(Sub,Term) :- 
        compound(Term), functor(Term,F,N), subterm(N,Sub,Term).
 
     subterm(N,Sub,Term) :- 
        N > 1, N1 is N-1, subterm(N1,Sub,Term).
     subterm(N,Sub,Term) :- 
        arg(N,Term,Arg), subterm(Sub,Arg).
 
%  Program 9.2    Finding subterms of a term

Comments

pl/prolog/pllib/subterm.txt · ostatnio zmienione: 2019/06/27 15:50 (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