<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I really like this proposal, so its a +1 from me. It really clarifies that inout is implemented via an implicit reference type that wraps the original value. To make thinks more consistent, one could also think about adding generic reference types to the language (inout T then becomes syntactic sugar for Reference&lt;T&gt;), however, I am not sure that such an addition would be that valuable. But this proposal would certainly open up a path for introducing references, if deemed reasonable at some point.&nbsp;<div class=""><br class=""></div><div class="">— Taras<br class=""><div class=""><br class=""></div><div class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 30 Jan 2016, at 21:28, Patrick Gili via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">+1<div class=""><br class=""></div><div class="">This is very reasonable and clarifies usage.</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 29, 2016, at 2:37 PM, Erica Sadun via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><a href="https://github.com/apple/swift-evolution/pull/127" class="">https://github.com/apple/swift-evolution/pull/127</a><div class=""><br class=""></div><div class=""><h1 id="adjustinginoutdeclarationsfortypedecoration" style="margin: 0px 0px 0.875em; font-size: 1.5em; line-height: 0.875em; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Adjusting&nbsp;<code class="">inout</code>&nbsp;Declarations for Type Decoration</h1><ul style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 16px;" class=""><li style="font-size: 18px;" class="">Proposal: TBD</li><li style="font-size: 18px;" class="">Author(s):&nbsp;<a href="https://github.com/jckarter" style="color: rgb(13, 110, 161); text-decoration: none; transition: color 0.2s ease-in-out; -webkit-transition: color 0.2s ease-in-out;" class="">Joe Groff</a>,&nbsp;<a href="http://github.com/erica" style="color: rgb(13, 110, 161); text-decoration: none; transition: color 0.2s ease-in-out; -webkit-transition: color 0.2s ease-in-out;" class="">Erica Sadun</a></li><li style="font-size: 18px;" class="">Status: TBD</li><li style="font-size: 18px;" class="">Review manager: TBD</li></ul><h2 id="introduction" 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;" class="">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;" class="">The&nbsp;<code class="">inout</code>&nbsp;keyword indicates copy-in/copy-out argument behavior. In its current implementation<br class="">the keyword prepands argument names. We propose to move the&nbsp;<code class="">inout</code>&nbsp;keyword to the right<br class="">side of the colon to decorate the type instead of the parameter label.&nbsp;</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;" class=""><em class="">The initial Swift-Evolution discussion of this topic took place in the “Replace ‘inout’ with &amp;” thread.</em></p><h2 id="motivation" 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;" class="">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;" class="">In Swift 2, the&nbsp;<code class="">inout</code>&nbsp;parameter lives on the label side rather than the type side of the colon<br class="">although the keyword isn’t modifying the label but its type. Decorating<br class="">types instead of labels offers identifiable advantages:&nbsp;</p><ul style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 16px;" class=""><li style="font-size: 18px;" class=""><div style="word-wrap: break-word; line-height: 1.3125em; margin: 0px;" class="">It enables the&nbsp;<code class="">inout</code>&nbsp;keyword to properly integrate into full type syntax, for example:&nbsp;</div><pre class=""><code class="swift coffeescript hljs" 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 class="hljs-function"><span class="hljs-params" style="color: rgb(153, 0, 0); font-weight: bold;">(x: inout T)</span> -&gt;</span> U <span class="hljs-regexp" style="color: rgb(0, 153, 38);">//</span><span class="hljs-function"> =&gt;</span> <span class="hljs-function"><span class="hljs-params" style="color: rgb(153, 0, 0); font-weight: bold;">(inout T)</span> -&gt;</span> U</code></pre></li><li style="font-size: 18px;" class=""><div style="word-wrap: break-word; line-height: 1.3125em; margin: 0px;" class="">It avoids notational similarity with arguments labeled&nbsp;<code class="">inout</code>, for example:</div><pre class=""><code class="swift coffeescript hljs" 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 class="hljs-function"><span class="hljs-params" style="color: rgb(153, 0, 0); font-weight: bold;">(inOut x: T)</span> // <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params" style="color: rgb(153, 0, 0); font-weight: bold;">(inOut:)</span>, <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">type</span> <span class="hljs-params" style="color: rgb(153, 0, 0); font-weight: bold;">(T)</span> -&gt;</span> Void
func foo<span class="hljs-function"><span class="hljs-params" style="color: rgb(153, 0, 0); font-weight: bold;">(inout x: T)</span> // <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params" style="color: rgb(153, 0, 0); font-weight: bold;">(_:)</span>, <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">type</span> <span class="hljs-params" style="color: rgb(153, 0, 0); font-weight: bold;">(inout T)</span> -&gt;</span> Void</code></pre></li><li style="font-size: 18px;" class=""><div style="word-wrap: break-word; line-height: 1.3125em; margin: 0px;" class="">It better matches similar patterns in other languages such as borrowing in Rust, that may be later introduced back to Swift&nbsp;</div></li></ul><h2 id="detaileddesign" 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;" class="">Detailed design</h2><pre style="color: rgb(17, 17, 17); font-size: 16px;" class=""><code class=" lasso hljs" 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 class="hljs-attribute" style="color: rgb(0, 128, 128);">-parameter</span><span class="hljs-attribute" style="color: rgb(0, 128, 128);">-name</span> optlocal<span class="hljs-attribute" style="color: rgb(0, 128, 128);">-parameter</span><span class="hljs-attribute" style="color: rgb(0, 128, 128);">-name</span> : <span class="hljs-keyword" style="font-weight: bold;">type</span><span class="hljs-attribute" style="color: rgb(0, 128, 128);">-annotation</span>
<span class="hljs-keyword" style="font-weight: bold;">type</span><span class="hljs-attribute" style="color: rgb(0, 128, 128);">-annotation</span> → inout <span class="hljs-keyword" style="font-weight: bold;">type</span><span class="hljs-attribute" style="color: rgb(0, 128, 128);">-annotation</span></code></pre><h2 id="alternativesconsidered" 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;" class="">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;" class="">Decorations using&nbsp;<code class="">@inout</code>&nbsp;(either&nbsp;<code class="">@inout(T)</code>&nbsp;or&nbsp;<code class="">@inout T</code>) were considered and discarded</p></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></div></div></body></html>