[fpc-devel] Multiple variable initialization - YES

Alexander Grotewohl alex at dcclost.com
Tue Apr 3 04:33:08 CEST 2018


uses SysUtils; // inttostr
procedure blank(a: array of pointer);
var
   i: longint;
begin
   for i:=low(a) to high(a) do
     // string(a[i]^):='';
     string(a[i]^):='silly ~~~~~~~ '+IntToStr(i);
end;
   
var
   s, i, l, {l,} y: string;
begin
   blank([@s, @i, @l, {@l,} @y]);

   writeln(s); writeln(i);
   writeln(l); writeln(l);
   writeln(y); // !!
end.


On 4/2/2018 9:38 AM, Péter Gábor wrote:
> Hi!
>
> I have bean read all of the emails in this topic and now I have to write
> :) :
>
> If multiple type declaration (A, B: Integer) are allowed then this new
> feature would not make difficulty to learn. Especially if we compare it
> to generics, what is already in the language and required/requires to
> learn a new (and non-conventional) syntax.
>
> If the question is (as Jonas said) that "Is it really necessary to allow
> this"? - NOT necessary, we can live without it BUT...
>
> BUT if ask the sub-questions (by Jonas):
> - Does it make things much easier to read? - YES
> - Less error prone to write? - YES
> - Increase productivity a lot? - YES
>
> Sum of answers are absolutely YES!
> The requested language feature is a good idea that can make our favorite
> language better in all manners.
>
> You can see it if you (all) take a look at at the examples (from Ondrej)
> below:
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - - - -
>
> OLD:
>
>    procedure Test(const A: Integer = 0; const B: Integer = 0; const C:
> Integer = 0; const D: Integer = 0);
>
> NEW:
>
>    procedure Test(const A, B, C, D: Integer = 0);
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - - - -
>
> OLD:
>
>    procedure Test;
>    var
>      A, B, C, D, E, F: string;
>    begin
>      A := '';
>      B := '';
>      C := '';
>      D := '';
>      E := '';
>      F := '';
>    end;
>
> NEW:
>
>    procedure Test;
>    var
>      A, B, C, D, E, F: string = '';
>    begin
>    end;
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - - - -
>
> OLD-MIXED:
>
>    procedure Test(const A: Integer = 0; const B: Integer = 0; const C:
> Integer = 0; const D: Integer = 0);
>    var
>      E, F, G, H,,I, J: string;
>    begin
>      E := '';
>      F := '';
>      G := '';
>      H := '';
>      I := '';
>      J := '';
>    end;
>
> NEW-MIXED:
>
>    procedure Test(const A, B, C, D: Integer = 0);
>    var
>      E, F, G, H, I, J: string = '';
>    begin
>    end;
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - - - -
>
> And again, the requested language feature is a good idea that can make
> our favorite language better in all manners.
>
>
>
> 2018-03-24 11:46 keltezéssel, Ondrej Pokorny írta:
>> Is there a reason why multiple variable initialization is forbidden?
>>
>> program Test;
>> var
>>    A: Integer = 0;    // allowed
>>    B, C: Integer = 0; // not allowed
>> begin
>> end.
>>
> Regards
>




More information about the fpc-devel mailing list