Page 1 of 1

Array declaration construct question.

Posted: Wed Mar 14, 2007 9:10 pm
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.

Posted: Wed Mar 14, 2007 9:15 pm
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.

Posted: Wed Mar 14, 2007 9:26 pm
by Yukiko
Thanks.

I am converting to current compatibility sooo... the parens get changed to braces.

Posted: Thu Mar 15, 2007 6:10 am
by tekproxy
In the distro we do this:

Code: Select all

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

Posted: Thu Mar 15, 2007 8:40 am
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.

Posted: Thu Mar 15, 2007 8:56 am
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

Posted: Thu Mar 15, 2007 11:53 am
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.