Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: Multi-dimensional array initialization syntax?  (Read 4883 times)
Hans-Joachim K.
Posts: 7


« on: November 09, 2023, 12:30:08 pm »

Hello, this is probably an easy one for you but I did not find any hint in the doc so far.

When defining a simple array, I can initialize it at the same time:

DEFINE myarray1 ARRAY [4] OF INTEGER = [ 1, 2, 3, 4 ]

But when defining a two-dimensional array like this:

DEFINE myarray2 ARRAY [2,4] OF INTEGER

How is the syntax then? I tried different variants but was not successful so far.

Thank you very much in advance,
Hajo
Sebastien F.
Four Js
Posts: 509


« Reply #1 on: November 09, 2023, 02:09:56 pm »

Hi!

Code
  1. sf@toro:/tmp$ cat a.4gl
  2. IMPORT util
  3.  
  4. DEFINE arr ARRAY[5,3] OF INTEGER = [
  5. [1,2,3],
  6. [1,2,3],
  7. [1,2,3],
  8. [1,2,3],
  9. [1,2,3]
  10. ]
  11.  
  12. MAIN
  13.    DISPLAY util.JSON.stringify(arr)
  14. END MAIN
  15. sf@toro:/tmp$ fglcomp -M a.4gl && fglrun a.42m
  16. [[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3]]
  17.  
Hans-Joachim K.
Posts: 7


« Reply #2 on: November 09, 2023, 03:05:59 pm »

Hello Sebastien, thank you for your fast reply.

This way of initialization was actually among the ones I tried, but I am always getting this:

Compiling 'jobs/testArr.4gl'
testArr.4gl:4:1:4:1:error:(-6609) A grammatical error has been found at '[' expecting: CHAR_CONST INT_CONST DEC_CONST IDENT DATETIME FALSE INTERVAL MDY NOTFOUND NULL TRUE '+' '-' '(' '%'.
::error:(GS-1072) The command 'fglcomp --build-rdd -M /opt/gstshare/watmes_khj/jobs/testArr.4gl' failed with exit code 1.
*** Failure [15:01:28] ***

I am using exactly your code:

IMPORT util
 
DEFINE arr ARRAY[5,3] OF INTEGER = [
[1,2,3],
[1,2,3],
[1,2,3],
[1,2,3],
[1,2,3]
]
 
MAIN
   DISPLAY util.JSON.stringify(arr)
END MAIN

Was there maybe a bugfix which I am missing in the compiler?
I am  using Studio 4.00.03 with the matching version on the Linux host.

Thank you very much,
Hajo
Sebastien F.
Four Js
Posts: 509


« Reply #3 on: November 09, 2023, 03:26:29 pm »

Consider watching the product news on our web site!
https://4js.com/news/products/

Genero 4.00 is desupported since 4.01 was released back in April 2022:
https://4js.com/2022-genero-enterprise-4-01-maintenance-release/

The latest version of Genero BDL is 4.01.05:
https://4js.com/2023-genero-enterprise-four-js-maintenance-release-activity-for-september-2023/

Download from:
https://4js.com/download/products/?

Seb
Rene S.
Four Js
Posts: 111


« Reply #4 on: November 09, 2023, 03:49:59 pm »

... requires 4.01.02 or later.
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines