<p dir="ltr">+1. One important consideration, however, and I would love to see some input from Chris Lattner or someone else who works on LLVM, is how much it would complicate the grammar of the language when all possible cases are considered. </p>
<br><div class="gmail_quote"><div dir="ltr">On Fri, Dec 18, 2015, 8:05 AM Matthew Johnson via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div><blockquote type="cite"><div>On Dec 18, 2015, at 6:52 AM, Al Skipp <<a href="mailto:al_skipp@fastmail.fm" target="_blank">al_skipp@fastmail.fm</a>> wrote:</div><br><div><div style="word-wrap:break-word"><blockquote type="cite">On 18 Dec 2015, at 03:27, Matthew Johnson via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br><br>Swift currently offers dot shorthand for static members of type Self in type contexts expecting a value of the type in question. This is most commonly used with enum cases.<br><br>Swift does not currently offer shorthand for instance members. Introducing a shorthand for instance members would improve clarity and readability of code in common cases:<br><br>anArray.map{$0.anInstanceMethod()}<br><br>becomes:<br><br>anArray.map(.anInstanceMethod())<br><br>This shorthand would work in typing contexts expecting a single argument function. It would allow abbreviated access to any visible instance property getter or instance method on the type of the argument. Of course the return type would need to match the return type expected by the context or a type mismatch compiler error would occur.<br><br>The readability advantage is arguably small but it does exist. The feature also aligns very well with an existing language feature.<br><br>I think it’s an interesting idea and am wondering whether others feel like it is something worth pursuing or not.<br><br>Matthew<br></blockquote><br><div>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><br></div><div>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><b>anArray.map(.anInstanceMethod())</b></div><div><br></div><div>I’m not sure many people would argue for it to be changed to:</div><div><b>anArray.map { $0.anInstanceMethod() }</b></div></div></div></blockquote><br></div></div><div style="word-wrap:break-word"><div>Thanks Al. 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><br></div><div>struct S {</div><div> var predicate: String -> Bool</div><div>}</div><div><br></div><div>var s = S()</div><div>s.predicate = { $0.hasPrefix(“abc”) }</div><div><br></div><div>vs</div><div>s.predicate = .hasPrefix(“abc”)</div><div><br></div><div>It’s not a super important change, but maybe a low-hanging fruit item that can improve clarity and readability.</div><div><br></div><div>Matthew</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=8CZIdLciSFC-2BO5jF-2FiP8qN7dBFsgCUZ50wdTsolcRPc0vDipCeQGbpQBbR7Waagu6AHKFL8gpEAhzWVGtlRUe-2FldGVvEGAeEdnV14XIOUkK1-2BpNeDKOpJ13ZQmnOQlUvb52RtlNf7foVdt8WFWNjEjNeXkq6PSlY64nTVyIswTkz3f3bJS4-2FJTBihP6aHcCPmCm9Qs3lmiqKhydUBjSas9qgTieGAVRZmB4aCVTj1OE-3D" alt="" width="1" height="1" border="0" 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">
</div>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>