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

Peter Schachte schachte at cs.mu.OZ.AU
Fri Jul 6 12:08:25 AEST 2001


On Thu, Jul 05, 2001 at 07:18:55PM +1000, Tyson Dowd wrote:
> On 05-Jul-2001, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:
> > I cringe at the thought
> > of using the spelling of a function name to determine what sort of back end
> > code to generate for it.  It's just too reminiscent of FORTRAN deciding
> > whether a variable is int or float based on its first letter, or BASIC
> > deciding it's a string if it ends with a $.
> 
> This is a red-herring, as the examples you are giving are where a source
> language feature is determined by the spelling of a function name, not a
> backend feature (if you want to argue backend features, we need a new
> email).

I'm talking about whether you can use ^ syntax with a function.  If we
accept this new proposal, some functions you can, and some you can't,
depending on the spelling of the function name.  That's ugly.

> However, the current Mercury language already supports code where the
> spelling of a function name affects the source -- setter functions are
> distinguished based on spelling.

True, and I agree this is ugly.

I think rather than having funny naming conventions for such functions, it
would be better to make it explicit and declarative.  If we go with my
suggestion of requiring a setter for every getter, we could use a syntax
like:

	:- type position ---> position(float,float).

	....

	:- property position ^ r = float.

	position(X,Y) ^ r = sqrt(X*X + Y*Y).

	(position(X,Y) ^ r = R) = position(X*Factor,Y*Factor) :-
		Factor = R / sqrt(X*X + Y*Y).

This seems much cleaner and more intititive to me than incorporating funny
naming conventions into the Mercury language standard.

If we do that, then we can choose to allow the property name to be used as
an ordinary function if we like.  Ie, Mercury can allow

	Radius = r(Pos)

if we like.  More importantly, it can allow

	map(r, Positions, Radii)

instead of requiring 

	map('= r', Positions, Radii)

Ie, every property is a function, but not every function is a property, and
only properties can use ^ syntax.

-- 
Peter Schachte <schachte at cs.mu.OZ.AU>  The secret of being miserable is to
http://www.cs.mu.oz.au/~schachte/      have the leisure to bother about
Phone:  +61 3 8344 9166                whether you are happy or not. The
Fax:    +61 3 9348 1184                cure is occupation. -- George Bernard
--------------------------------------------------------------------------
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