Różnice

Różnice między wybraną wersją a wersją aktualną.

Odnośnik do tego porównania

pl:prolog:pllib:terms_variety [2019/06/27 15:50] (aktualna)
Linia 1: Linia 1:
 +====== Terms variety ======
 +{{tag>​operators numbers}}
 +===== Description =====
 +Testing if terms are variants
 +
 +**Source**: ​ The Art of Prolog
 +===== Download =====
 +Program source code: {{terms_variety.pl}}
 +===== Listing =====
 +<code prolog>
 +/*
 +   ​variants(Term1,​Term2) :- Term1 and Term2 are variants.
 +*/
 +
 +:- op(900, fx, [not]).
 +
 +   ​variants(Term1,​Term2) :-
 + verify((numbervars(Term1,​0,​N), ​
 + numbervars(Term2,​0,​N),​
 + Term1=Term2)).
 +
 + verify(Goal) :- not (not Goal).
 +
 + numbervars('​$VAR'​(N),​N,​N1) :-
 + N1 is N+1.
 + numbervars(Term,​N1,​N2) :-
 + nonvar(Term),​ functor(Term,​Name,​N),​
 + numbervars(0,​N,​Term,​N1,​N2).
 +
 + numbervars(N,​N,​Term,​N1,​N1).
 + numbervars(I,​N,​Term,​N1,​N3) :-
 + I < N,
 + I1 is I+1,
 + arg(I1,​Term,​Arg),​
 + numbervars(Arg,​N1,​N2),​
 + numbervars(I1,​N,​Term,​N2,​N3).
 +
 +%  Program 11.7  Testing if terms are variants
 +</​code>​
 +===== Comments =====
  
pl/prolog/pllib/terms_variety.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