<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 23 Feb 2017, at 12:49, Vladimir.S <<a href="mailto:svabox@gmail.com" class="">svabox@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">On 23.02.2017 14:17, Haravikk wrote:<br class=""><blockquote type="cite" class=""><br class=""><blockquote type="cite" class="">On 22 Feb 2017, at 21:25, Patrick Pijnappel <<a href="mailto:patrickpijnappel@gmail.com" class="">patrickpijnappel@gmail.com</a><br class=""><<a href="mailto:patrickpijnappel@gmail.com" class="">mailto:patrickpijnappel@gmail.com</a>>> wrote:<br class=""><br class="">To summarize, there's one ambiguous case we'd need to resolve:<br class=""><br class="">func foo(_ x: Int, reportingOverflow)<br class="">func foo(_ x: Int, _ reportingOverflow: Bool)<br class=""><br class="">let reportingOverflow = true<br class="">foo(5, reportingOverflow) // Ambiguous<br class=""><br class="">One solution is to make trailing argument labels syntactic sugar for a<br class="">trailing void argument.<br class="">That would allow breaking ambiguity by specifying it explicitly:<br class=""><br class="">foo(5, reportingOverflow: ())<br class=""><br class="">A related issue is the call-site ambiguity for the reader (less of a<br class="">problem if Xcode highlighted argument labels).<br class=""></blockquote><br class="">Vladimir suggested that an alternative might be to use a leading colon to<br class=""></blockquote><br class="">There is another alternative I can think of, based on feature that was discussed at some point of time the list: anonymous enums, i.e. when you can declare enum inside function declaration, when such enum has almost no meaning outside of the function call.<br class=""><br class="">I.e. something like this:<br class=""><br class="">func foo(_ x: Int, with: (.reportingOverflow))<br class=""><br class="">foo(10, with:.reportingOverflow)<br class=""><br class="">I.e. you can have more than one enum case here if you want:<br class="">func foo(_ x: Int, with: (.reportingOverflow, .otherFlag))<br class="">// IIRC, such syntax was discussed:<br class="">// func foo(_ x: Int, with: (.reportingOverflow | .otherFlag))<br class=""><br class="">foo(10, with:.otherFlag)<br class=""><br class="">But such anonymous enums were considered as bad idea during the discussion, so…</div></div></blockquote><br class=""></div><div>Yeah, I was one of the ones who liked the idea but it never seemed to get much traction unfortunately.</div><div><br class=""></div><div>Part of the problem though with using enums to select methods is that it's not immediately obvious what they're doing; if you look at the signature for a method you see a type, then have to investigate what it is and find it only has one case, which is confusing. Documentation then needs to fill in all the gaps to explain that it will only ever have one case (e.g- it's not an enum that may be expanded with more options in future), and that's it's for selecting methods. A single-case ad-hoc enum could be a bit clearer, but it's still more of a workaround.</div><div><br class=""></div><div>I think having a proper language feature is still the way to go, as it can be more obvious at the function declaration that it's something different, since it would be an untyped parameter.</div><div><div class=""><br class=""></div><div class="">You mentioned another possibility of putting the extra label after the function, and I've been thinking about that as well, because the interesting thing about that is it could be thought of as a kind of label on the return type.</div><div class=""><br class=""></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func adding(_ other:Self) -> Self</font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func adding(_ other:Self):reportingOverflow -> (Self, Bool)</font></div><div class=""><font face="Monaco" class=""><br class=""></font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let resultOnly = a.adding(b)</font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let resultReportingOverflow = a.adding(b):reportingOverflow</font></div><div class=""><br class=""></div><div class="">You did say it looks a bit like an operation on the result, but I suppose another way of thinking about it is that until you set (or omit) :reportingOverflow then you're actually calling *both* methods with two possible results, and by adding that you tell Swift which one you want. It could be a very neat thing to use as well within modern auto-complete; type out the method at which point you can either hit space to move onto something else, hit period to call a method on the result, or hit colon to narrow down the result to something more specific.</div><div class=""><br class=""></div><div class="">Ack, I think I'm confusing myself now as to which solution I prefer. Having the trailing label *after* the function call does have merits as well.</div></div></body></html>