Recent

Author Topic: 3.2 docs don't include new features  (Read 2533 times)

segfault

  • Full Member
  • ***
  • Posts: 107
3.2 docs don't include new features
« on: October 23, 2020, 06:11:11 pm »
It seems the docs haven't been updated for 3.2, at least not the chm files. I was trying to find some examples of using the new insert, delete and concat functions for dynamic arrays, but there is nothing. Unless I'm looking in the wrong place?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11382
  • FPC developer.
Re: 3.2 docs don't include new features
« Reply #1 on: October 23, 2020, 07:28:14 pm »
The CHM files are compiled from the same sources as the other docs.

Afaik the string versions have been updated to have both prototypes.

e.g. for delete, there is

Code: [Select]
procedure Delete(
 
  var S: string;
 
  const Index: Integer;
 
  const Count: Integer
 
);

procedure Delete(
 
  var A: DynArrayType;
 
  const Index: Integer;
 
  const Count: Integer
 
);
 


segfault

  • Full Member
  • ***
  • Posts: 107
Re: 3.2 docs don't include new features
« Reply #2 on: October 24, 2020, 09:47:33 am »
Fair enough, it's just that there's no mention of the additions in 3.2 in the ref. manual in the section on dynamic arrays, just one example of using 'Copy' with them.
I was getting an error using concat when adding a single element to an array, then I realized the element should be surrounded by [] to denote an array, like you do with sets. It seems there are 3 ways (at least) of doing this :

Code: Pascal  [Select][+][-]
  1. {concatenate element to array}
  2.  
  3. const
  4.   MAX = 5;
  5. type
  6.   intArray = array of integer;
  7. var
  8.   A : intArray;
  9.   i : integer;
  10.  
  11. procedure output;
  12. begin
  13.   for i := low(A) to high(A) do
  14.     write(A[i]:3);
  15. end;
  16.  
  17. begin
  18.   {method 1 - setlength}
  19.   for i := 1 to MAX do
  20.     begin
  21.     setlength(A, length(A) + 1);
  22.     A[high(A)] := random(10);
  23.     end;
  24.   output;
  25.  
  26.   A := default(intArray);
  27.   writeln;
  28.  
  29.   {method 2 - concat}
  30.   for i := 1 to MAX do
  31.     A := concat(A, [random(10)]);
  32.   output;
  33.  
  34.   A := default(intArray);
  35.   writeln;
  36.  
  37.   {method 3 - insert}
  38.   for i := 1 to MAX do
  39.     insert(random(10), A, length(A));
  40.   output;
  41.   writeln;
  42. end.
  43.  


Not sure whether they're equally efficient though.
« Last Edit: October 24, 2020, 12:04:08 pm by segfault »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11382
  • FPC developer.
Re: 3.2 docs don't include new features
« Reply #3 on: October 24, 2020, 12:13:59 pm »
Yes, that is normal, it operates like all open array, see the corresponding item in the docs.

segfault

  • Full Member
  • ***
  • Posts: 107
Re: 3.2 docs don't include new features
« Reply #4 on: October 25, 2020, 02:13:38 pm »
But why does 'insert' not require the element to be enclosed in square brackets but 'concat' does? It seems a little inconsistent.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11382
  • FPC developer.
Re: 3.2 docs don't include new features
« Reply #5 on: October 25, 2020, 02:18:03 pm »
Because you don't insert multiple separate string at the same point ? Then you typically insert one big string

While it is more optimal to do

Code: Pascal  [Select][+][-]
  1. s:=s+s1+s3+'4343'+s4;

using a routine like concat that only copies all items once.

 

TinyPortal © 2005-2018