<div dir="ltr">Note that I got this idea while thinking about Erica's proposal to move the inout keyword to the type position in declarations. If that is accepted, the difference between the inout locations would be eliminated. So you examples would then be:<div><br></div><font face="monospace, monospace">func add(number n: inout Int)<br>add(number: inout n)<br><br>func </font><span style="font-family:monospace,monospace">getUserData(id id: Int, name: inout String, gid: inout Int, shell: inout String)</span><font face="monospace, monospace"><br>getUserData(id: userid, name: inout username, gid: inout groupid, shell: inout shell)</font></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 29, 2016 at 10:57 PM, Dany St-Amant 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"><span class=""><br><div><blockquote type="cite"><div>Le 29 janv. 2016 à 17:44, Trent Nadeau via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> a écrit :</div><br><div><div dir="ltr"><a href="https://github.com/tanadeau/swift-evolution/blob/master/proposals/00xx-use-inout-at-func-call-site.md" target="_blank">https://github.com/tanadeau/swift-evolution/blob/master/proposals/00xx-use-inout-at-func-call-site.md</a><div><br></div><div><pre># Use `inout` at Function Call Sites
* Proposal: TBD
* Author(s): [Trent Nadeau](<a href="http://github.com/tanadeau" target="_blank">http://github.com/tanadeau</a>)
* Status: TBD
* Review manager: TBD
## Introduction
Currently when a function has `inout` parameters, the arguments are passed with the `&` prefix operator. For example:
```swift
func add1(inout num: Int) {
num += 1
}
var n = 5
add1(&n) // n is now 6
```
This operator does not fit with the rest of the language nor how the parameter is written at the function declaration. It should be replaced so that `inout` is used in both locations so that the call site above would instead be written as:
```swift
add1(inout n) // symmetric and now obvious that n can change
</pre></div></div></div></blockquote></div><div><br></div></span><div>inout vs & doesn’t look that ugly in a simple single argument function, but what if you have many:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">getUserData(userid, &username, &groupid, &shell) <span style="color:rgb(0,132,0)">// Current syntax</span></div></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">getUserData(userid, <span style="color:#bb2ca2">inout</span> username, <span style="color:#bb2ca2">inout</span> groupid, <span style="color:#bb2ca2">inout</span> shell) <span style="color:rgb(0,132,0)">// Proposal</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br></div></div><div>Yes, for the above one should use something better ( userData=getUserData(userid) ). But, I’m sure there are valid scenario where one wants multiple inout parameters. And such an example must be provided to visualize the impact of moving from & to inout.</div><div><br></div><div>Just realizing that the above syntax is without label, even the proposal doesn’t show the use of the inout with labels…</div><div>So the current proposal changes:</div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#31595d">add</span>(number: &<span style="color:#4f8187">n</span>)</div><div>to</div><div><div style="margin:0px;line-height:normal"><div style="font-family:Menlo;font-size:11px;margin:0px;line-height:normal;color:rgb(0,132,0)"><span style="color:#31595d">add</span><span style="color:#000000">(</span><span style="color:#bb2ca2">inout</span><span style="color:#000000"> number: n) </span>// Perfect symmetry</div><div style="font-family:Menlo;font-size:11px;margin:0px;line-height:normal;color:rgb(0,132,0)"><span style="color:#31595d">add</span><span style="color:#000000">(number: </span><span style="color:#bb2ca2">inout</span><span style="color:#000000"> n) </span>// Matching token location</div><div style="font-family:Menlo;font-size:11px"><br></div><div><span style="font-family:Helvetica;font-size:12px">So with my bad example from above </span>changing:</div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">getUserData(id: userid, name: &username, gid: &groupid, shell: &shell)</div></div><div>to:</div></div></div></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">getUserData(id: userid, <span style="color:#bb2ca2">inout</span> name: username, <span style="color:#bb2ca2">inout</span> gid: groupid, <span style="color:#bb2ca2">inout</span> shell: shell)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">getUserData(id: userid, name: <span style="color:#bb2ca2">inout</span> username, gid: <span style="color:#bb2ca2">inout</span> groupid, shell: <span style="color:#bb2ca2">inout</span> shell)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br></div></div><div><div>That’s a lot of word, syntax highlighting does help a bit but I do not want to rely on it.</div><div><br></div><div>Dany</div><div></div></div></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><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Trent Nadeau</div>
</div>