[mercury-users] Assert/Retract

Peter Hawkins hawkinsp at cs.stanford.edu
Wed Jan 25 09:15:39 AEDT 2006


Hi...
Daniel Elenius wrote:
> Is it possible to assert/retract statements in Mercury? 
No, it isn't. But that's arguably a _good_ thing. Mercury is a pure 
logic programming language, which means that predicates can't have 
side-effects, which occur when the execution of a predicate changes the 
state of the world beyond its own outputs. Assert and retract are by 
definition side-effecting operations, and as such they are not supported 
by Mercury.

Instead Mercury supports a rich variety of purely declarative data 
structures, which let you achieve the same thing in a much clearer and 
more obvious way. The resulting code usually is much simpler to 
understand and to reason about.

You might do well to read Ralph Becket's tutorial and the Prolog to 
Mercury transition guide at:
http://www.cs.mu.oz.au/research/mercury/information/documentation.html
> Mercury looks like a very good fit for a project I'm doing, but I 
> don't think I can manage without those "meta" facilities. Also, can I 
> create a list of terms (atoms)?
I'm not really a prolog programmer, so this question may not mean what I 
think it means. Mercury has a polymorphic list type list(T), so you can 
create lists of any other Mercury type. In particular, you can define a 
list of a discriminated union type, which looks just like a list of 
terms. Something like this:

:- module foo.
:- interface.
:- import_module io.

:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module int.
:- import_module string.
:- import_module list.

:- type myterms ---> term1(int) ; term2(string) ; term3(int, string).

main(!IO) :-
    A = [term2("hello"), term1(-42), term3(3, "bar")],
    io.print(A, !IO).


Cheers,
Peter
--------------------------------------------------------------------------
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