<div dir="ltr">@Tyler,<div><br></div><div>Excellent summary of concerns which has made me revise my preferences!</div><div><br></div><div>I would suggest a few differences from your suggestions (primarily based on the interpretation of `mutating &lt;name&gt;` as the name of the method, i.e. the method name includes `mutating`). The couple of areas I suggest are:</div><div><br></div><div>    1. Use `mutating` after `func` in declarations: `func mutating sort(...)`.</div><div>    2. Use mutating after `.` in calls: `array.mutating sort(&lt;)`</div><div>    3. Allow mutating for classes:</div><div>        </div><div>        protocol P { func mutating p() }</div><div>        class AP: P { func mutating p() { ... }</div><div>        let aP = AP()</div><div>        aP.mutating p() // Mutates what `aP` points to</div><div><br></div><div>    2. Treat mutating as part of name when chaining:</div><div><br></div><div>        <span style="color:rgb(69,69,69);font-size:12.8px">let median = foo.calculateBigHugeArray().mutating </span><span style="color:rgb(69,69,69);font-size:12.8px">sort().medianValue()</span></div><div><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature">  -- Howard.<br></div></div>
<br><div class="gmail_quote">On 28 April 2016 at 10:44, Tyler Cloutier via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><blockquote type="cite"><span class=""><div>On Apr 23, 2016, at 1:27 AM, Pyry Jahkola via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br></span><div><div style="word-wrap:break-word"><span class=""><div>I&#39;d like to second James Campbell&#39;s suggestion of a `<font face="Menlo"><span style="font-size:11px">mutate</span></font>` keyword. Clarifying comments inline below:</div><br><blockquote type="cite">On 23 Apr 2016, at 00:24, Dave Abrahams via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></blockquote></span><div><span class=""><blockquote type="cite"><br><div><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">This is not a new idea.  Something almost identical to this has been</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">explored and discussed quite thoroughly already:</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">&lt;</span><a href="https://github.com/apple/swift/blob/master/docs/proposals/Inplace.rst" style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://github.com/apple/swift/blob/master/docs/proposals/Inplace.rst</a><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">&gt;.</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">In fact, it was implmented and later reverted because it raised</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">language-design questions for which we had no good answers.</span></div></blockquote><div><br></div><div>I don&#39;t know if the following are particularly good answers, but I&#39;ll try anyway:</div><br><blockquote type="cite"><div><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">I don&#39;t </span><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">believe the choice of glyph (&amp; vs =) affects any of the</span></div></blockquote><blockquote type="cite"><div><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">fundamental </span><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">issues:</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">* Should the x.=f() syntax be required for *every* mutating method</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important"> invocation?</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"></div></blockquote><div><br></div><div>Allow me to ask it differently: Should <b>some</b> specific syntax be required for every mutating method? — Yes.</div><div><br></div></span><span class=""><div>Should the syntax be `<font face="Menlo"><span style="font-size:11px">x.=f()</span></font>`? — Not necessarily. I kinda like James Campbell&#39;s idea of a `<font face="Menlo"><span style="font-size:11px">mutate</span></font>` keyword. Consider the following:</div><div><br></div><div><font face="Menlo"><span style="font-size:11px">    <b>var</b> numbers = [5, 12, 6, 2]</span></font></div><div><font face="Menlo"><span style="font-size:11px">    <b>mutate</b> numbers.append(10)</span></font></div><div><font face="Menlo"><span style="font-size:11px">    <b>mutate</b> numbers.sort()</span></font></div><div><font face="Menlo"><span style="font-size:11px">    <b>if let</b> </span></font><span style="font-family:Menlo;font-size:11px">biggest</span><font face="Menlo"><span style="font-size:11px"> = <b>mutate</b> numbers.popLast() {</span></font></div><div><font face="Menlo"><span style="font-size:11px">        print(&quot;The biggest number was:&quot;, biggest)</span></font></div><div><font face="Menlo"><span style="font-size:11px">    }</span></font></div><div><br></div></span><div>So `<font face="Menlo"><span style="font-size:11px">mutate</span></font>` would work much like `<font face="Menlo"><span style="font-size:11px">try</span></font>` but—unlike `<font face="Menlo"><span style="font-size:11px">try</span></font>` which can move further to the left—`<font face="Menlo"><span style="font-size:11px">mutate</span></font>` would have to always prefix the mutating receiver. Here&#39;s a contrived example of a corner case:</div><div><br></div><div><font face="Menlo"><span style="font-size:11px">    <b>enum</b> Error : ErrorType { <b>case</b> BadNumber }</span></font></div><div><font face="Menlo"><span style="font-size:11px"><br></span></font></div><div><font face="Menlo"><span style="font-size:11px">    <b>func</b> demo() <b>throws</b> -&gt; Int {</span></font></div><div><font face="Menlo"><span style="font-size:11px">        </span></font></div><div><font face="Menlo"><span style="font-size:11px">    }</span></font></div><div><br></div><blockquote type="cite"><div><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">* Are assignment methods a redundant way to spell mutating methods?</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important"> Should we really have both mechanisms?</span></div></blockquote><div><br></div><div>(I had to look up the definition of an <i>assignment method</i>. For the uninitiated, Dave is talking about what&#39;s written here: <a href="https://github.com/apple/swift/blob/master/docs/proposals/Inplace.rst#use-one-simple-name" target="_blank">https://github.com/apple/swift/blob/master/docs/proposals/Inplace.rst#use-one-simple-name</a>.)</div><div><br></div><div>— Yes they are redundant, and no, we should not have both.</div><div><br></div><div>With `<font face="Menlo"><span style="font-size:11px">mutate</span></font>` required at the call site, we could simply allow both overloads `<font face="Menlo"><span style="font-size:11px"><b>func</b> sort()</span></font>` and `<font face="Menlo"><span style="font-size:11px"><b>mutating func</b> sort()</span></font>` to coexist, because the call sites become unambiguous:</div><div><br></div><div><font face="Menlo"><span style="font-size:11px">    <b>let</b> originals = [2, 1, 3, 0, 4, 2]</span></font></div><div><font face="Menlo"><span style="font-size:11px">    <b>var</b> copies = originals</span></font></div><div><font face="Menlo"><span style="font-size:11px"><br></span></font></div><div><font face="Menlo"><span style="font-size:11px">    originals.sort()           <font color="#919191">// <b>warning:</b> result of call to &#39;sort()&#39; is unused</font></span></font></div><div><font face="Menlo"><span style="font-size:11px">    <font color="#ff2600"><b>mutate</b> originals.sort()</font>    <font color="#919191">// <b>compiler error</b></font></span></font></div><div><font face="Menlo"><span style="font-size:11px">    <b>let</b> xs = originals.sort()  <font color="#919191">// ok</font></span></font></div><div><br></div><div><font face="Menlo"><span style="font-size:11px">    copies.sort()</span></font><span style="font-family:Menlo;font-size:11px">                 </span><span style="font-family:Menlo;font-size:11px"><font color="#919191">// <b>warning:</b> result of call to &#39;sort()&#39; is unused</font></span></div><div><font face="Menlo"><span style="font-size:11px">    <b>mutate</b> copies.sort()          <font color="#919191">// ok</font></span></font></div><div><font face="Menlo"><span style="font-size:11px">    <b>let</b> ys = copies.sort()        <font color="#919191">// ok</font></span></font></div><div><span style="font-size:11px;font-family:Menlo">    <b>let</b> zs = mutate copies.sort() <font color="#919191">// <b>warning:</b> constant &#39;x&#39; inferred to have type &#39;()&#39;, which may be unexpected</font></span></div><div><br></div><div>The language could also allow the use of</div><div><font face="Menlo"><span style="font-size:11px"><b><br></b></span></font></div><div><b style="font-family:Menlo;font-size:11px">    mutate</b><font face="Menlo"><span style="font-size:11px"> x.next()</span></font></div><div><br></div><div>as shorthand for</div><div><br></div><div><font face="Menlo"><span style="font-size:11px">    x = x.next()</span></font></div><div><br></div><div>when only the non-mutating variant `<font face="Menlo"><span style="font-size:11px"><b>func</b> next() -&gt; <b>Self</b></span></font>` exists with compatible return type.</div><br><blockquote type="cite"><div><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">* Can we really introduce this feature without having a way to apply it</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important"> to class types?</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"></div></blockquote><div><br></div><div>Yes we can. Why complicate the naming of value type members with the complexities of reference semantics? The current API naming conventions are <i>good</i> for reference types which sometimes come with unobvious to obscure behaviour (i.e. anything from bumping an internal counter to firing missiles and wiping hard drives).</div><div><br></div><div>But value types ought to have no side effects (besides memory allocation and logging maybe), and so we don&#39;t necessarily need that strong a naming convention to limit their collateral damage.</div><div><br></div><div>If the `<font face="Menlo"><span style="font-size:11px">mutate</span></font>` keyword became required for calling `<font face="Menlo"><span style="font-size:11px">mutating</span></font>` methods, then operators would remain the only place where naming convention were needed to distinguish mutation:</div><div><br></div><div><ul><li>Mutating assignment is <b>explicit</b>: `<font face="Menlo"><span style="font-size:11px">xs = [1, 2] + xs + [2, 1]</span></font>` (i.e. `<font face="Menlo"><span style="font-size:11px">=</span></font>` without `<font face="Menlo"><span style="font-size:11px">let</span></font>` or `<font face="Menlo"><span style="font-size:11px">var</span></font>` means mutation)</li><li>Mutating method call becomes <b>explicit</b>: `<font face="Menlo"><span style="font-size:11px"><b>mutate</b> xs.sort()</span></font>` and `<font face="Menlo"><span style="font-size:11px"><b>let</b> x = <b>mutate</b> xs.removeAtIndex(2)</span></font>`</li><li>Mutating function arguments are <b>explicit</b> with the `<font face="Menlo"><span style="font-size:11px">&amp;</span></font>` prefix: `<font face="Menlo"><span style="font-size:11px">swap(&amp;xs, &amp;ys)</span></font>`</li><li>Mutating operators are <b>implicit</b> and <i>by convention,</i> should end with the `=` symbol: `<font face="Menlo"><span style="font-size:11px">xs += [8, 9]</span></font>`</li><li>Reference types have no notion of `<font face="Menlo"><span style="font-size:11px">mutating</span></font>` members (and probably ought to remain that way) so they mutate <b>implicitly</b>.</li></ul></div><br><blockquote type="cite"><div><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">I should also point out that under the assignment method paradigm one</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">would probably need to re-evalutate rules for naming.  Under the current</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">API guidelines&#39; approach, we&#39;d write:</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">   x.=sorted()      // sort x in-place</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">and I am not sure how easy that would be for people to swallow</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">considering how much more straightforward</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">   x.sort()         // current way to sort x in-place</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">is, and because the language now contains explicit notation for</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">mutation, it becomes harder to argue against theis pair:</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">   y = x.sort()</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">   x.=sort()      // sort x in place</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"></div></blockquote><div><br></div><div>I agree that the current API guidelines wouldn&#39;t work for value types anymore. Both `sort` and `sorted` would be called `sort`.</div><br><blockquote type="cite"><div><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">Lastly, I should point out that the proposal does nothing to solve the</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">problem of `c.formSuccessor(&amp;i)`, since that doesn&#39;t mutate the</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">receiver.</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"></div></blockquote><div><br></div><div>This proposal does address the problem of `<font face="Menlo"><span style="font-size:11px">c.formSuccessor(&amp;i)</span></font>`. Given that it&#39;s value types at play here, what mutates in the following is unambiguous even to non-native English speakers:</div><div><br></div><div><font face="Menlo"><span style="font-size:11px">    c.frobnicate(&amp;i)                <font color="#919191">// cannot possibly mutate c but mutates i</font></span></font></div><div><font face="Menlo"><span style="font-size:11px">    </span><b style="font-size:11px">let</b><span style="font-size:11px"> j = c.frobnicate(i)         </span><font color="#919191" style="font-size:11px">// cannot possibly mutate either</font></font></div><div><font face="Menlo"><span style="font-size:11px">    </span><b style="font-size:11px">mutate</b><span style="font-size:11px"> c.frobnicate(i)          </span><font color="#919191" style="font-size:11px">// mutates c</font></font></div><div><font face="Menlo"><span style="font-size:11px">    </span><b style="font-size:11px">let</b><span style="font-size:11px"> k = </span><b style="font-size:11px">mutate</b><span style="font-size:11px"> c.frobnicate(&amp;i) </span><font color="#919191" style="font-size:11px">// mutates both</font></font></div></div></div></div></blockquote><div><br></div><div>How would this chain if I wanted to do something like:</div><div><br></div><div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)">let median = foo.calculateBigHugeArray().sort().medianValue()</div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)"><br></div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)">and I want the sort to be done in place. Or will this type of thing just be disallowed in favor of.</div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)"><br></div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)">let array = foo.calculateBigHugeArray()</div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)">mutate array.sort()</div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)">let median = array.medianValue() </div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)"><br></div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)"><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal">Alternately you could replace the method invocation operator with &amp;</div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal">let median = foo.calculateBigHugeArray()&amp;sort().medianValue()</div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal">Or depending how sacrilegious you’re feeling you could use the only character on the keyboard that isn’t currently used and doesn’t require the shift key and is easily distinguished from a ‘.’</div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal">let median = foo.calculateBigHugeArray()&#39;sort().medianValue()</div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal">This is definitely more confusing than the &amp; and mutate, since &amp; is used to indicate mutation elsewhere.</div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal"><br></div></div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)"><br></div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)">Also, if you wanted to stick with consistent &amp; syntax, you could do:</div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)"><br></div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)">&amp;c.frobnicate(i)</div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)">and </div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)">let k = &amp;c.frobnicate(&amp;i)</div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)"><br></div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)"><br></div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)">Dave, to your point about classes, there is currently already special syntax for value types with the &amp; as parameters. Reference semantics is the wild west there anyway.</div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)"><br></div></div><br><blockquote type="cite"><div><div style="word-wrap:break-word"><div><br><blockquote type="cite"><div><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">I still like the proposal&#39;s basic approach and would love to see it used</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">to address these naming problems, but I want to be clear that it&#39;s by no</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">means a panacea and there are real obstacles between here and actually</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">being able to apply it.  If you want to move forward with something like</span><br style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Menlo-Regular;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">this, you need to solve the problems described above.</span></div></blockquote></div><br>I think this proposal would simplify all code handling value types. Yes, it adds one keyword of boilerplate but wins clarity in return. I think reference types should stay separate from this discussion, as their mutation has always been implicit anyway. The API guidelines set a good convention for them.<br><div><br></div><div>— Pyry</div><div><br></div></div><span class="">_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></span></div></blockquote></div><br></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>