<div dir="ltr">+1<div><br></div><div>I would also like to change the call site to use <font face="monospace, monospace">inout</font> as well.</div><div><br></div><div><font face="monospace, monospace">foo(inout myVariable)</font></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 29, 2016 at 2:40 PM, Dave via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></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">+1<br><div><blockquote type="cite"><div><div><div>On Jan 29, 2016, at 11:37, Erica Sadun via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br></div></div><div><div><div><div style="word-wrap:break-word"><a href="https://github.com/apple/swift-evolution/pull/127" target="_blank">https://github.com/apple/swift-evolution/pull/127</a><div><br></div><div><h1 style="margin:0px 0px 0.875em;font-size:1.5em;line-height:0.875em;font-family:'Helvetica Neue',Helvetica,Arial,Verdana,sans-serif">Adjusting <code>inout</code> Declarations for Type Decoration</h1><ul style="color:rgb(17,17,17);font-family:'Helvetica Neue',Helvetica,Arial,Verdana,sans-serif;font-size:16px"><li style="font-size:18px">Proposal: TBD</li><li style="font-size:18px">Author(s): <a href="https://github.com/jckarter" style="color:rgb(13,110,161);text-decoration:none" target="_blank">Joe Groff</a>, <a href="http://github.com/erica" style="color:rgb(13,110,161);text-decoration:none" target="_blank">Erica Sadun</a></li><li style="font-size:18px">Status: TBD</li><li style="font-size:18px">Review manager: TBD</li></ul><h2 style="color:rgb(17,17,17);margin:0px 0px 0.9545454545454546em;font-size:1.375em;line-height:0.9545454545454546em;font-family:'Helvetica Neue',Helvetica,Arial,Verdana,sans-serif">Introduction</h2><p style="color:rgb(17,17,17);font-family:'Helvetica Neue',Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word;font-size:1.1429em;line-height:1.3125em;margin:1.3125em 0px">The <code>inout</code> keyword indicates copy-in/copy-out argument behavior. In its current implementation<br>the keyword prepands argument names. We propose to move the <code>inout</code> keyword to the right<br>side of the colon to decorate the type instead of the parameter label. </p><p style="color:rgb(17,17,17);font-family:'Helvetica Neue',Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word;font-size:1.1429em;line-height:1.3125em;margin:1.3125em 0px"><em>The initial Swift-Evolution discussion of this topic took place in the “Replace ‘inout’ with &” thread.</em></p><h2 style="color:rgb(17,17,17);margin:0px 0px 0.9545454545454546em;font-size:1.375em;line-height:0.9545454545454546em;font-family:'Helvetica Neue',Helvetica,Arial,Verdana,sans-serif">Motivation</h2><p style="color:rgb(17,17,17);font-family:'Helvetica Neue',Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word;font-size:1.1429em;line-height:1.3125em;margin:1.3125em 0px">In Swift 2, the <code>inout</code> parameter lives on the label side rather than the type side of the colon<br>although the keyword isn’t modifying the label but its type. Decorating<br>types instead of labels offers identifiable advantages: </p><ul style="color:rgb(17,17,17);font-family:'Helvetica Neue',Helvetica,Arial,Verdana,sans-serif;font-size:16px"><li style="font-size:18px"><div style="word-wrap:break-word;line-height:1.3125em;margin:0px">It enables the <code>inout</code> keyword to properly integrate into full type syntax, for example: </div><pre><code style="display:block;padding:0.5em;color:rgb(51,51,51);background-color:rgb(248,248,248);background-position:initial initial;background-repeat:initial initial"><span><span style="color:rgb(153,0,0);font-weight:bold">(x: inout T)</span> -></span> U <span style="color:rgb(0,153,38)">//</span><span> =></span> <span><span style="color:rgb(153,0,0);font-weight:bold">(inout T)</span> -></span> U</code></pre></li><li style="font-size:18px"><div style="word-wrap:break-word;line-height:1.3125em;margin:0px">It avoids notational similarity with arguments labeled <code>inout</code>, for example:</div><pre><code style="display:block;padding:0.5em;color:rgb(51,51,51);background-color:rgb(248,248,248);background-position:initial initial;background-repeat:initial initial">func foo<span><span style="color:rgb(153,0,0);font-weight:bold">(inOut x: T)</span> // <span style="color:rgb(153,0,0);font-weight:bold">foo</span><span style="color:rgb(153,0,0);font-weight:bold">(inOut:)</span>, <span style="color:rgb(153,0,0);font-weight:bold">type</span> <span style="color:rgb(153,0,0);font-weight:bold">(T)</span> -></span> Void
func foo<span><span style="color:rgb(153,0,0);font-weight:bold">(inout x: T)</span> // <span style="color:rgb(153,0,0);font-weight:bold">foo</span><span style="color:rgb(153,0,0);font-weight:bold">(_:)</span>, <span style="color:rgb(153,0,0);font-weight:bold">type</span> <span style="color:rgb(153,0,0);font-weight:bold">(inout T)</span> -></span> Void</code></pre></li><li style="font-size:18px"><div style="word-wrap:break-word;line-height:1.3125em;margin:0px">It better matches similar patterns in other languages such as borrowing in Rust, that may be later introduced back to Swift </div></li></ul><h2 style="color:rgb(17,17,17);margin:0px 0px 0.9545454545454546em;font-size:1.375em;line-height:0.9545454545454546em;font-family:'Helvetica Neue',Helvetica,Arial,Verdana,sans-serif">Detailed design</h2><pre style="color:rgb(17,17,17);font-size:16px"><code style="display:block;padding:0.5em;color:rgb(51,51,51);background-color:rgb(248,248,248);background-position:initial initial;background-repeat:initial initial">parameter → external<span style="color:rgb(0,128,128)">-parameter</span><span style="color:rgb(0,128,128)">-name</span> optlocal<span style="color:rgb(0,128,128)">-parameter</span><span style="color:rgb(0,128,128)">-name</span> : <span style="font-weight:bold">type</span><span style="color:rgb(0,128,128)">-annotation</span>
<span style="font-weight:bold">type</span><span style="color:rgb(0,128,128)">-annotation</span> → inout <span style="font-weight:bold">type</span><span style="color:rgb(0,128,128)">-annotation</span></code></pre><h2 style="color:rgb(17,17,17);margin:0px 0px 0.9545454545454546em;font-size:1.375em;line-height:0.9545454545454546em;font-family:'Helvetica Neue',Helvetica,Arial,Verdana,sans-serif">Alternatives Considered</h2><p style="color:rgb(17,17,17);font-family:'Helvetica Neue',Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word;font-size:1.1429em;line-height:1.3125em;margin:1.3125em 0px">Decorations using <code>@inout</code> (either <code>@inout(T)</code> or <code>@inout T</code>) were considered and discarded</p></div></div></div></div>_______________________________________________<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></div></blockquote></div><br></div><br>_______________________________________________<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" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Trent Nadeau</div>
</div></div>