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

Simon Taylor stayl at cs.mu.OZ.AU
Wed Nov 5 15:03:02 AEDT 2003


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)).
 
> ...the semantics would be:
> 
> update(Data0, Data1) :-
>   add_one_to_int(Data0^bar, TInt),
>   Data1 = Data0^bar:=TInt.
> 
> I do not see any problem in another extra feature, using more than one
> part of the dataterm at the same time:

> How deep in your todo list would this wish sink?

I'm not sure this is a good idea (at least not on its own).

It would be better to have a syntax for updating a field using the
output of a predicate without introducing an extra variable, but it's
difficult to come up with a syntax that isn't horribly ugly.

Simon.
--------------------------------------------------------------------------
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