<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body><div>Feels like an abuse of subscripting IMHO. I'm fine with parametrized properties but the subscript doesn't quite fit in this case. <br><br>Sent from my Apple Watch</div><div><br>On Jul 11, 2016, at 23:24, David Hart 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">How about a proposal for named subscripts?<div class=""><br class=""></div><div class="">button.image[for: .normal] = image</div><div class=""><br class=""></div><div class="">defined using:</div><div class=""><br class=""></div><div class="">subscript image(for: UIControlState): UIImage? {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>get { … }<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>set { … }</div><div class="">}</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 12 Jul 2016, at 00:29, Tim Vermeulen 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=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 12 Jul 2016, at 00:20, Jacob Bandes-Storch <<a href="mailto:jtbandes@gmail.com" class="">jtbandes@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">When would you want to use this instead of something like `button[imageFor: .normal]` ?</div></div></blockquote><div class=""><br class=""></div><div class="">All the time, basically. Primarily because IMO it doesn’t really make sense to make “image” part of the argument label for the control state - we just have to (using subscripts) because subscripts themselves can’t be named. I think most people would agree that</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> image = </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">button</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">image</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">for</span><span style="font-variant-ligatures: no-common-ligatures" class="">: .</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">normal</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div></div><div class=""><br class=""></div><div class="">is more readable than</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> image = </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">button</span><span style="font-variant-ligatures: no-common-ligatures" class="">[imageFor: .normal]</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span style="font-family: Helvetica; font-size: 12px;" class="">and likewise, I would prefer</span></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span style="font-family: Helvetica; font-size: 12px;" class=""><br class=""></span></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">button</span>.image(<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">for</span>: .normal) = <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">image</span></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span style="font-family: Helvetica; font-size: 12px;" class=""><br class=""></span></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span style="font-family: Helvetica; font-size: 12px;" class="">over</span></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span style="font-family: Helvetica; font-size: 12px;" class=""><br class=""></span></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">button</span>[imageFor: .normal] = <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">image</span></span></div></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra">
<div class="gmail_quote">On Mon, Jul 11, 2016 at 3:00 PM, Tim Vermeulen via swift-evolution <span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></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="">Slightly related to this, I would really love to have non-subscript parameterized properties. It would allow us to write<div class=""><br class=""></div><div class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:#4f8187" class="">button</span><span class="">.image(</span><span style="color:#ba2da2" class="">for</span><span class="">: .normal) = </span><span style="color:#4f8187" class="">image</span></div></div><div class=""><br class=""></div><div class="">instead of</div><div class=""><br class=""></div><div class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)" class=""><span class="">button</span><span style="" class="">.</span><span style="color:#3e1e81" class="">setImage</span><span style="" class="">(</span><span class="">image</span><span style="" class="">, </span><span style="color:#ba2da2" class="">for</span><span style="" class="">: .</span><span style="color:#703daa" class="">normal</span><span style="" class="">)</span></div></div><div class=""><br class=""></div><div class="">The same can be achieved through subscripts, but it’s not always as nice. It would bring subscripts and computed properties closer together, which also seems to be the goal of your proposal. Perhaps the two ideas could be combined?<span class=""><br class=""><div class=""><br class=""></div><div class="">> Subscripts are a hybrid of properties and functions, since they have a parameter list, as well as getters and setters, so use of either symbol will be unusual in this case.<br class="">> <br class="">> However, I think a colon is more suitable, since it implies the possibility to set the value.<br class="">> <br class="">> <br class="">> In the future, if we add throwing getters/ setters:<br class="">> <br class="">> subscript(_ position: Int) ->Element {<br class="">> get {<br class="">> return …<br class="">> }<br class="">> throwing set {<br class="">> …<br class="">> }<br class="">> }<br class="">> <br class="">> Should this require ‘throws ->Element’? Using a colon also removes this potentially confusing case.<br class="">> <br class="">> <br class="">> Thoughts?<br class="">> <br class="">> <br class="">><span class=""> </span>
</div></span></div></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>
</div></blockquote></div><br class=""></div>_______________________________________________<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">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></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>