Recent

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

Duthomhas

  • Newbie
  • Posts: 3
Dynamic Array Extensions, FPC 3.0.4
« on: February 21, 2019, 09:10:06 am »
Hey, just downloaded the latest and greatest from Lazarus.

Tried to compile a simple program using the Dynamic Array Extensions, RE http://free-pascal-general.1045716.n5.nabble.com/Feature-announcement-Dynamic-array-extensions-td5731410.html.

However, I cannot get any of it to compile.

Alas, it has been a long time since I have played with (my favorite language), and my Google-fu is a little weak... I cannot find any complaints about this or what to do to fix it.

What do I do to make FPC allow the Dynamic Array Extensions?

Thank you for your time.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 9090
  • FPC developer.
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #1 on: February 21, 2019, 09:24:57 am »
Those are later Delphi extensions, barely two years old

FPC does support the first example, but only in development versions, not in the 3.0.x release branch (which stopped getting new language features in 2014-2015)

Duthomhas

  • Newbie
  • Posts: 3
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #2 on: February 21, 2019, 06:16:57 pm »
<confused-frowny-face>

Okay, that’s the version I got from the Lazarus download page two weeks ago (Feb 2019). Command-line reports version as:
Quote
Free Pascal Compiler version 3.0.4 [2019/02/03] for i386

Two years is a fairly long time in computers... XE 7 supports them (finally), and I was excited to see the post (dated last year, 2018) stating that FPC had them. And the post lists examples.


So...
Development/release cycle seems a bit off for a two-year gap.



I’ll live, I guess... :-J

Thank you for the swift and kindly update.

avra

  • Hero Member
  • *****
  • Posts: 2112
    • Additional info
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #3 on: February 22, 2019, 08:32:16 am »
Two years is a fairly long time in computers... XE 7 supports them (finally), and I was excited to see the post (dated last year, 2018) stating that FPC had them. And the post lists examples.
Nothing stops you from using FPC 3.2 fixes or trunk versions instead of the official 3.0.4. The easiest way to do it is with FpcUpDeluxe:
http://wiki.lazarus.freepascal.org/fpcupdeluxe
It can coexist with your current Lazarus installation(s).
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

segfault

  • Full Member
  • ***
  • Posts: 107
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #4 on: February 22, 2019, 10:08:11 am »
I didn't know about these extensions, they are very cool and will make manipulating arrays so much easier. Here's a short example of using "Insert" and initializing a variable (on FPC 3.3.1) -

Code: Pascal  [Select][+][-]
  1. var
  2.   A : array of integer = (1,2,3,4,5);
  3.   i : integer;
  4. begin
  5.   insert(8, A, 2);   // insert 8 at index 2
  6.   for i := low(A) to high(A) do
  7.     writeln(A[i])
  8. end.

1
2
8
3
4
5
« Last Edit: February 22, 2019, 10:18:27 am by segfault »

Duthomhas

  • Newbie
  • Posts: 3
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #5 on: February 22, 2019, 11:16:22 am »
@avra
I did not know FpcUpDeluxe existed. Thank you! You rock!

segfault

  • Full Member
  • ***
  • Posts: 107
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #6 on: February 22, 2019, 11:52:59 am »
Trying to compile this I get "operator is not overloaded" :

Code: Pascal  [Select][+][-]
  1. uses crt;
  2. var
  3.   A : array of integer = (1,2,3);
  4.   i : integer;
  5. begin
  6.   clrscr;
  7.   A += [4];
  8.   for i in A do
  9.     writeln(i);
  10. end.
  11.  

And the following compiles but generates a run time error :

Code: Pascal  [Select][+][-]
  1. uses crt;
  2. var
  3.   A : array of integer = (1,2,3);
  4.   i : integer;
  5. begin
  6.   clrscr;
  7.   A := concat(A, [4]);
  8.   for i in A do
  9.     writeln(i);
  10. end.
  11.  

Thaddy

  • Hero Member
  • *****
  • Posts: 10707
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #7 on: February 22, 2019, 12:47:50 pm »
+= 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.
« Last Edit: February 22, 2019, 12:50:42 pm by Thaddy »

segfault

  • Full Member
  • ***
  • Posts: 107
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #8 on: February 22, 2019, 12:59:46 pm »
Thanks Thaddy. I tried modifying the code for the second example as you suggested but I'm still getting runtime error 216.

Thaddy

  • Hero Member
  • *****
  • Posts: 10707
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #9 on: February 22, 2019, 01:30:34 pm »
That's strange.
I used this to test:
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}
  2. var
  3.   A : array of integer = (1,2,3);
  4.   B : array of integer =(4);
  5.   i : integer;
  6. begin
  7.   A := concat(A, B);
  8.   for i in A do
  9.     writeln(i);
  10.     readln;
  11. end.
And:
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}
  2. var
  3.   A : array of integer = (1,2,3);
  4.   i : integer;
  5. begin
  6.   A := concat(A, [4]);
  7.   for i in A do
  8.     writeln(i);
  9.     readln;
  10. end.

Both work on arm and win64.
Did you forget a $mode?
Did you use a recent trunk?
« Last Edit: February 22, 2019, 01:52:23 pm by Thaddy »

segfault

  • Full Member
  • ***
  • Posts: 107
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #10 on: February 22, 2019, 01:59:11 pm »
No luck I'm afraid. I'm using linux 64 with the text mode ide. Here are screenshots (not sure how to insert an image here) -

https://i.postimg.cc/Kvk2KQK0/compile.png

https://i.postimg.cc/qBQstxf6/run.png


Thaddy

  • Hero Member
  • *****
  • Posts: 10707
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #11 on: February 22, 2019, 02:24:30 pm »
No luck I'm afraid. I'm using linux 64 with the text mode ide. Here are screenshots (not sure how to insert an image here) -

https://i.postimg.cc/Kvk2KQK0/compile.png

https://i.postimg.cc/qBQstxf6/run.png
Better simply attach the pictures here. Most of us do not like links to third party sites.
You did not answer my questions,
3.0.4 will not work, you need at least 3.2.0 or trunk 3.3.1.

You are using a very old version of trunk. Don't do that! See screenshot
« Last Edit: February 22, 2019, 02:31:29 pm by Thaddy »

Cyrax

  • Hero Member
  • *****
  • Posts: 839
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #12 on: February 22, 2019, 02:26:40 pm »
No luck I'm afraid. I'm using linux 64 with the text mode ide. Here are screenshots (not sure how to insert an image here) -

https://i.postimg.cc/Kvk2KQK0/compile.png

https://i.postimg.cc/qBQstxf6/run.png

Quote
Free Pascal IDE Version 1.0.12 [2019/02/18]
Compiler Version 3.3.1
GDB Version GNU gdb (GDB) 8.2.1

Quote
Free Pascal Compiler version 3.3.1-r41365 [2019/02/18] for x86_64
Copyright (c) 1993-2018 by Florian Klaempfl and others

It works for me. Your trunk is too old. Please update.

Too bad that textmode IDE doesn't show the revision number.

segfault

  • Full Member
  • ***
  • Posts: 107
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #13 on: February 22, 2019, 02:34:18 pm »
@ Thaddy, I mentioned I'm using 3.3.1 earlier in the thread, but maybe you missed it?

@ Cyrax,

Quote
It works for me. Your trunk is too old. Please update.
Too bad that textmode IDE doesn't show the revision number.

How do you know the trunk is too old if you can't see the revision number? Anyway I'll try installing the latest...

Cyrax

  • Hero Member
  • *****
  • Posts: 839
Re: Dynamic Array Extensions, FPC 3.0.4
« Reply #14 on: February 22, 2019, 02:39:00 pm »
I can deduct that by seeing the build date of the textmode IDE. Yours is Free Pascal IDE Version 1.0.12 [2018/09/23].

And the textmode IDE contains the compiler itself.

 

TinyPortal © 2005-2018