[Swift-devel] Appendable data structures in Swift/K and Swift/T

Mihael Hategan hategan at mcs.anl.gov
Wed Sep 4 16:07:18 CDT 2013


On Wed, 2013-09-04 at 15:23 -0500, Tim Armstrong wrote:
> Awesome, thanks, that clears things up.  For some reason I was thinking
> that [auto] was something like an auto-incremented integer.

I think we quickly dismissed that because of the problems you alluded to
in the previous email.

There is also the issue of re-starts, which requires that the index
allocation be deterministic (actually identical) between different runs
of the same script.

> 
> Does that mean that "b[k] = x"  and append(b, x) are semantically identical
> in these two code fragments?
> 
> ==============
> foreach v, k in a {
>    b[k] = a[k] * 2;
> }
> ---------------------------
> foreach v in a {
>    append(b, a[k] * 2);
> }
> ==============

Nope. The first guarantees that both arrays have the same number of
elements AND the same keys.

The second one only guarantees that the arrays have the same number of
elements.

The distinction is obvious if you add another loop:

foreach v, k in a {
   int s = a[k] + b[k];
}

That subsequent foreach is only guaranteed to work in the first case you
have above.

> 
> Also, I was wondering how this interacts with mappers?  E.g. if a have an
> [auto] array mapped with simple_mapper, then what filenames would be
> produced for something like this?
> file outfile[] <simple_mapper;prefix="baz",suffix=".txt">;
> 
> append(outfile , ...);
> 
> append(outfile , ...);

Like a [int] array. The string keys get SHA-1ed.

Which might be  a reasonable solution to getting rid of the string keys.
Thanks!

Mihael




More information about the Swift-devel mailing list