[mercury-users] Event handling in mercury

David Overton dmo at cs.mu.OZ.AU
Tue Jul 24 02:02:34 AEST 2001


On Mon, Jul 23, 2001 at 02:53:24PM +0200, Holger Krug wrote:
> > > So one would have 2 different forms of `:=', one only used to
> > > initialize a static mutvar, the other to set it's value in io_state
> > > related operations.
> > 
> > Yes, in my example I was assuming that `:=' would just be used for
> > static initialization, and that if dynamic initialization based on the
> > io__state is required then you'd use `io_store__set_mutvar' to override
> > the static initializer.
> 
> `:=/2' is used for initialization.
> Why not to use `:=/4' in DCG-rules as follows:
> 
>         :- interface.
> 	% static variable foo accessible only in IO-related operations
>         :- static foo = int.
> 	
> 	:- import_module io.
> 
> 	:- pred main(io__state, io__state).
> 	:- mode main(di, uo) is cc_multi.
> 
>         :- implementation 
> 	%%% initializer `:=/2' %%%
>         foo := 42.
>  
> 	main -->
> 	%%% update `:=/4' %%%
> 		foo := 43.

Hmmm.  If we're going to use ':=/4', it might be nice to think of
these global variables as "fields" of the io__state and access them
using DCG field access syntax, e.g.

	main -->
		N =^ foo,	% Get the value of foo.
		io__write_int(N),
		io__nl,
		^foo := N + 1.	% Set the value of foo.

That would reduce the amount of new syntax we need to add.



David
-- 
David Overton      Department of Computer Science & Software Engineering
PhD Student        The University of Melbourne, Victoria 3010, Australia
+61 3 8344 9159    http://www.cs.mu.oz.au/~dmo
--------------------------------------------------------------------------
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