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

Alexander Klenin klenin at gmail.com
Sat Aug 7 07:47:28 CEST 2010

On Sat, Aug 7, 2010 at 08:56, "Vinzent Höfler"
<JeLlyFish.software at gmx.net> wrote:
> Alexander Klenin <klenin at gmail.com>:
>> Exactly, and so we are back to square one -- you accumulate integers with
>> "Inc",
>> points with "AddPoint", doubles with "FloatInc", write extraneous
>> four-line wrapper for every type and always forget which of
>> MultVector and VecMultiply is procedure, and which is function.
> Well, if you do it that way... I'd use overloading and use the same name (or, admitted, even the same operator) for the same concept.

IIRC, overloading is not available in Delphi 7 either.

> If you'd used just Add, Scale, and Multiply the code may be slightly more readable. :P

Argee, but only slightly.

>> Here is the same code after upgrading:
>>   mu :=
>>       InverseCoordMatrix(w * dst.A + AWeight * ASource.A) *
>>       (w * dst.A * dst.Mu + AWeight * ASource.A * ASource.Mu);
>>   a := w * dst.A + AWeight * ASource.A / (w + AWeight);
>> [Both versions slightly simplified to avoid overbloating the message].
>> Believe me, expressive power of operators is severely underestimated
>> by those who did not try to do calculations without them ;-)
> Believe me, after all those years I still know what I am talking about. :) And why didn't you overload "-" for "Inverse"?

Because inverse is not negation, and Delphi does not have ** operator for power.

> Surely, I didn't want to negate the fact that operator overloading can solve some problems, but why the hell does it always have to be the "add/sub/div/mul/mod/$whatever and assign" operator? Oh, this one doesn't exist at all, because it's two actions in one? My bad. Why didn't I think of the "multiply and add" operator, which was very common in DSPs once and meanwhile made it to mainstream CPUs? "*+:=" would be a proper symbol for it, wouldn't it?

No, that would be for "multiply, add and assign". Besides, is not it a ternary?

> So, I still do not find an occasion of a "reverse polish assignment" in this example. I even don't see what part of this example it would make more readable. Well, maybe it's just my eyes...

Why "reverse polish"? Assign operators are infix (and do not form
expressions in Pascal).
And true, this is not an example for using assignment operators, just
operators in general.
It is the same principle, though -- Lisp is not a readable way to
spell calculations,
whatever its other advantages ;-)

Alexander S. Klenin

More information about the fpc-devel mailing list