[mercury-users] goal manipulation

Alan Baljeu alanb at cornerstonemold.com
Thu Jun 19 07:26:19 AEST 2003

> I would probably use an ordinary Mercury data type,
> probably a discriminated union type, to represent these goals.
> Then, I'd write a Mercury predicate to evaluate such goals.
> Since the goals are represented as an ordinary Mercury data
> type, analyzing them and reordering them is straight-forward.
> The only vaguely tricky bit is executing them.
> But that's not too hard: can write an interpreter for your goals.
> For example, here's some code from samples/calculator.m
> which defines an "expr" type, and an interpreter which
> evaluates terms of that type:
> :- import_module int.
> :- type expr
> ---> number(int)
> ; plus(expr, expr)
> ;       minus(expr, expr)
> ;       times(expr, expr)
> ;       div(expr, expr).
> :- func evalexpr(expr) = int.
> evalexpr(number(Num)) = Num.
> evalexpr(plus(X,Y)) = evalexpr(X) + evalexpr(Y).
> evalexpr(minus(X,Y)) = evalexpr(X) - evalexpr(Y).
> evalexpr(times(X,Y)) = evalexpr(X) * evalexpr(Y).
> evalexpr(div(X,Y)) = evalexpr(X) // evalexpr(Y).
This is all fine for functional expressions, but my concern is with logical predicates and
variables.  I want to evaluate foo(+A,+B,-C, -D) and track the bindings given to C and D.
What I had done in Prolog is create exactly such an interpreter, and built up a list of
bindings for variables in the interpreted language.

The language is basically a subset of Prolog and I'm hoping to find easier means of
managing assignments.


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