[m-dev.] for review: destructive changes to string.m

Fergus Henderson fjh at cs.mu.OZ.AU
Sun Nov 12 00:42:21 AEDT 2000


On 11-Nov-2000, schachte at cs.mu.OZ.AU <schachte at cs.mu.OZ.AU> wrote:
> Perhaps it would be better to make the field access syntax work for
> this?  Ie, define the right functions so that you can write something
> like
> 
> 	String ^ char(3)
> 
> to access the third (or fourth?) character of String and
> 
> 	String ^ char(3) := 'a'
> 
> to replace that character with 'a'.  This makes the duality between
> access and set clearer.

Not a bad idea, but there's one substantial drawback... it would
require a non-trivial extension to Mercury syntax.

> I forget the syntax/conventions for doing
> this and am too lazy to look it up, but I think you just have to
> define a 
> 
>        char(int,string) = char
> 
> function and a 
> 
> 	'set char'(int,string,char) = string 
> 
> function, or something like that.

Unfortunately that won't work.  We don't support "indexed fields"
like that.  We only support ordinary named fields.  The field name
can't include any arguments.  So 

	String ^ char := 'a'

would be OK, but

	String ^ char(3) := 'a'

won't work.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list