[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)
>
> /and the read_term of mercury have made the following:
>
> /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)?
parser__read_term (which is pretty much the same as term_io__read_term,
if you were wondering) has the following signature
:- pred parser__read_term(read_term(T), io__state, io__state).
:- 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).
So read_term/3 has done exactly what you asked it to, namely to read in
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
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