[mercury-users] Pred defns

Peter Schachte pets at students.cs.mu.OZ.AU
Fri Apr 3 18:06:51 AEST 1998


On Fri, 3 Apr 1998, Lee Naish wrote:

> >> 	map__set(map#, Key1, Value1, map#:=),
> >But since map# and := sensible separate things, it would be tempting to
> >leave a space between the # and the :=, leading to nothing good.
> 
> This argument can be leveled at pretty much every operator with more
> than one character.  After a few syntax error messages I think most
> programmers would get the hang of it.

Not really.  The point is that # and := are both valid operators that
naturally appear in succession.  Having a separate, different, #:= operator
seems like asking for trouble.

> >Worse,
> >when you do an assignment, you'd /need/ to leave a space between the # and
> >the := or nothing good would come of it.  I find this more worrying. 
> 
> I'm not sure its good to have a special := construct as well as a
> general update accumulator construct - the general purpose one alone is
> probably better.

Oh, great, then you have to write

	x#:= = x# + 1.

Doesn't look too nice to me.

>  I think a := construct will confuse novices a great
> deal - they will try to use it to assign to variables (perhaps I'm being
> unduely influenced by my current teaching load :-).

Not until the get over trying to use = as an assignment:

	X = X + 1,

Anyway, the'll get an error message if they try to write

	X := X + 1

because the thing to the left of := isn't a thread variable.

The reason I like := and $, and only added $:= as a somewhat grudging
afterthought is that they're sufficient by themselves, and have a very
simple and intuitive semantics.  But $:= is very convenient, so I threw it
in, too.  It's still a pretty simple feature.  Adding the ..., $foo, $, ... 
idiom makes it a bit more complicated and confusing to use than I'd like, a
bit closer to the point where the confusion potential outweighs the value,
but still probably worthwhile.


-Peter Schachte               | IBM is not a necessary evil. IBM is not
mailto:pets at cs.mu.OZ.AU       | necessary.
http://www.cs.mu.oz.au/~pets/ |     -- Ted Nelson 
PGP key available on request  | 




More information about the users mailing list