[fpc-pascal] Record operator for assignment

Sven Barth pascaldragon at googlemail.com
Fri Apr 28 08:06:43 CEST 2017

On 28.04.2017 08:01, Ryan Joseph wrote:
>> On Apr 28, 2017, at 12:43 PM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>> It would introduce an ambiguity as "(x" could also complete to other expressions (e.g. "(x + y) * 2" or even merely "(x)"). Especially older Pascal compilers were geared towards the simplicity of the language and thus they didn't add it. For FPC it simply never came up.
> I never thought about it either until I saw some c++ code doing it. Despite having overlooked it, it’s basically a built in record constructor that’s been in the language since forever. First it was making functions that paired with records and now it’s constructors and "advanced record syntax" when the more obvious and simpler solution was there all along. Maybe I’m crazy though. ;)
> You mean like: 
> rec := (x: (x + y) * 2; y: 0; z: 0);

No, I mean

rec := (x + y) * 2;

The compiler has to differentiate these two.

> Why can’t everything between : and ; just be treated like a normal assignment? “x” is already defined but it’s just a label and not part of the assignment.

And that's another point. The compiler does not know what "x", "y" and
"z" are, cause it doesn't care about the left hand side of the
assignment until *after* the right hand side is parsed (in a var/const
section it knows the type; that's a different situation).
So a different syntax would be needed that would allow the compiler to
know that it's parsing a specific record type.

>> The compiler currently prefers to cast array constructors towards sets, especially if they contain values that could be expressed as a set. That will change once proper support for array constructors is added. Though I don't know whether this would work then ;)
> Huh, that syntax works in constructors, just not in the operator overloading. Anyways I guess I’ll just assume that’s not implemented behavior.

Because in that case it knows that it's a parameter and handles that
differently. A type conversion is a different case.


More information about the fpc-pascal mailing list