Array declaration construct question.

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.

Moderator: POL Developer

Post Reply
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Array declaration construct question.

Post by Yukiko »

I am currently working on converting some old scripts and I have come across a curiosity.

In one of them there is an array declared as follows:

var thingarray:=(len(stuff));

Note the parenthesis rather than braces. I was just curious if this is legal? eCompile seems to accept it just fine but I have always seen arrays defined with braces.
Danielle
Grandmaster Poster
Posts: 104
Joined: Tue Feb 07, 2006 3:32 pm
Location: Pittsburgh, Pennsylvania

Post by Danielle »

Both methods work, but using braces is the preferred method and parenthesis are only there for backwards compatibility. It was changed with POL95.

From core-changes.txt:

Code: Select all

06-12 Syzygy
    escript changes:
        Added (yet another) syntax for declaring initialized arrays:
            var x := array { 4, 3, 2 };
            this is more consistent with struct { x, y, z } initializer syntax.
            array(8,3,2) looks too much like it's creating a multi-dimensional array, so I don't like it anymore.
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Post by Yukiko »

Thanks.

I am converting to current compatibility sooo... the parens get changed to braces.
User avatar
tekproxy
Forum Regular
Posts: 352
Joined: Thu Apr 06, 2006 5:11 pm
Location: Nederland, Texas

Post by tekproxy »

In the distro we do this:

Code: Select all

var array := array{1, 2, 3};
Barbeirosa

Post by Barbeirosa »

In addition to changing the parens to braces, you should add the 'array' keyword like tek showed, as I think that's the more 'official' way and so is likely to stay supported in the future too.
Bracco
Adept Poster
Posts: 80
Joined: Thu Dec 28, 2006 11:52 am

Post by Bracco »

i always used

var abc:={};

to declare an array... i like it more than var abc:=array; or var abc:=array{};

the latter one seems too much of a 2 dimension array... and the other is too "literal", i like the {} which reminds me of [] c++ syntax

:P
Yukiko
Distro Developer
Posts: 2825
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Post by Yukiko »

I have no idea why the use of the sole keyword array was deprecated. It seems illogical to me that array{} and {} are legal and array is not. Using just {} is very cryptic and array{} adds more typing and takes up additional, albeit a minor amount of, space in src files.
Post Reply