[m-rev.] field syntax (was: smart recompilation)

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Jul 3 17:20:18 AEST 2001


On 03-Jul-2001, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> On 03-Jul-2001, Tyson Dowd <trd at cs.mu.OZ.AU> wrote:
> > On 23-Jun-2001, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> > > `Object ^ Field' is just a synonym for `Field(Object)'. I think the
> > > only argument was that the `Object ^ Field' syntax was a bit redundant.
> > 
> > Can I add the note that the redundancy also makes it very explicit.
> > 
> > Field(Object) is pretty difficult to tell apart from NotField(Object),
> > but Object ^ Field is impossible to confuse with NotField(Object).
> > 
> > That is a round-about way of saying -- it would be nice to get rid of
> > Field(Object) and just use Object ^ Field.  This way you always know
> > whether a function is intended to be used as a field accessor or not.
> 
> I don't understand how you're going to "get rid of" `Field(Object)'.

My proposal is to name the field functions for a field 'foo' as

	'foo ='
and	'foo :='

rather than as

	'foo'
and	'foo :='

So then you could write

	Object ^ foo

or
	'foo ='(Object)

but not

	'foo'(Object)

> The lack of distinction between fields and functions was deliberate.
> It's useful to be able to redefine a field as a pair of functions
> without changing any of the code that uses the field.

The proposal above preserves that property.  The advantage is that
it makes it obvious when a function is intended to be used as a field
accessor, and when a field accessor is used as a function.  It avoids
accidental overloading between field names and functions or constructors
that happen to have the same name.  If you want to refer to the field
accessor as a function (e.g. to pass to a higher-order function such as
`list__map'), you can still do so, you just have to use 'foo =' rather
than 'foo'.

P.S.
Alternatively, perhaps they should be named

	'^foo ='
and	'^foo :='.

-- 
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-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list