[fpc-devel] Proposal: Enhanced replacement for assignment operators

Alexander Klenin klenin at gmail.com
Fri Aug 6 19:29:41 CEST 2010

On Sat, Aug 7, 2010 at 02:34, Martin <fpc at mfriebe.de> wrote:
>  On 06/08/2010 16:21, Alexander Klenin wrote:
> It's not about implementation in the fpc parser/compiler, or syntax
> highlighter => you can implement any such thing...
> But it's breaking the fundamentals of pascal, to differentiate between
> symbol and identifiers.

No, this is not fundamentals, this is minor syntactic point.
The fundamentals are things like readability, orthogonality etc.
(randomly chosen example:

> Obviously it acts like a symbol does, so it should be a symbol; but if
> symbol can have chars, then why can't identifiers have $+-...

1) Since div and mod are already symbols, this distinction is already broken.
2) $+- in identifiers are disallowed because they will cause ambiguity.
In fact, some other languages allow and even encourage them in identifiers
(e.g. in Perl 6 and Lisp it is preferred style to separate words
inside the identifier
with minus, not underscore).
3) Identifiers in FPC can start with "&" character, which further blurs
  the distinction you are trying to make.
So, famous "triple else" example can not be translated to Pascal:
if &if = &then then &then := &else else &else := &if;

> If we give up this barrier, then surely the following should be valid to?

So, the answer is that valid symbols are those which can not result in
AFAICS, {div|mod|or|and|xor}= satisfy this criteria.

> ----------
> if there should be a shorthand for "a:=a mod b" => ok => but please make it
> look like pascal.
> Either inc style, or symbol style. maybe use "%=" (and "::=" for div (first ":" =divide))
> I don't say I like those, but "mod=" is just the worst I can imagine.

Let's return to the orthogonality principle for the moment.
It is, IMO, very simple and easily memorable rule:
"a <op>= b" is equivalent to "a := a <op> b".
Instead, we now have "a <op>= b" is equivalent to "a := a <op> b"
if <op> if is addition, subtraction, multiplication or
floating-point (!) division.
I think that adding rule "a <op1>= b" is equivalent to "a := a <op2> b"
where op1 and op2 are different is much worse than
some allowing few more "mixed" tokens into the language.

If you see
a div= b;
operator, you may aesthetically dislike it, but you will
instantly recognize what it does.

Alexander S. Klenin

More information about the fpc-devel mailing list