[mercury-users] About unification and AI

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Apr 26 05:25:00 AEST 2004

On 24-Apr-2004, Maurizio Colucci <seguso.forever at tin.it> wrote:
> On Friday 23 April 2004 14:25, Maurizio Colucci wrote:
> > > % rule/2
> > > % rule( If, Then).
> > > rule([[A, use, B],   [B, isBoomerang]], % Preconditions
> > >      [[A, throw, B]]).  % Consequences
> >
> > Another thing: the first problem is that I don't know how to define the
> > type for rule/2.
> I found the term type in the mercury library, but I am not sure how to write 
> the term [A, use, B],

The simplest way would probably be to put the rule definitions in a
separate file, and then use term_io__read_term to read them in.
See samples/interpeter.m for an example.
(If you don't want to use a separate file, another alternative would
be to use a string literal, and then use parser__read_termk_from_string.)

If you want to write it out explicitly, it would look like this:

	cons(variable("A"), cons(mkatom("use"), cons(variable("B"),

Here I have made use of a couple of helper functions:

	:- func cons(term, term) = term.
	cons(H,T) = functor(atom("[|]"), context_init, [H,T]).

	:- func mkatom(string) = term.
	mkatom(A) = functor(atom(A), context_init, []).

> how to unify two terms, and whether the code for 
> demon/0 would continue to work. Since the unification used in the prolog code 
> seems somewhat "global" (see code).

See samples/interpreter.m for an example of one way to do this sort of thing
in Mercury.

Fergus Henderson                    |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe

More information about the users mailing list