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

schachte at cs.mu.OZ.AU schachte at cs.mu.OZ.AU
Mon Nov 13 01:16:14 AEDT 2000


On 12 Nov, Fergus Henderson wrote:
> 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.

Bummer.  The original proposal was that

	X ^ Y

be equivalent to call(Y, X), and

	X ^ Y := Z

be equivalent to call(Setter, X, Z), where Setter is defined as if
by (using Prolog builtins; it would be a bit different in Mercury)

	Y =.. [Fun0 | Rest]
	atom_chars(Fun0, Gettername),
	append("set ", Gettername, Settername),
	atom_chars(Fun, Settername),
	Setter =.. [Fun |  Rest]

(so of course the principle functor of Y would need to be known at
compile time).  This is a pretty obvious generalization of what's
implemented, so I don't see how it's a non-trivial extension to Mercury
syntax.  Which is not to say it's a trivial extension to implement....

It would be useful.  There are a million accessor/setter pairs like this
for which it would be good to have a syntax that made clearer the
duality between access and get.  Array elements, substrings, array
slices, map lookup, etc.  The ':=' syntax could be really useful.

-- 
Peter Schachte                     The use of COBOL cripples the mind; its
mailto:schachte at cs.mu.OZ.AU        teaching should, therefore, be regarded
http://www.cs.mu.oz.au/~schachte/  as a criminal offense.
PGP: finger schachte at 128.250.37.3      -- E. W. Dijkstra 

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