[fpc-pascal] Record operator for assignment

noreply at z505.com noreply at z505.com
Mon May 8 05:47:06 CEST 2017


On 2017-04-28 01: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.

You can also look into GoLang for struct ideas, as golang is simpler 
than C++

> rec := (x: (x + y) * 2; y: 0; z: 0);
> 
> 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.
> 

It's always easier said than done, to say "Why can't" and then have to 
write the actual parser code to do it ;-)

I think fpc is based on wirth's simplicity, and even wirth's languages 
probably did not have the ability to setup a record initially with 
default record as another poster said. I do like this feature a lot , 
but can see why a minimalist like worth would avoid it.

It's similar to this feature:

x,y,z := 1, 12, 7

It's neat to be able to assign multiple variables on a single line. But 
necessary? mandatory?
Again, could look into golang for ideas.. may have something like it 
too, without becoming a large C++ mammoth.

In fact that's how golang's error checking works.



More information about the fpc-pascal mailing list