Re: Definable operators

Ephram Cohen <ephram@ear.Psych.Berkeley.EDU>
6 May 1997 22:27:07 -0400

          From comp.compilers

Related articles
[25 earlier articles]
Re: Definable operators (David Rush) (1997-04-20)
Re: Definable operators (Craig Burley) (1997-04-22)
Re: Definable operators (Craig Burley) (1997-04-30)
Re: Definable operators (1997-04-30)
Re: Definable operators (1997-05-04)
Re: Definable operators (Dave Lloyd) (1997-05-04)
Re: Definable operators ephram@ear.Psych.Berkeley.EDU (Ephram Cohen) (1997-05-06)
Re: Definable operators (Francois-Rene Rideau) (1997-05-08)
Re: Definable operators monnier+/news/comp/ (Stefan Monnier) (1997-05-08)
Re: Definable operators (Craig Burley) (1997-05-08)
Re: Definable operators (Craig Burley) (1997-05-08)
Re: Definable operators (Dave Lloyd) (1997-05-12)
Re: Definable operators (1997-05-12)
[7 later articles]
| List of all articles for this month |

From: Ephram Cohen <ephram@ear.Psych.Berkeley.EDU>
Newsgroups: comp.compilers
Date: 6 May 1997 22:27:07 -0400
Organization: Sirius Connections
References: 97-03-037 97-03-076 97-03-112 97-03-115 97-03-141 97-03-162 97-03-184 97-04-027 97-04-095 97-04-113 97-04-130 97-04-164
Keywords: syntax, design

After reading this thread with interest I kept flipflopping as to
whether I liked being able to overload (re-define) the + operator.
Just for the record I see the evils of this, however, I like being
able to do it for cases like complex, or, matrices. I will not enter
into a debate about this, that is not the reason I said it. I just
wanted to be clear on where I stand.

That out of the way. What about including the other punctuation
characters that are not used in a given language as available for
definition. Technical issues aside (I know this can be ugly) I think
that this scheme has some merit. A heirarchy can be defined for
precedence of operator that stays with the language.

+ -
* /
% ^
` (matrix inversion?)
~ $ (low order ala +-)

The parser could be set for associativity and precedence and allow
meaning devoid context (` is not used that I know of except in shell
scripts) thereby flagging to the reader of code that this is a
function call; go look at the code to see what it does.

It seems to me that the benifit of syntactic sugar in terms of
readability of code is immense. I would much rather define complex
and some operators over the complex type and just be able to write
expressions with it than have to string together some long series of
statements that end up reading like assembly language.

complex a,b,c,d;
a = complexadd(b,c);
d = complexmult(a,c);
d = (b+c)*c;
or even
d = (b~c)>;

I know that the complex type is a poor example because it is math and
plus pretty well means plus. However, I like being able to cat two
(or more) strings together with plus rather than a series of function
calls with temporary results.

Well, I know this thread has died out a little, but, I would like to
know what people thought about the idea of using the non-used
punctuation as definable operators. I admit the closer I look the
less unused punctuation there is, but, nontheless...

Ephram Cohen
Psychoacoustics Lab
UC Berkeley
[Previous messages agreed that using + and * for operations recognizable
as addition and multiplication is a fine idea. -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.