<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="">Johan, you are right that all of this is possible but it seems rather verbose to me. &nbsp;I’d rather use the currently possible { $0.member } syntax. &nbsp;The point of the idea is to <i class="">remove </i>syntactic noise. &nbsp;<div class=""><br class=""></div><div class="">It’s reasonable to argue that this isn’t necessary, but in that case the current state suffices IMO. &nbsp;We don’t need a <i class="">more</i>&nbsp;verbose alternative to what we already have.<div class=""><div class=""><div class=""><br class=""></div><div class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 18, 2015, at 9:00 AM, Johan Jensen &lt;<a href="mailto:jj@johanjensen.dk" class="">jj@johanjensen.dk</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">I’m not very fond of having just a single dot in front of the method call, as it could easily be missed.<br class="">In the case of <span style="font-family:monospace,monospace" class="">s.predicate = .hasPrefix("abc")</span><span style="font-family:arial,helvetica,sans-serif" class="">, I would prefer something slightly more expressive.<br class=""><br class=""></span></div><div class=""><span style="font-family:arial,helvetica,sans-serif" class="">As it is right now in Swift, accessing methods directly gives you a curried function back, which expects the object instance as argument in the first call, and the rest in the second call.<br class=""></span></div><div class=""><span style="font-family:arial,helvetica,sans-serif" class="">E.g. <span style="font-family:monospace,monospace" class="">String.hasPrefix("abcd")("a")</span> is the same as <span style="font-family:monospace,monospace" class="">"abcd".hasPrefix("a")<br class=""></span><br class=""></span></div><div class=""><span style="font-family:arial,helvetica,sans-serif" class="">Flipping the arguments like this:<br class=""><span style="font-family:monospace,monospace" class="">func flip&lt;A, B, C&gt;(f: A -&gt; B -&gt; C) -&gt; (B -&gt; A -&gt; C) {<br class="">&nbsp;&nbsp;&nbsp; return { valB in<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return { valA in<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return f(valA)(valB)<br class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br class="">&nbsp;&nbsp;&nbsp; }<br class="">}<br class=""><br class="">String.hasPrefix("abcd")("a")<br class="">let myHasPrefix = flip(String.hasPrefix)<br class="">myHasPrefix("a")("abcd")</span><br class=""><br class=""></span></div><div class=""><span style="font-family:arial,helvetica,sans-serif" class="">…would allow us to write the following:<br class=""></span></div><div class=""><span style="font-family:arial,helvetica,sans-serif" class=""><span style="font-family:monospace,monospace" class="">s.predicate = flip(String.hasPrefix("abcd"))</span><br class=""><br class=""></span></div><div class=""><span style="font-family:arial,helvetica,sans-serif" class="">Perhaps it could be extended to</span> something akin to<br class=""><span style="font-family:arial,helvetica,sans-serif" class=""><span style="font-family:monospace,monospace" class="">s.predicate = String::hasPrefix("abcd")</span><br class=""><br class=""></span></div><div class=""><span style="font-family:arial,helvetica,sans-serif" class="">The currying only works for methods and not for properties, so this isn’</span><span style="font-family:arial,helvetica,sans-serif" class=""><span style="font-family:arial,helvetica,sans-serif" class="">t currently possible to express like the above:<br class=""></span><span style="font-family:monospace,monospace" class="">["John", "Rachel", "Thomas"].map({ $0.endIndex })<br class=""></span></span></div><div class=""><span style="font-family:arial,helvetica,sans-serif" class=""><span style="font-family:monospace,monospace" class="">["John", "Rachel", "Thomas"].map({ $0.characters.count })</span><br class=""></span></div><div class=""><span style="font-family:arial,helvetica,sans-serif" class=""><br class="">—Johan</span></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Dec 18, 2015 at 2:05 PM, Matthew Johnson via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><span class=""><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="">On Dec 18, 2015, at 6:52 AM, Al Skipp &lt;<a href="mailto:al_skipp@fastmail.fm" target="_blank" class="">al_skipp@fastmail.fm</a>&gt; wrote:</div><br class=""><div class=""><div style="word-wrap:break-word" class=""><blockquote type="cite" class="">On 18 Dec 2015, at 03:27, Matthew Johnson via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">Swift currently offers dot shorthand for static members of type Self in type contexts expecting a value of the type in question.&nbsp; This is&nbsp;most commonly used with enum cases.<br class=""><br class="">Swift does not currently offer shorthand for instance members.&nbsp; Introducing a shorthand for instance members would improve clarity&nbsp;and readability of code in common cases:<br class=""><br class="">anArray.map{$0.anInstanceMethod()}<br class=""><br class="">becomes:<br class=""><br class="">anArray.map(.anInstanceMethod())<br class=""><br class="">This shorthand would work in typing contexts expecting a single argument function.&nbsp; It would allow abbreviated access to any visible&nbsp;instance property getter or instance method on the type of the argument.&nbsp; Of course the return type would need to match the return&nbsp;type expected by the context or a type mismatch compiler error would occur.<br class=""><br class="">The readability advantage is arguably small but it does exist.&nbsp; The feature also aligns very well with an existing language feature.<br class=""><br class="">I think it’s an interesting idea and am wondering whether others feel like it is something worth pursuing or not.<br class=""><br class="">Matthew<br class=""></blockquote><br class=""><div class="">I’d be interested to hear peoples thoughts regarding this proposal. I’m personally in favour, but perhaps there are potential issues with the suggestion?</div><div class=""><br class=""></div><div class="">It’s only a small visual change, but I think it is a syntactic improvement. Let’s pretend for a moment that the current syntax was:</div><div class=""><b class="">anArray.map(.anInstanceMethod())</b></div><div class=""><br class=""></div><div class="">I’m not sure many people would argue for it to be changed to:</div><div class=""><b class="">anArray.map { $0.anInstanceMethod() }</b></div></div></div></blockquote><br class=""></div></span><div class="">Thanks Al.&nbsp; I should have also pointed out that the syntactic advantage is a bit greater in other contexts where the braces would not replace parentheses:</div><div class=""><br class=""></div><div class="">struct S {</div><div class="">&nbsp; var predicate: String -&gt; Bool</div><div class="">}</div><div class=""><br class=""></div><div class="">var s = S()</div><div class="">s.predicate = { $0.hasPrefix(“abc”) }</div><div class=""><br class=""></div><div class="">vs</div><div class="">s.predicate = .hasPrefix(“abc”)</div><div class=""><br class=""></div><div class="">It’s not a super important change, but maybe a low-hanging fruit item that can improve clarity and readability.</div><div class=""><br class=""></div><div class="">Matthew</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=KlmFWKNIEcyPEGx2Wqruu-2FaM6I0anrxIOlKS1pgqec6F7LvfJew-2Fo6U081v3n-2FR2FQkjWpV8RL-2BOE0SZ3QTBBEXDnp2G9qJs5qIft2kg8JAR4NY1YBTircPXUfaidVJ1K-2BpB3KWxb-2BOZiGMewFvh4M5X-2FR2BOTegh5OfrPOZhA1h9ZIYEKgp1YCKsRNmFGIyo-2BeQE34U10WQmNTD5O-2BZOvjjj3POAoqxnAghYaHfacA-3D" alt="" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important" height="1" border="0" width="1" class="">
</div>
<br class="">_______________________________________________<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" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></div></div></div></div></body></html>