<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 11, 2016, at 7:53 PM, Chris Lattner <<a href="mailto:clattner@apple.com" class="">clattner@apple.com</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="">On Jan 10, 2016, at 7:44 PM, Matthew Johnson via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><div class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><h2 id="proposedsolution" style="color: rgb(17, 17, 17); font-size: 27px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Proposed solution</h2><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">The proposed solution is to introduce an automatic parameter forwarding mechansim. It allows users to provide direct arguments for some parameters while forwarding others.</p><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">The basic mechanism looks like this:</p><pre style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);" class=""><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">(i i: Int, s: String, f: Float = <span class="hljs-number" style="color: rgb(0, 153, 153);">42</span>, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>, b: Bool = <span class="hljs-literal">false</span>)</span></span> { }
<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// user writes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">(...fooParams)</span></span> {
foo(i: <span class="hljs-number" style="color: rgb(0, 153, 153);">32</span>, ...fooParams)
}
<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// compiler synthesizes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">(s: String, f: Float = <span class="hljs-number" style="color: rgb(0, 153, 153);">42</span>, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>, b: Bool = <span class="hljs-literal">false</span>)</span></span> {
foo(i: <span class="hljs-number" style="color: rgb(0, 153, 153);">32</span>, s: s, f: f, d: d, b: b)
}</code></pre></div></div></div></blockquote>This approach is extremely problematic and unlikely to be accepted.</div></div></div></blockquote><div><br class=""></div>Ok, I won’t pursue it further in that case. Thanks for calling that out before I spent any further time on it.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">Swift is carefully designed so that the compiler can type check the interface to a function without type checking its body. This is important for compiler scalability to large projects, IDE tooling, and also because otherwise you can run into circular dependencies to compile the code.</div></div></div></blockquote><div><br class=""></div><div>Good to know.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">Another major problem with this approach is that it only works if “foo” is unambiguous.</div></div></div></blockquote><div><br class=""></div><div>I addressed the fact that the call to foo must be unambiguous further down in the proposal. Did I miss something important? (Not that it matters if this approach is a dead end)</div><div><br class=""></div><div>Do you have any ideas for a better direction that could handle forwarding of default parameter values and / or a subset of parameters? Or is tuple packing and unpacking the best we can hope for?</div><div><br class=""></div><div>Matthew</div><div><br class=""></div></div></body></html>