[Swift-devel] Associative array in Swift [GSoC]
Ben Clifford
benc at hawaga.org.uk
Fri Jun 17 16:26:49 CDT 2011
> must have in order to be useful for map-reduce. It seems that there must
> be some way to add multiple associations of values to the same key.
> Right now, if I try :
> a[0] = 100 ; a[0] = 200;
> I get an error saying " a is closed with value 100"
> Instead the above should probably make the lookup a[0] return a list of
> values, say [100, 200] . I could really use help on this.
As you phrase it above, that seems quite awkward. The syntax you specify
above looks like a mutation: a[0] "starts" empty, then you say a[0]=100,
meaning something like a[0] = a[0] ++ [100]; (where ++ is list
concatenation); and then you say a[0] = 200; which means a[0] = a[0] +
[200];
Expressing mutating behaviour like that is very wrong in the existing
model.
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 can see various ways that might work, though.
--
More information about the Swift-devel
mailing list