<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 20, 2016, at 8:57 AM, Jordan Rose 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 style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; 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;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Jan 19, 2016, at 20:35 , John McCall 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 class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; 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;"><blockquote type="cite" class=""><div class="">On Jan 19, 2016, at 7:20 PM, Paul Cantrell 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 class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Surprisingly, this code does not compile:<div class=""><br class=""></div><div class=""><div class=""><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal;"><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal;"> <span class="" style="color: rgb(50, 62, 125);">func</span><span class="Apple-converted-space"> </span>foo(val:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(88, 126, 168);">Int</span>) { }</div><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal; min-height: 12px;"><br class=""></div><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal;"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(50, 62, 125);">func</span><span class="Apple-converted-space"> </span>bar(closure: (<span class="" style="color: rgb(88, 126, 168);">Int</span>,<span class="" style="color: rgb(88, 126, 168);">Int</span>) -><span class="Apple-converted-space"> </span><span class="" style="color: rgb(88, 126, 168);">Void</span>) {</div><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal;"> closure(<span class="" style="color: rgb(50, 62, 125);">0</span>,<span class="Apple-converted-space"> </span><span class="" style="color: rgb(50, 62, 125);">1</span>)</div><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal;"> }</div><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal; min-height: 12px;"><br class=""></div><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal;"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(88, 126, 168);">bar</span><span class="Apple-converted-space"> </span>{<span class="Apple-converted-space"> </span><span class="" style="color: rgb(88, 126, 168);">foo</span>($0) } <span class="Apple-converted-space"> </span><span class="" style="color: rgb(102, 139, 73);">// compiler error</span></div><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal;"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(88, 126, 168);">bar</span><span class="Apple-converted-space"> </span>{<span class="Apple-converted-space"> </span><span class="" style="color: rgb(88, 126, 168);">foo</span>($1) } <span class="Apple-converted-space"> </span><span class="" style="color: rgb(102, 139, 73);">// just dandy</span></div><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal;"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(88, 126, 168);">bar</span><span class="Apple-converted-space"> </span>{<span class="Apple-converted-space"> </span><span class="" style="color: rgb(88, 126, 168);">foo</span>($0 + $1) } <span class="Apple-converted-space"> </span><span class="" style="color: rgb(102, 139, 73);">// also works</span></div><div class=""><span class="" style="color: rgb(102, 139, 73);"><br class=""></span></div></div></div></div><div class="">The compiler error is:</div><div class=""><br class=""></div><div class=""> Cannot convert value of type (Int, Int) to expected argument type Int</div></div><div class=""><br class=""></div><div class="">It appears that the meaning of <span class="" style="font-family: Menlo; font-size: 11px;">$0</span> is overloaded: it can refer either to the tuple of all arguments, or to just the first argument. The presence of another placeholder variable (<span class="" style="font-family: Menlo; font-size: 11px;">$1</span> in the third example) seems to trigger the latter behavior.</div></div></div></blockquote><div class=""><br class=""></div>It’s dumber than that. The type-checker assumes that the closure has a tuple of arguments ($0, $1, …, $N), where $N is the largest N seen in the closure. Thus, a two-argument closure falls down if you ignore the second argument. It’s dumb, and we’ve known about it for a long time; and yet it’s been remarkably annoying to fix, and so we haven’t yet.</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; 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;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; 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;">Anyway, it’s a bug and doesn’t need to go through evolution.</div></div></blockquote><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; 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;" class="">I wouldn't go as far as to say it's a bug. It's known and occasionally useful for forwarding arguments. (For a while I had it as a fix-it for doing function representation conversions.)</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; 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;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; 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;" class="">I agree that having it always be the first argument is less surprising and probably more generally useful, though.</div></div></blockquote><br class=""></div><div>In the spirit of the Great Argument Simplification to distinguish arguments from tuples, we probably ought to introduce a separate '$*'-like sigil to bind "all arguments" distinct from $0.</div><div><br class=""></div><div>-Joe</div><br class=""></body></html>