Recent

Author Topic: Cannot nest anonymous array  (Read 1511 times)

SudoKai

  • New member
  • *
  • Posts: 6
    • SudoKai
Cannot nest anonymous array
« on: July 21, 2020, 09:20:08 am »
Just started playing around with pas2js and got stuck with Multi-Dimensional Arrays. I get 'Error: Cannot nest anonymous array' with the following:

Code: Pascal  [Select][+][-]
  1. Var
  2.  Multi_Array: Array of Array of Array of Integer;

I can bypass with the following code:

Code: Pascal  [Select][+][-]
  1. Type Multi_Array_Level_02 = record
  2.   M_Array_Level_02: Array of Integer;
  3.  end;
  4.  
  5. Type Multi_Array_Level_01 = record
  6.   M_Array_Level_01: Array of Multi_Array_Level_02;
  7.  end;
  8.  
  9. Var
  10.  Multi_Array: Array of Multi_Array_Level_01;

I also skimmed through the 'Pas2JS-WebGL demo' to see if there was a piece of code using Multi-Dimensional Arrays. But I spotted this comment in 'Mat4.pas'

Code: Pascal  [Select][+][-]
  1. // NOTE: [][] doesn't typecast to array of syntax so we need this

So is Multi-Dimensional Arrays not supported in pas2js just yet, or is it my programming skills that needs some adjustment?

Thaddy

  • Hero Member
  • *****
  • Posts: 10991
Re: Cannot nest anonymous array
« Reply #1 on: July 21, 2020, 09:25:10 am »
It should work. Try the most recent version and if that does not work file a bug report on Mantis.
Code: Pascal  [Select][+][-]
  1. program ma;
  2. Var
  3.  Multi_Array: Array of Array of Array of Integer;
  4. begin
  5. end.
« Last Edit: July 21, 2020, 09:26:55 am by Thaddy »
The average programmer productivity is 4-5 hours per day. Peak performance 72 hours for short bursts. MTBF is 1 second or less.

PascalDragon

  • Hero Member
  • *****
  • Posts: 3515
  • Compiler Developer
Re: Cannot nest anonymous array
« Reply #2 on: July 21, 2020, 11:55:02 am »
Nested anonymous array are currently not supported in Pas2JS as the compiler remarks (Error: Cannot nest anonymous array). You need to declare each sub array:

Code: Pascal  [Select][+][-]
  1. program tdynarr;
  2.  
  3. type
  4.   TLongIntArray = array of LongInt;
  5.   TLongIntArrayArray = array of TLongIntArray;
  6.   TLongIntArrayArrayArray = array of TLongIntArrayArray;
  7.   TLongIntArrayArrayArrayArray = array of TLongIntArrayArrayArray;
  8.  
  9. var
  10.   arr: TLongIntArrayArrayArrayArray;// array of array of array of array of LongInt;
  11.  
  12. begin
  13. end.

Thaddy

  • Hero Member
  • *****
  • Posts: 10991
Re: Cannot nest anonymous array
« Reply #3 on: July 21, 2020, 03:12:03 pm »
Yes that works, but it reads like a train station in Wales....
( which to be fair is actually https://en.wikipedia.org/wiki/Rhoose_Cardiff_International_Airport_railway_station )
« Last Edit: July 21, 2020, 03:19:21 pm by Thaddy »
The average programmer productivity is 4-5 hours per day. Peak performance 72 hours for short bursts. MTBF is 1 second or less.

 

TinyPortal © 2005-2018