[Swift-devel] Associative array in Swift [GSoC]

Yadu Nand yadudoc1729 at gmail.com
Fri Jun 17 17:08:50 CDT 2011


>> One practical problem, for example, is if I want to use the value of a[0].
>> How can I know when that value is fully specified? If I have to wait until
>> there are no more writes to a[], then a lot of the pipelining stops
>> working - in swift now, i can use values of a[] as they are written (for
>> example, in foreach loop), without having to wait for a[] to be fully
>> populated.
>
> I think a[0] would be treated like an array over which one could
> iterate. But then we can already have arrays of arrays, so I'm not quite
> sure what the issue is here.

I tested the following piece of code, and I think my earlier doubts are
cleared.

int a[ ][ ];
a["hi"][0] = 10;
a["hi"][1] = 20;
a["hi"][2] = 30;
foreach value, i in a["hi"] {
        trace(value);
}

It works :)

Now the only doubt that remains is, what happens when you write code
in which we don't know the 2nd index. Say something like this :
a[0][1] = 100;
 ...
a[0][n] = 10000;
Is such a situation possible ? In which case is the logic following
logic valid?
a[0] [ a[0].length + 1 ]  = val ;


-- 
Thanks and Regards,
Yadu Nand B



More information about the Swift-devel mailing list