Recent

Author Topic: Dynamic Array Extensions, FPC 3.0.4  (Read 7044 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #15 on: February 22, 2019, 02:43:25 pm »
Indeed. That "trunk" is almost 6 months old. Don't do that with trunk. Keep it up-to-date at least once a week.... I do it even daily depending on what has changed in the development branch. Using trunk in any other way is a complete waste of time. For you and for us too.
« Last Edit: February 22, 2019, 02:51:17 pm by Thaddy »
Specialize a type, not a var.

segfault

  • Full Member
  • ***
  • Posts: 107
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #16 on: February 22, 2019, 04:01:27 pm »
Well actually I only installed trunk because the debugger wouldn't work in 3.04. It did in trunk though. Will the next stable release be 3.2 or a lower version?

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #17 on: February 22, 2019, 04:41:52 pm »
It will be 3.2, as announced
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #18 on: February 22, 2019, 05:21:37 pm »
Well actually I only installed trunk because the debugger wouldn't work in 3.04. It did in trunk though. Will the next stable release be 3.2 or a lower version?
If you installed trunk you are obviously able to build it... So write a script for it...
Trunk means running updates that often change by seconds. It needs to be reasonably up-to-date. Don't use trunk if you are not prepared to do that. Trunk is subject to change (e.g. new features can be withdrawn too, it is a development version, anything can happen)
The latest 3.2.0 RC is a release candidate and will have a stable feature set and is usually stable.

Note the feature we are talking about was introduced in trunk 3.1.1. for release 3.2.0 and any improvements have been back-ported from 3.3.1.
The latest release candidate contains the features as per my example code.

I would advise to install the latest 3.2.0 RC instead of trunk, I think you do not yet fully understand trunk its limitations....That'll come with time and patience.
Freepascal's release cycle is conservative and usually takes between 1-2 years. It won't take that long for an RC to reach gold, usually...

Just in case... the only official trunk needs to be build from source.... You can't"ïnstall" it.
In commercial software trunk is hidden from view, even to beta testers.
« Last Edit: February 22, 2019, 05:48:16 pm by Thaddy »
Specialize a type, not a var.

segfault

  • Full Member
  • ***
  • Posts: 107
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #19 on: February 23, 2019, 01:15:25 pm »
I think you do not yet fully understand trunk its limitations....That'll come with time and patience.

You're right.

Anyway I downloaded fpcupdeluxe and used it to build and install 3.2 beta. Everything works fine including the IDE debugger and both code examples using the new features run without error.  :)

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #20 on: February 25, 2019, 09:38:52 am »
+= syntax is not supported for dynamic arrays. This is also in the discussion on the mailing list rregarding the feature announcement.
 second example needs something like this:
Code: Pascal  [Select][+][-]
  1. uses crt;
  2. var
  3.   A : array of integer = (1,2,3);
  4.   B : array of integer =(4);
  5.   i : integer;
  6. begin
  7.   clrscr;
  8.   A := concat(A, B);
  9.   for i in A do
  10.     writeln(i);
  11. end.

C-Operators are supported as is the ordinary "+":
Code: Pascal  [Select][+][-]
  1. // these two are important
  2. {$COperators On}
  3. {$modeswitch arrayoperators}
  4.  
  5. var
  6.   A: array of Integer = (1, 2, 3);
  7.   B: array of Integer = (4);
  8.   i: Integer;
  9. begin
  10.   A += B;
  11.   // these work as well
  12.   //A += [4];
  13.   //A := A + B;
  14.   //A := A + [4];
  15.   for i in A do
  16.     Writeln(i);
  17. end.  
  18.  

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #21 on: February 25, 2019, 10:29:59 am »
I must have missed that. So the comments in the mailing list were not correct?
Anyway, good job and nice that it works.
Specialize a type, not a var.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #22 on: February 26, 2019, 09:00:48 am »
Which comments do you mean? I know that there had been one bug where it didn't work correctly, so that might be it...

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #23 on: February 26, 2019, 10:30:55 am »
I see. It was the discussion here:http://free-pascal-general.1045716.n5.nabble.com/Feature-announcement-Dynamic-array-extensions-tp5731410p5731443.html about code like this:
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$H+}{$modeswitch arrayoperators+}
  2. {this doesn't work:
  3. operator + (const a:TstringArray;const b:string):TstringArray;
  4. begin
  5.  Result := a +[b];
  6. end;}
  7.  
  8.  
  9. var
  10.   a:array of string = ('Foo');
  11.   s:string;
  12. begin
  13.   // a +='Bar'; // this does not work
  14.   a +=['Bar'];  // this does work indeed
  15.   for s in a do writeln(s);
  16. end.
We can't overload the + operator in this mode, but I can live with that limitation. There is a workaround now, see below.
Because the + as concatenation when array operators are ON.

You have to work around it by first disabling arrayoperators, then  mimic its concatenation functionality with TWO operator overloads.
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$H+}{$modeswitch arrayoperators-}
  2. type
  3.   TStringArray = array of string;
  4.  
  5. operator + (const a,b:TstringArray):TstringArray;
  6. begin
  7.  Result := concat(a,b);
  8. end;
  9.  
  10. operator + (const a:TstringArray;const b:string):TstringArray;
  11. begin
  12.  Result := a +[b];
  13. end;
  14.  
  15. var
  16.   a:array of string = ('Foo');
  17.   s:string;
  18. begin
  19.   a +='Bar';
  20.   a +=['Bar'];
  21.   for s in a do writeln(s);
  22. end.

Am I correct in the assumption this behavior stays as it is above?
Because it seems to me that with hindsight the + operator increasingly looks like it is a hindrance rather than a feature. (I know the modeswitch was introduced for exactly that... fine with me, you can work around it.)


« Last Edit: February 26, 2019, 10:40:25 am by Thaddy »
Specialize a type, not a var.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #24 on: February 27, 2019, 09:10:03 am »
Hmm... Overloading the "+" operator for a dynamic array and its element type should work in my opinion... I'll have to take a look there what's going wrong and whether that's intentional...  %)

 

TinyPortal © 2005-2018