[Swift-devel] New syntax for appending to arrays
Mihael Hategan
hategan at mcs.anl.gov
Tue Jun 28 14:12:34 CDT 2011
On Wed, 2011-06-29 at 00:31 +0530, Yadu Nand wrote:
> On Wed, Jun 29, 2011 at 12:26 AM, Mihael Hategan <hategan at mcs.anl.gov> wrote:
> > I very much agree with this, except I wouldn't say that one could
> > approach this from a type system perspective, but it is necessary to do
> > so. Using auto-indices on an int array would break things if the
> > auto-indices are string (which they are). In other words, the following
> > code would pass type checking but is essentially incorrect:
> > int a[];
> > a += 1; a += 2;
> >
> > foreach v, k in a {
> > trace(k + 1);
> > }
> This doesn't fail.
> a += 1 ; a += 2 ;
> Eventually comes to a[x] = 1 ; a[y] = 2 (where x and y are thread prefixes
> which turn out to be integers).
Only in special cases. Try this:
...
foreach dummy in [1..2] {
int a[];
a += 1; a += 2;
foreach v, k in a {
trace(k + 1);
}
}
More information about the Swift-devel
mailing list