<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Seems sensible; here's my $0.02:</div><div><br></div><div>I don't know whether that kind of thing has been proposed, but it would be interesting to explore two different language features and their interaction with first-class getters and setters. This way, I believe, we could avoid introducing non-orthogonality and special cases into the language.</div><div><br></div><div>The first feature is <span style="background-color: rgba(255, 255, 255, 0);">uniform function call syntax:</span></div><div> - for structs and final classes (where there's no inheritance), if a function is declared with the struct type as its first parameter, e.g. some_property(self: MyStruct) {…}, it could be called as if it was a method on the struct (cf. Go's behavior). With this behavior would be consistent the ability to simply map getters and setters over a collection of structs (or otherwise treat technically free functions as methods if the types match).</div><div> - for non-final classes, inheritance kicks in. In this case, I think it's a little too magical (albeit certainly not hard to implement) to have one function name map to several functions (i.e. have inheritance semantics), especially without visual indication of the object being manipulated. There's a source of mental tension here, though: specifically, this behavior would however be consistent with the notion of overridden functions at the same time.</div><div><br></div><div>The second feature is macros - I know that they have been discussed and postponed for now, but theoretically they'd be capable of solving the kinds of syntactic repetition that can't otherwise be refactored into functions. The standard library could then contain macros which would expand to appropriate getters and setters - pseudocode follows:</div><div><br></div><div> macro get(name: Identifier) {</div><div> return { $0.`name` }</div><div> }</div><div><br></div><div> macro set(name: Identifier) {</div><div> return { $0.`name` = $1 }</div><div> }</div><div><br></div><div>What do you think about this?</div><div><br><div>Sent from my iPhone</div></div><div><br>On 28 Dec 2015, at 18:10, Thorsten Seitz via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div></div><div>+1 for being able to use <span style="background-color: rgba(255, 255, 255, 0);"><span class="">cars</span><span class="">.</span><span class="">map</span><span class="">(</span><span class="">make)</span></span></div><div><br>Am 16.12.2015 um 16:23 schrieb Al Skipp via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><div><blockquote type="cite" class=""><div class="">On 16 Dec 2015, at 12:47, Sean Kosanovich via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">As a Groovy user, I really enjoy the shorthand Spread Operator over the Collect Closure (Map is the equivalent in Swift).</span><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Consider the following Swift code:</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">struct</span><span class="Apple-converted-space"> </span>Car {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(187, 44, 162);">let</span><span class="Apple-converted-space"> </span>make:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(112, 61, 170);">String</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(187, 44, 162);">let</span><span class="Apple-converted-space"> </span>model:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(112, 61, 170);">String</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">let</span><span class="Apple-converted-space"> </span>cars = [<span class="" style="color: rgb(79, 129, 135);">Car</span>(make:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"Jeep"</span>, model:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"Grand Cherokee"</span>),<span class="Apple-converted-space"> </span><span class="" style="color: rgb(79, 129, 135);">Car</span>(make:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"Dodge"</span>, model:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"Challenger"</span>)]</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">let</span><span class="Apple-converted-space"> </span>makes =<span class="Apple-converted-space"> </span><span class="" style="color: rgb(79, 129, 135);">cars</span>.<span class="" style="color: rgb(61, 29, 129);">map</span>() { $0.<span class="" style="color: rgb(79, 129, 135);">make</span><span class="Apple-converted-space"> </span>}</div></div><div class="" style="font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px; font-size: 11px; font-family: Menlo;"><br class=""></div><div class="" style="font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px; font-size: 11px; font-family: Menlo;"> </div><div class="" style="font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px; font-size: 11px; font-family: Menlo;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="">Now consider the same code using a Spread Operator:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">let</span><span class="Apple-converted-space"> </span>makes =<span class="Apple-converted-space"> </span><span class="" style="color: rgb(79, 129, 135);">cars</span>*.make</div></div></div></div></blockquote></div><br class=""><div class="">I think there is a tension in Swift between its object oriented nature and higher-order functions which leads to a lot of repetition of { $0.property }</div><div class=""><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);"><br class=""></span></div><div class="">In this example:</div><div class=""><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);">cars</span><span style="font-family: Menlo; font-size: 11px;" class="">.</span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(61, 29, 129);">map</span><span style="font-family: Menlo; font-size: 11px;" class=""> { $0.</span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);">make</span><span style="font-family: Menlo; font-size: 11px;" class=""> }</span></div><div class=""><span style="font-family: Menlo; font-size: 11px;" class=""><br class=""></span></div><div class=""><div class="">I’d like to write the following, but ‘make’ is a member, not a free function:</div></div><div class=""><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);">cars</span><span style="font-family: Menlo; font-size: 11px;" class="">.</span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(61, 29, 129);">map</span><span class="" style="font-family: Menlo; font-size: 11px;">(</span><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);">make)</span></div><div class=""><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);"><br class=""></span></div><div class="">Is anyone else irked by the preponderance of { $0.property } in Swift (or is it just me being grumpy)? Not sure what the solution would be, but I can’t say I’m keen on the suggestion of:</div><div class=""><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);"><br class=""></span></div><div class=""><span class="" style="font-family: Menlo; font-size: 11px; color: rgb(79, 129, 135);">cars</span><span style="font-family: Menlo; font-size: 11px;" class="">*.make</span></div><div class=""><br class=""></div><div class="">It’s too mysterious.</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=1MXK54sosN3xru3iYcLt0oBZ2w20i49gyogXctgrspcJllYkMx2zN7jpkwwYKNnXX-2Bn4Zop4fyUSq-2BmcR1-2BstADLmxRTvdGJnYSdqjrHMuJPQSWvTkpp-2Fbabszc3XxeXOZe2TCHGOWaxQqjAz6K1bR-2BbpjgmAQO-2FWx4CP7hGaV82qcpm4KWYgAZdhh4NQibFDb31SeddZPTjuJHU4V7yYkDZSOV6X3-2FyH07kLksysLk-3D" alt="" width="1" height="1" border="0" style="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></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=3X4jBaRMJYTgQaTXt-2FL0X83k5h3WwaDWbCmwjXS4P8Fa4SOkX7tnpNIJKf64TMva0noORZJy9Go2a6gn6tWYADTVvoz9XEtvlZAbZaBKDZllK9xy1jt9lQS6aDauJ8rry-2FF9cNseaZWpAr6P7YMPTsaSEEcCrujW0kMTrdiUvR0wS2-2BhyxFiiR8V6b-2FIUiSiQtBYUh-2FL5MHQdmEra-2Fxm2mhcMmZtYWHp7a2BVJuDNsY-3D" alt="" width="1" height="1" border="0" style="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></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>