<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="">Sorry, the subscript part was responding to Jacob's comment of how ‘button[imageFor: .normal]’ could be used with current syntax.<div class=""><br class=""></div><div class="">I've just sent a pull request for this proposal, I mentioned exactly your suggestion in the ‘future directions’ section.</div><div class=""><br class=""><div class=""><a href="https://github.com/MutatingFunk/swift-evolution/blob/aa1fd53ec62b162f4cdefa9bd3845e13ac6f0d8d/proposals/NNNN-use-colons-for-subscript-type-declarations.md" class="">https://github.com/MutatingFunk/swift-evolution/blob/aa1fd53ec62b162f4cdefa9bd3845e13ac6f0d8d/proposals/NNNN-use-colons-for-subscript-type-declarations.md</a></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 12 Jul 2016, at 11:23, Tim Vermeulen <<a href="mailto:tvermeulen@me.com" class="">tvermeulen@me.com</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=""><div class="">I wasn’t suggesting named subscripts :) As you seem to have figured out, that gets confusing pretty quickly. Writing `self.items[0 ... 1]` seems a bit silly because the use of a subscript already implies items of some kind. So, to be clear, I was suggesting computed properties that allow parameters in round brackets, not in square brackets.</div><div class=""><br class=""></div><div class="">I agree that this might not make Swift 3, but your proposal already brings subscripts and computed properties closer together. What I’m suggesting is to make their declarations equivalent apart from `subscript` vs `var <variableName>`. As an example, this is what you’re proposing:</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="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> ArrayWrapper<Element> {</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><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> array: [</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Element</span><span style="font-variant-ligatures: no-common-ligatures" class="">]</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><br class="webkit-block-placeholder"></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><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">subscript</span><span style="font-variant-ligatures: no-common-ligatures" class="">(index: Int): Element {</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=""> get { </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> array[index] }</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=""> set { array[index] = newValue }</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></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></div></div><div class=""><br class=""></div><div class="">and my suggestion would allow this:</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 style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">ArrayWrapper</span><span style="font-variant-ligatures: no-common-ligatures;" 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><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> element(at index: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">): Element {</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=""> get { </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> array[</span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">index</span><span style="font-variant-ligatures: no-common-ligatures" 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=""> set { array[</span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">index</span><span style="font-variant-ligatures: no-common-ligatures" class="">] = newValue }</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></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></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><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="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> wrapper = </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">ArrayWrapper</span><span style="font-variant-ligatures: no-common-ligatures" class="">(array: [</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span><span style="font-variant-ligatures: no-common-ligatures" class="">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">2</span><span style="font-variant-ligatures: no-common-ligatures" class="">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">3</span><span style="font-variant-ligatures: no-common-ligatures" 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; color: #4f8187" class="">wrapper</span><span style="font-variant-ligatures: no-common-ligatures" class="">.element(at: </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span><span style="font-variant-ligatures: no-common-ligatures" class="">) = </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">5</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">wrapper</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures: no-common-ligatures" class="">array</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) </span><span style="font-variant-ligatures: no-common-ligatures; color: #008400" class="">// [1, 5, 3]</span></div></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 12 Jul 2016, at 11:24, James Froggatt <<a href="mailto:james.froggatt@me.com" class="">james.froggatt@me.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto" class=""><div class="">I like the idea of ‘named parameterised properties’, but I don't see it happening for Swift 3, which is unfortunate since it would tidy up quite a few APIs.</div><div class="">If this feature does get added, updating getter functions to them would be a non-breaking change, so maybe it would be possible to deprecate setImage(_:for:) and have a long trasition period.</div><div class=""><br class=""></div><div class="">The idea of using subscripts for this kind of property is interesting, but currently they don't show up in autocomplete, so working with labelled subscripts is tricky.</div><div class=""><br class=""></div><div class="">This does raise the question of where to draw the line with subscripts - should they only be used where the container itself is the base name of the ‘function’? But if this is the case:</div><div class=""><br class=""></div><div class="">self.items[0 ... 1] //good</div><div class=""><br class=""></div><div class="">self.item[0] //good</div><div class=""><br class=""></div><div class="">self.items[0] //bad, reads as ‘items 0’, not the grammatical term ‘item 0’</div><div class=""><br class=""></div><div class="">You could say we're already misusing them.</div><div class=""><br class="">On 11 Jul 2016, at 23:00, Tim Vermeulen <<a href="mailto:tvermeulen@me.com" class="">tvermeulen@me.com</a>> wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" 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="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">button</span><span style="font-variant-ligatures: no-common-ligatures" class="">.image(</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">for</span><span style="font-variant-ligatures: no-common-ligatures" class="">: .normal) = </span><span style="font-variant-ligatures: no-common-ligatures; 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 style="font-variant-ligatures: no-common-ligatures" class="">button</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">setImage</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" 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="">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?<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="Apple-converted-space"> </span>
</div></div></div></blockquote></div></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></div></div></body></html>