[mercury-users] Feature request: State Variables + Data Terms

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Nov 7 07:21:51 AEDT 2003


On 05-Nov-2003, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> On 04-Nov-2003, obo at ruk.cuni.cz <obo at ruk.cuni.cz> wrote:
> > I've fallen in love with the state variables syntax. But falling in love
> > with something also means that one often wishes to improve the object...
> > 
> > Would it be hard to allow syntax like this:
> > 
> > :- type my_data ---> data( foo::string, bar::int ).
> > 
> > :- pred update(my_data::in, my_data::out) is det.
> > 
> > update(!Data) :-
> >   add_one_to_int(!Data^bar).
> 
> That would need to be 
>     add_one_to_int(!(Data^bar)).

Uh, why?

I understand that !Data^bar will get parsed as (!Data)^bar.
But that would be OK.  We could still define (!Data)^bar
to expand to the pair of arguments (!.Data)^bar and (!:Data)^bar,
and likewise for cases involving multiple levels of field
access, i.e. !Foo^f1^f2^...^fn.

Do you see any problems with that approach?

While we're at it, I would also like to see a nice syntax for
field updates that don't involve procedure calls, e.g.
by giving the obvious semantics to the syntax

	!Data^bar := ...

That is, this syntax would expand to

	!:Data = (!.Data^bar := ...)

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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