<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 Feb 22, 2017, at 10:16 AM, Nate Cook 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=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hello all,<div class=""><br class=""></div><div class="">I was surprised to find that I can't use an instance member as the default value of a method parameter, only constants and the run-time calculated #file, #line, etc. Is it possible to remove this limitation?</div><div class=""><br class=""></div><div class="">I'd like to propose that we add an overload of the collection <font face="Menlo" class="">index(_:offsetBy:)</font> methods that use the collection's <font face="Menlo" class="">startIndex </font>as a default parameter, but we can't provide that without either this feature or an extra overload. If the declaration looks like this:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">extension Collection {</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; func index(_ i: Index = startIndex, offsetBy n: IndexDistance) -&gt; Index {</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp; // ...</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; }</font></div><div class=""><font face="Menlo" class="">}</font></div><div class=""><br class=""></div><div class="">then calling that method with an omitted first parameter would treat it as something like this:</div><div class=""><br class=""></div><div class=""><div class=""><font face="Menlo" class="">extension Collection {</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; func index(offsetBy&nbsp;</font><span style="font-family: Menlo;" class="">n: IndexDistance</span><font face="Menlo" class="">) -&gt; Index {<span class="Apple-tab-span" style="white-space:pre">        </span></font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp; let i = startIndex</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp; // ...</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; }</font></div><div class=""><font face="Menlo" class="">}</font></div></div><div class=""><br class=""></div><div class="">Is this just syntactic sugar, or am I missing something that makes this harder than it looks? I can see how more complex expressions could be useful there, too, and can't find an obvious reason we couldn't use any code that could be inserted at the top of the method body.</div></div></div></blockquote><br class=""></div><div>+1, I didn’t realize we couldn’t do that now.</div><br class=""><div class="">- Dave Sweeris</div></body></html>