Recent

Author Topic: Arbitrary complex data structure?  (Read 1290 times)

giahung1997

  • Full Member
  • ***
  • Posts: 113
Arbitrary complex data structure?
« on: June 07, 2019, 10:25:16 am »
Please close this thread  :(
« Last Edit: June 20, 2019, 02:20:41 pm by giahung1997 »
Hate me? I'm gone. You will never see me again. Fuck the people of this forum! Fuck this Lazarus! Fuck Pascal!

Thaddy

  • Hero Member
  • *****
  • Posts: 9280
Re: Arbitrary complex data structure?
« Reply #1 on: June 07, 2019, 03:09:17 pm »
Dynamic arrays can be ragged arrays. I gave an example on this forum some time ago.
Simplest example:
Code: Pascal  [Select]
  1. {$mode delphi}
  2. var
  3.    a:array of array of integer;
  4. begin
  5.    a:= [[1,2,3,4],[1,2,3]]; // now 4 X 3, rectangular
  6.    a[1] := [4,5]; // change 1 element to 2 instead of three: ragged, no longer rectangular
  7. end.
Needs FPC 3.2.0 or higher.
You can build infinitely complex structures using this technique. Does that help?
« Last Edit: June 07, 2019, 03:20:00 pm by Thaddy »
also related to equus asinus.

Zoran

  • Hero Member
  • *****
  • Posts: 1468
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Arbitrary complex data structure?
« Reply #2 on: June 19, 2019, 07:34:42 pm »
Dynamic arrays can be ragged arrays. I gave an example on this forum some time ago.
Simplest example:
Code: Pascal  [Select]
  1. {$mode delphi}
  2. var
  3.    a:array of array of integer;
  4. begin
  5.    a:= [[1,2,3,4],[1,2,3]]; // now 4 X 3, rectangular
  6.    a[1] := [4,5]; // change 1 element to 2 instead of three: ragged, no longer rectangular
  7. end.
Needs FPC 3.2.0 or higher.
You can build infinitely complex structures using this technique. Does that help?

In this example, I don't understand how is a rectangular in the first place?!


lucamar

  • Hero Member
  • *****
  • Posts: 2130
Re: Arbitrary complex data structure?
« Reply #3 on: June 19, 2019, 08:31:50 pm »
In this example, I don't understand how is a rectangular in the first place?!

The line:

Code: [Select]
a:= [[1,2,3,4],[1,2,3]];
creates an array of 4 rows, 3 columns per row (or viceversa ;)); i.e. a rectangular array, as if it had been declared as:
a: array[0..3, 0..2] of Integer;
« Last Edit: June 19, 2019, 08:34:56 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

Thaddy

  • Hero Member
  • *****
  • Posts: 9280
Re: Arbitrary complex data structure?
« Reply #4 on: June 19, 2019, 08:43:42 pm »


In this example, I don't understand how is a rectangular in the first place?!
Well , that's disappointing  because it shows an arbitrary array that  I understood what OP meant.
also related to equus asinus.

Zoran

  • Hero Member
  • *****
  • Posts: 1468
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Arbitrary complex data structure?
« Reply #5 on: June 19, 2019, 09:12:40 pm »
In this example, I don't understand how is a rectangular in the first place?!

The line:

Code: [Select]
a:= [[1,2,3,4],[1,2,3]];
creates an array of 4 rows, 3 columns per row (or viceversa ;)); i.e. a rectangular array, as if it had been declared as:
a: array[0..3, 0..2] of Integer;


Strange syntax it is. %)

I would expect that initializer to allocate and populate array a to something like this:
a[0] = [1, 2, 3, 4] -- four elements
a[1] = [1, 2, 3] -- three elements

but, if I understand you well, it is actually:
a[0] ... allocate three integers (will they be initialized? to what? zeros?)
a[1] ... ditto
a[2] ... ditto
a[3] ... ditto

?


« Last Edit: June 19, 2019, 09:15:29 pm by Zoran »

lucamar

  • Hero Member
  • *****
  • Posts: 2130
Re: Arbitrary complex data structure?
« Reply #6 on: June 19, 2019, 09:49:15 pm »
Yes, that's it. It's kind of an array constructor; something like BASIC's Dim() sentence.

That is,  if I understood correctly the new sintax  :-[

ETA: Oh, re. initialization, IIRC they are initialized to the Default for the items' type. in that same constructor? I'm not sure.

It was announced in May, 2018 in (where else? :)) the fpc-anounce mailing list and extensively discused in fpc-pascal
« Last Edit: June 19, 2019, 10:12:47 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

Zoran

  • Hero Member
  • *****
  • Posts: 1468
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Arbitrary complex data structure?
« Reply #7 on: June 19, 2019, 11:28:30 pm »

It was announced in May, 2018 in (where else? :)) the fpc-anounce mailing list and extensively discused in fpc-pascal

But no, according to this announcement, it will be what I thought in the first place -- it will allocate 4+3 = 7 integers (and initialize them to given values). It will not allocate 4 * 3 = 12 integers.

So, the array was not rectangular in the first place.


lucamar

  • Hero Member
  • *****
  • Posts: 2130
Re: Arbitrary complex data structure?
« Reply #8 on: June 20, 2019, 09:34:52 am »
But no, according to this announcement, it will be what I thought in the first place -- it will allocate 4+3 = 7 integers (and initialize them to given values). It will not allocate 4 * 3 = 12 integers.

So, the array was not rectangular in the first place.

Hmmm ... You're right. It's not understandable otherwise.

Seems I'll have to re-learn quite some things after the 3.2 release  :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

Zoran

  • Hero Member
  • *****
  • Posts: 1468
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Arbitrary complex data structure?
« Reply #9 on: June 20, 2019, 10:38:48 am »
Ragged array like this is not what I means and I myself think it ugly. When people from JVM based language background said data structure he means Classes.

There are different container classes:
The simplest: TFPList

Then, TList
TColection

Then, generic containers (unit fgl)
Apart from these generic containers from fgl unit, there is more efficient generics.collections library, but not yet available in current FPC 3.0.

Some information in wiki: https://wiki.freepascal.org/Data_Structures,_Containers,_Collections






marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7596
Re: Arbitrary complex data structure?
« Reply #10 on: June 20, 2019, 10:56:06 am »
I think he means something like Tuples in some languages. It is not an original java or C# feature, but one that was added later because their VMs got it added for other functional and/or scripting languages. (LINQ)

And while you can emulate it with arrays of variants to some agree (and TDataset etc does), the scripting like language level syntax is not there. And hopefully never comes.

If you want a scripting language, may I suggest Python?
« Last Edit: June 22, 2019, 12:58:37 pm by marcov »

Thaddy

  • Hero Member
  • *****
  • Posts: 9280
Re: Arbitrary complex data structure?
« Reply #11 on: June 20, 2019, 11:32:09 am »
Yes, and has excellent FPC bindings...
also related to equus asinus.

giahung1997

  • Full Member
  • ***
  • Posts: 113
Re: Arbitrary complex data structure?
« Reply #12 on: June 20, 2019, 03:33:47 pm »
I think he means something like Tuples in some languages. It is not an original java or C# feature, but one that was added later because their VMs got it added for other functional and/or scripting languages.

And while you can emulate it with arrays of variants to some agree (and TDataset etc does), the scripting like language level syntax is not there. And hopefully never comes.

If you want a scripting language, may I suggest Python?
Please close this thread. Everyone misunderstood me and I confused everyone  :(
« Last Edit: June 21, 2019, 03:12:45 am by giahung1997 »
Hate me? I'm gone. You will never see me again. Fuck the people of this forum! Fuck this Lazarus! Fuck Pascal!

PascalDragon

  • Hero Member
  • *****
  • Posts: 712
  • Compiler Developer
Re: Arbitrary complex data structure?
« Reply #13 on: June 21, 2019, 10:09:27 am »
Please close this thread. Everyone misunderstood me and I confused everyone  :(
But please don't edit your initial post to remove the question, cause now nobody knows what everyone answered to.

giahung1997

  • Full Member
  • ***
  • Posts: 113
Re: Arbitrary complex data structure?
« Reply #14 on: June 22, 2019, 07:36:44 am »
Please close this thread. Everyone misunderstood me and I confused everyone  :(
But please don't edit your initial post to remove the question, cause now nobody knows what everyone answered to.
Then delete this thread altogether. It's a useless offtopic bulshit  8-)
Hate me? I'm gone. You will never see me again. Fuck the people of this forum! Fuck this Lazarus! Fuck Pascal!