<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="">Accidentally sent this offlist (why no 'reply to' header?)<br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class="">-thislooksfun (tlf)</div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Dec 28, 2016, at 9:52 AM, thislooksfun <<a href="mailto:thislooksfun@repbot.org" class="">thislooksfun@repbot.org</a>> 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="">This already basically exists in the form `inout`<div class=""><div dir="ltr" class=""><div class="markdown-here-wrapper"><pre class="" style="font-family: Consolas, Inconsolata, Courier, monospace; font-size: 1em; line-height: 1.2em; margin-top: 1.2em; margin-bottom: 1.2em;"><code class="language-swift hljs" style="font-size: 0.85em; font-family: Consolas, Inconsolata, Courier, monospace; margin: 0px 0.15em; overflow: auto; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 1px solid rgb(204, 204, 204); padding: 0.5em; color: rgb(51, 51, 51); background-color: rgb(248, 248, 248); display: block !important;">// Define the function
func position(x: inout Int, y: inout Int) {
x = 0
y = 0
}
// Create the variables you want to assign (they do have to be initialized beforehand)
var x = 0, y = 0
// And call it! Remember to prefix with & when using a primitive type (not 100% sure what kinds you don't need to specify that for, but the compiler will tell you).
position(x: &x, y: &y)</code></pre></div></div></div><div class=""><div class=""><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">There is no way to define a variable from the value passed to an `inout` parameter (it does need to go 'in' as well, after all), but other than that it seems to be what you're asking for.</div><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""></div><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">-thislooksfun (tlf)</div>
</div>
<div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 28, 2016, at 5:09 AM, Anton Zhilin via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important" class="">Some people on the list wondered, why we have moved from tuples in function parameters, but multiple returns are still implemented using tuples? The following code still compiles:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px" class=""><code class="language-swift hljs" style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248)"><span class="hljs-func"><span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">func</span> <span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold">position</span><span class="hljs-params">()</span> -> <span class="hljs-params">(x: Int, y: Int)</span> </span>{
<span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">return</span> (x: <span class="hljs-number" style="color:rgb(0,128,128)">0</span>, y: <span class="hljs-number" style="color:rgb(0,128,128)">0</span>)
}
<span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">let</span> (y, x) = position()
</code></pre><p style="margin:0px 0px 1.2em!important" class="">(Maybe it’s a bad example, because naturally we’d use <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">Point</code> struct. Let’s pretend those two parameters don’t make sense as a struct.)</p><p style="margin:0px 0px 1.2em!important" class="">What I want to discuss is if we should introduce <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">out</code> parameters <strong class="">and</strong> make them the default for multiple returns for Swift 4. The syntax would look like:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px" class=""><code class="language-swift hljs" style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important;display:block;overflow-x:auto;padding:0.5em;color:rgb(51,51,51);background:rgb(248,248,248)"><span class="hljs-func"><span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">func</span> <span class="hljs-title" style="color:rgb(153,0,0);font-weight:bold">position</span><span class="hljs-params">(x: out Int, y: out Int)</span> </span>{
x = <span class="hljs-number" style="color:rgb(0,128,128)">0</span>
y = <span class="hljs-number" style="color:rgb(0,128,128)">0</span>
}
<span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">var</span> y
position(x: <span class="hljs-keyword" style="color:rgb(51,51,51);font-weight:bold">let</span> x, y: y)
</code></pre><p style="margin:0px 0px 1.2em!important" class=""><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline" class="">out</code> arguments can be any patterns allowed on the left side of assignment, including wildcard pattern and tuple destructuring pattern.</p>
<div title="MDH:PGRpdj5Tb21lIHBlb3BsZSBvbiB0aGUgbGlzdCB3b25kZXJlZCwgd2h5IHdlIGhhdmUgbW92ZWQg
ZnJvbSB0dXBsZXMgaW4gZnVuY3Rpb24gcGFyYW1ldGVycywgYnV0IG11bHRpcGxlIHJldHVybnMg
YXJlIHN0aWxsIGltcGxlbWVudGVkIHVzaW5nIHR1cGxlcz8gVGhlIGZvbGxvd2luZyBjb2RlIHN0
aWxsIGNvbXBpbGVzOjxicj48L2Rpdj48ZGl2Pjxicj48L2Rpdj48ZGl2PmBgYHN3aWZ0PC9kaXY+
PGRpdj48ZGl2PmZ1bmMgcG9zaXRpb24oKSAtJmd0OyAoeDogSW50LCB5OiBJbnQpIHs8L2Rpdj48
ZGl2PiZuYnNwOyAmbmJzcDsgcmV0dXJuICh4OiAwLCB5OiAwKTwvZGl2PjxkaXY+fTwvZGl2Pjxk
aXY+PGJyPjwvZGl2PjxkaXY+bGV0ICh5LCB4KSA9IHBvc2l0aW9uKCk8L2Rpdj48L2Rpdj48ZGl2
PmBgYDwvZGl2PjxkaXY+PGJyPjwvZGl2PjxkaXY+KE1heWJlIGl0J3MgYSBiYWQgZXhhbXBsZSwg
YmVjYXVzZSBuYXR1cmFsbHkgd2UnZCB1c2UgYFBvaW50YCBzdHJ1Y3QuIExldCdzIHByZXRlbmQg
dGhvc2UgdHdvIHBhcmFtZXRlcnMgZG9uJ3QgbWFrZSBzZW5zZSBhcyBhIHN0cnVjdC4pPC9kaXY+
PGRpdj48YnI+PC9kaXY+PGRpdj5XaGF0IEkgd2FudCB0byBkaXNjdXNzIGlzIGlmIHdlIHNob3Vs
ZCBpbnRyb2R1Y2UgYG91dGAgcGFyYW1ldGVycyAqKmFuZCoqIG1ha2UgdGhlbSB0aGUgZGVmYXVs
dCBmb3IgbXVsdGlwbGUgcmV0dXJucyBmb3IgU3dpZnQgNC4gVGhlIHN5bnRheCB3b3VsZCBsb29r
IGxpa2U6PC9kaXY+PGRpdj48YnI+PC9kaXY+PGRpdj5gYGBzd2lmdDwvZGl2PjxkaXY+ZnVuYyBw
b3NpdGlvbih4OiBvdXQgSW50LCB5OiBvdXQgSW50KSB7PC9kaXY+PGRpdj4mbmJzcDsgJm5ic3A7
IHggPSAwPC9kaXY+PGRpdj4mbmJzcDsgJm5ic3A7IHkgPSAwPC9kaXY+PGRpdj59PC9kaXY+PGRp
dj48YnI+PC9kaXY+PGRpdj52YXIgeTwvZGl2PjxkaXY+cG9zaXRpb24oeDogbGV0IHgsIHk6IHkp
PC9kaXY+PGRpdj5gYGA8L2Rpdj48ZGl2Pjxicj48L2Rpdj48ZGl2PmBvdXRgIGFyZ3VtZW50cyBj
YW4gYmUgYW55IHBhdHRlcm5zIGFsbG93ZWQgb24gdGhlIGxlZnQgc2lkZSBvZiBhc3NpZ25tZW50
LCBpbmNsdWRpbmcgd2lsZGNhcmQgcGF0dGVybiBhbmQgdHVwbGUgZGVzdHJ1Y3R1cmluZyBwYXR0
ZXJuLjxicj48L2Rpdj4=" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0" class=""></div></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></div></blockquote></div><br class=""></body></html>