[mercury-users] Prolog DCGs Pattern Matching in Mercury
Goncalo Jorge Coelho e Silva
l10454 at alunos.uevora.pt
Mon Apr 28 08:49:05 AEST 2003
Hi again,
I'd like to thank the replies to my previous
questions and bad coding. ;)
I've been trying to explore how to use DCGs
in Mercury, for the same purpose as they are
used in Prolog's pattern matching.
Prolog example:
--------------
gce(name(N)) --> {nl, write(' matched "name(_something_)" '), nl},
or
gce(X) --> {X=[name(N)]},
{nl, write(' matched "name(_something_)" '), nl},
For that purpose, I made a quick test in
Mercury:
-------
:- module inter.
:- interface.
:- import_module io.
:- pred main(io__state, io__state).
:- mode main(di, uo) is det.
%:- mode main(di, uo) is semidet.
:- pred seee(string, io__state, io__state).
:- mode seee(in, di, uo)is semidet.
:- implementation.
:- import_module string.
%main -->
main(IO0,IO):-
%seee(=(faraway)),
%seee(faraway),
seee("faraway", IO0, IO1),
%io__write_string("It's harder to see it.").
io__write_string("It's harder to see it.", IO1, IO).
seee("faraway") --> io__write_string("Never ending!").
%seee(faraway) --> io__write_string("Never ending!").
%seee(VAR) --> {VAR="faraway"}, io__write_string("Never ending!").
In this test example, I was trying to catch
an occurence of the string "faraway" and
print the sentence "Never ending!".
(I've taken the suggestion of leaving DGC's notation in favour
of explicit state_of_the_world argument passing...)
Which led me to the following errors:
Errors:
------
inter.m:006: In `main(di, uo)':
inter.m:006: error: determinism declaration not satisfied.
inter.m:006: Declared `det', inferred `semidet'.
inter.m:020: call to `seee(in, di, uo)' can fail.
make: *** [run] Error 1
If I was to comment the 'det' mode, in favour
of the semidet:
%:- mode main(di, uo) is det.
:- mode main(di, uo) is semidet.
%:- mode main(di, uo) is cc_multi.
I'd get:
inter.m:007: Error: main/2 must be `det' or `cc_multi'.
make: *** [run] Error 1
What am I doing wrong, what can I do to
use Prolog DGCs lookalike effect in Mercury?
Thanks.
Cheers,
Goncalo
--------------------------------------------------------------------------
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