[m-dev.] @ syntax (was: Freeze the compiler)
Fergus Henderson
fjh at cs.mu.OZ.AU
Tue Nov 14 13:52:19 AEDT 2000
On 13-Nov-2000, Ralph Becket <rbeck at microsoft.com> wrote:
> >From Fergus Henderson on 12/11/2000 16:40:29
> > On 10-Nov-2000, Ralph Becket <rbeck at microsoft.com> wrote:
> > >
> > > I presume the freeze would also apply to the library? If so, I'd
> > > like to check in the `@'-as-synonym-for-`lookup' change I've made
> > > to my local copy (my interpretation of the debate was that many
> > > people agreed it would be a good thing and those who didn't diverged
> > > in several different directions).
> > >
> > > Yea/nay?
> >
> > I'd like to take a conservative approach and leave this one as is for now.
> >
> > Peter Schachte's suggestion of making whatever syntax we use work
> > with `:=' is a good one, i.e. providing support for what C#
> > and (I think) Delphi call "indexers" in addition to our current
> > support for "properties". But I think that would require a syntax
> > like `map^elem(Key)', which would be incompatible with the use of `@'.
>
> Fair enough, although it seems orthogonal to me. As I understand it,
> the idea is to generalise from `X ^ Y' --> `Y(X)' to also handle
> curried stuff, `X ^ Y(A, B, C)' --> `Y(A, B, C, X)' (+ `:=' case).
>
> 1. How would such syntax be declared?
>
> 2. Would it also work for, e.g., typeclass methods (that is, is this
> just a syntactic transformation.)
It would just be a syntactic transformation.
You would just declare e.g.
:- func elem(map(K, V), K) = V.
:- func 'elem :='(map(K, V), K, V) = map(K, V).
and then you can use
map^elem(Key)
or
map^elem(Key) := Value
and they will call the respective functions.
Yes, it would work for type class methods.
> Either way, lookup op's are very common and adopting the concise `@'
> convention doesn't seem like too much hassle.
> On the page, we get the following:
>
> lookup(Map, Key)
> Map ^ lookup(Key)
> Map @ Key
The `@' convention has the drawback that you don't get the
syntactic correspondance between setter and getter functions.
You couldn't write
Map @ Key := Value
(without additional syntax extensions or undesirable overloading).
It seems a bit excessive to have _four_ different syntaxes for
accessing array elements:
1. lookup(Map, Key)
2. Map `lookup` Key
3. Map ^ elem(Key) and Map ^ elem(Key) := Value
4. Map @ Key
I supposed we could combine 3 & 4 as
Map ^ @(Key) and Map ^ @(Key) := Value
or (making `@' a prefix operator)
Map ^ @ Key and Map ^ @ Key := Value
However this would have the drawback that the space between the `^'
and the `@' would not be optional, which could well be confusing for
beginners.
--
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