Facilities of Mercury

Serap Yilmaz syilmaz at cs.bilkent.edu.tr
Wed Mar 5 21:43:39 AEDT 1997


Dear Mr. Henderson,

> Serap Yilmaz, you wrote:
> >
   Regarding 3, I actually use nonvar/1 and functor/3 in order to compare
> > two terms in terms of their functor and arities. The corresponding
> > Prolog program that I would write is:
> >
> > comparable(T1,T2) :-
> > 	nonvar(T1),
> >         nonvar(T2),
> > 	functor(T1, F, N),
> >         functor(T2, F, N).
>
> > Another question: how can I test if two neither non-ground nor ground
> > terms are equal i.e. terms like g(A,b,R). This is == in Prolog, and
> > what is corresponding operator for ~= in Mercury?
>
> I'm still missing the big picture here -- what is the real problem
> that you are trying to solve?  What do these non-ground terms represent?
> Why do you need to compare them?

My aim is to find the "most specific generalization" of two terms. I
need this, because I am working on an automatic programming system that induces
recursive logic programs. At one step of this system, I need to find that
most spec. generalization of two terms. For instance, msg of the
terms "t(a,B,d(E))" and "t(a,C,d(F))" is "t(a,X,d(Y))". Another example
is for terms "s(a,b,C)" and "s(b,b,f(d))" their msg is "s(X,b,Z)". So if
the functors and the arities of two terms are the same (if
they are comparable then their msg's are computed).

> Often the right way to solve these sorts of problems in Mercury is
> to use a ground representation; see the standard library module `term'
> for an example. However, without knowing more about your application,
> it's hard to give definitive advice.

I thought on using ground representation, however as far as I can see it
is not possible to use in finding the msgs of two terms. I need to
distinguish between variables and constants.

> (Note that using `term' may also avoid the need for `arg' and `functor'.)
>
> Cheers,
> 	Fergus.
>
> --
> Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
> WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
> PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.
>
Best,
Serap Yilmaz



More information about the users mailing list