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

Mihael Hategan hategan at mcs.anl.gov
Sat Jun 18 15:04:05 CDT 2011


I see no reason* why the addition operator couldn't be overloaded for
arrays to mean "append". That, to me, seems less random than a random
index symbol ("!"). Of course, I'd rather have this whole issue
implemented as list comprehensions in python/karajan style (a = for v, k
in b { f(v);}), but I think the changes, both semantic and syntactic to
swift required to have that would be too dramatic.

* Well, there is a reason, as that may conflict with bulk array
operations if we ever implement those (i.e. a + 3 meaning add 3 to each
element in the array).

On Sat, 2011-06-18 at 14:48 +0000, Ben Clifford wrote:
[...]
> In a Swift context, I could imagine a syntax:
> 
>   a[!] = f(i,j)
> 
> where ! means "some appropriate unique index" (I think the restart code 
> did/does do that foreach loops to label variables in nested scope in a way 
> that could be used here).
> 
> So then Yadu's: a[0] = 100; a[0] = 200; example might turn into:
> 
>   int a[][]; a[0][!] = 100; a[0][!] = 200;
> 
> That parallelises still but doesn't require you to explicitly think about 
> the index.
> 





More information about the Swift-devel mailing list