<div dir="ltr"><div><div>Awesome, thanks, that clears things up.  For some reason I was thinking that [auto] was something like an auto-incremented integer.<br></div><br></div><div>Does that mean that "b[k] = x"  and append(b, x) are semantically identical in these two code fragments?<br>
</div><div><span style="font-family:courier new,monospace"><br>==============<br>foreach v, k in a {<br>
   b[k] = a[k] * 2;<br>}<br>---------------------------</span><span style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"><br>foreach v in a {<br>
   append(b, a[k] * 2);<br>}<br></span>==============</span><br><br></div>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?<br>
<span style="font-family:courier new,monospace">file outfile[] <simple_mapper;prefix="baz",suffix=".txt">;<br><br>append(outfile , ...);<br><br>append(outfile , ...);<br><br><br></span>- Tim<br></div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Sep 4, 2013 at 3:01 PM, Mihael Hategan <span dir="ltr"><<a href="mailto:hategan@mcs.anl.gov" target="_blank">hategan@mcs.anl.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Wed, 2013-09-04 at 12:23 -0500, Tim Armstrong wrote:<br>
> Hi All,<br>
><br>
> I've been working on adding appendable data structures to Swift/T.  I<br>
> thought I would email to clarify a couple of points about the [auto] arrays<br>
> in Swift/K and also to get feedback on the Swift/T implementation.  Ideally<br>
> we'd do things the same way in both but I'm not confident that the Swift/K<br>
> semantics will work well for us.<br>
><br>
> First, clarifying questions, since I'm not 100% clear on what happens when<br>
> you "use auto key values from one array to access another", e.g. the<br>
> example:<br>
><br>
> ======================<br>
> int[auto] a;<br>
> int[auto] b;<br>
><br>
> append(a, 1);<br>
> append(a, 2);<br>
><br>
> foreach v, k in a {<br>
>   b[k] = a[k] * 2;<br>
> }<br>
> =====================<br>
><br>
> There are a few corner cases I don't quite understand in the above example.<br>
> Are there any guarantees about how the keys are assigned, e.g. in order<br>
> from 0?<br>
<br>
</div>I don't think foreach guarantees an order at all, regardless of the key<br>
types.<br>
<div class="im"><br>
>   What is the type of k?<br>
<br>
</div>auto :)<br>
<br>
Some unspecified internal representation that, from the perspective of<br>
the type system, is different from every other type (except a universal<br>
type if we had one).<br>
<br>
Internally it is a string at the moment. I think a sequential integer<br>
might be an alternative, but I suspect there is a reason why we didn't<br>
pick it.<br>
<div class="im"><br>
>  Can you treat it as an integer e.g. to<br>
> trace?<br>
<br>
</div>No. It cannot safely be treated as anything that tracef currently has.<br>
But %s would probably work by accident.<br>
<div class="im"><br>
><br>
> Also, is it possible to double-assign an index by doing that?  E.g. if I<br>
> append(b, 1); before the loop, is it possible for that to conflict with one<br>
> of the b[k] = ... assignments?<br>
<br>
</div>No. Which is probably why we use source location + thread ID instead of<br>
integers as keys. You can't have two different assignment statements in<br>
the same source location and running in the same thread.<br>
<div class="im"><br>
><br>
> Anyway, in Swift/T I've been playing around with an unordered set data<br>
> structure: a "bag": with some similar functionality.  There were a couple<br>
> of reasons I didn't just clone the Swift/K version:<br>
><br>
</div>>    - We can't efficiently sequentially assign indices if the data structure<br>
<div class="im">>    is split across multiple nodes (currently not the case, but possible in<br>
>    future).<br>
<br>
</div>DHTs?<br>
<br>
>    - The append(A, x) operation that mutates it's first argument is a<br>
<div class="im">>    little awkward semantically/implementation-wise, since it looks like a<br>
>    function call but can't be handled as one: the first argument is an LValue<br>
>    whereas a function argument is an RValue.  The logic for handling L/RValues<br>
>    in Swift/T is quite different in the grammar/frontend/semantic analyser.  I<br>
>    can easily enough make "append" a reserved word and special-case it in the<br>
>    grammar to work around this, but it feels a bit "wrong" and inconsistent to<br>
>    have something that looks like a function that's doesn't obey the semantics<br>
>    of a function.  I remember Swift/K had a += operator at one point - what<br>
>    was the argument for moving away from it?<br>
<br>
</div>I think that we voted on 'a << value', and that is still supported.<br>
Quoting from the swift parser's list of operators:<br>
GE        :   ">=";<br>
APPEND    :   "<<";<br>
ASSIGN  :   '=' ;<br>
<br>
I can't find the emails in the online archive, but I do have this in my<br>
inbox:<br>
<br>
Subject:        Re: [Swift-devel] New syntax for appending to arrays<br>
Date:   Tue, 28 Jun 2011 15:48:05 -0500 (06/28/11 13:48:05)<br>
<br>
> So far we have:<br>
> 3, 0, 3, 5, 3, 3, (0, 1, 5)<br>
><br>
> Anybody else?<br>
><br>
> On Tue, 2011-06-28 at 14:29 -0500, Mihael Hategan wrote:<br>
> > On Tue, 2011-06-28 at 09:08 -0500, Ian Foster wrote:<br>
> > > $0,02 from me -- given that Swift has a C-like syntax, this syntax<br>
will surely confuse people??<br>
> ><br>
> > "+=" is a bit confusing, but then I don't think it's more so than<br>
using<br>
> > "+" as a string concatenation operator.<br>
> ><br>
> > So please vote or propose an alternative:<br>
> ><br>
> > 0. a += 1;<br>
> > 1. a ++= 1;<br>
> > 2. a ++ 1;<br>
> > 3. a << 1;<br>
> > 4. a[] = 1;<br>
> > 5. a .= 1;<br>
<br>
Mihael<br>
<br>
</blockquote></div><br></div>