[mercury-users] Little problem

Ralph Becket rafe at cs.mu.OZ.AU
Thu Apr 22 07:34:46 AEST 2004

```Sergio Rafael Trindade Marques, Wednesday, 21 April 2004:
> Hi,
> I have a little problem:
> How can i say that a read_term is a "call to a predicate" or a
> "definition of a predicade with goals"?
>
> I have the following code:
>
> /(1) :-abcd(X,X,a,c).
>
> (2) dcba(a,X):-
>        acer(x,A,X)
>
>
> /term(varset(var_supply(1), two(var(1), "X", empty, empty), empty),
> functor(atom(":-"), [functor(atom("abcd"), [variable(var(1)),
> variable(var(1)), functor(atom("a"), [], context("t4.txt", 1)),
> functor(atom("c"), [], context("t4.txt", 1))], context("t4.txt", 1))],
> context("t4.txt", 1)))
> term(varset(var_supply(2), three(var(1), "X", var(2), "A", empty, empty,
> empty), empty), functor(atom(":-"), [functor(atom("dcba"),
> [functor(atom("a"), [], context("t4.txt", 4)), variable(var(1))],
> context("t4.txt", 4)), functor(atom("acer"), [functor(atom("x"), [],
> context("t4.txt", 5)), variable(var(2)), variable(var(1))],
> context("t4.txt", 5))], context("t4.txt", 4)))/
>
> Does anyone know how to distinguise (1) from (2)?

if you were wondering) has the following signature

:- mode parser__read_term(out, di, uo) is det.

and the type read_term/1 is defined (in term_io.m) as

:- type read_term(T) ---> eof ; error(string, int) ; term(varset(T), term(T)).

and the type term/1 is defined (in term.m) as

:- type term(T)         --->    term__functor(
const,
list(term(T)),
term__context
)
;       term__variable(var(T)).
:- type const           --->    term__atom(string)
;       term__integer(int)
;       term__string(string)
;       term__float(float).

:- type term__context   --->    term__context(string, int).
% file name, line number.

:- type var(T).

a string and parse it as a Mercury term.  To tell the difference between
(1) and (2) in your example, you need to parse the resulting term/1
value yourself.

In this case the term for (1) matches

functor(atom(":-"), [ABCDTerm], Context)

and the term for (2) matches

functor(atom(":-"), [DCBATerm, ACERTerm], Context)

-- Ralph
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au