Re: [swift-evolution] Change subscripts to use colons

2016-07-12 Thread James Froggatt via swift-evolution
Sorry, the subscript part was responding to Jacob's comment of how ‘button[imageFor: .normal]’ could be used with current syntax. I've just sent a pull request for this proposal, I mentioned exactly your suggestion in the ‘future directions’ section. https://github.com/MutatingFunk/swift-evolut

Re: [swift-evolution] Change subscripts to use colons

2016-07-12 Thread James Froggatt via swift-evolution
Submitted! Pull request: https://github.com/apple/swift-evolution/pull/423 Proposal doc: https://github.com/MutatingFunk/swift-evolution/blob/aa1fd53ec62b162f4cdefa9bd3845e13ac6f0d8d/proposals/-use-colons-for-subscript-type-declarations.md

Re: [swift-evolution] Change subscripts to use colons

2016-07-12 Thread Tim Vermeulen via swift-evolution
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 paramet

Re: [swift-evolution] Change subscripts to use colons

2016-07-12 Thread James Froggatt via swift-evolution
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. If this feature does get added, updating getter functions to them would be a non-breaking change, so maybe it would be possible to deprecat

Re: [swift-evolution] Change subscripts to use colons

2016-07-11 Thread Tim Vermeulen via swift-evolution
Then it kinda looks like your subscripting a property called `image`, doesn’t it? > On 12 Jul 2016, at 08:24, David Hart wrote: > > How about a proposal for named subscripts? > > button.image[for: .normal] = image > > defined using: > > subscript image(for: UIControlState): UIImage? { >

Re: [swift-evolution] Change subscripts to use colons

2016-07-11 Thread Saagar Jha via swift-evolution
Feels like an abuse of subscripting IMHO. I'm fine with parametrized properties but the subscript doesn't quite fit in this case. Sent from my Apple Watch On Jul 11, 2016, at 23:24, David Hart via swift-evolution wrote: > How about a proposal for named subscripts? > > button.image[for: .nor

Re: [swift-evolution] Change subscripts to use colons

2016-07-11 Thread David Hart via swift-evolution
How about a proposal for named subscripts? button.image[for: .normal] = image defined using: subscript image(for: UIControlState): UIImage? { get { … } set { … } } > On 12 Jul 2016, at 00:29, Tim Vermeulen via swift-evolution > wrote: > > >> On 12 Jul 2016, at 00:20, Jacob B

Re: [swift-evolution] Change subscripts to use colons

2016-07-11 Thread Tim Vermeulen via swift-evolution
> On 12 Jul 2016, at 00:20, Jacob Bandes-Storch wrote: > > When would you want to use this instead of something like `button[imageFor: > .normal]` ? 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 - w

Re: [swift-evolution] Change subscripts to use colons

2016-07-11 Thread Jacob Bandes-Storch via swift-evolution
When would you want to use this instead of something like `button[imageFor: .normal]` ? On Mon, Jul 11, 2016 at 3:00 PM, Tim Vermeulen via swift-evolution < swift-evolution@swift.org> wrote: > Slightly related to this, I would really love to have non-subscript > parameterized properties. It would

[swift-evolution] Change subscripts to use colons

2016-07-11 Thread Tim Vermeulen via swift-evolution
Slightly related to this, I would really love to have non-subscript parameterized properties. It would allow us to write button.image(for: .normal) = image instead of button.setImage(image, for: .normal) The same can be achieved through subscripts, but it’s not always as nice. It would bring

Re: [swift-evolution] Change subscripts to use colons

2016-07-11 Thread James Froggatt via swift-evolution
I've added one of my original points to the motivation section: ‘[The arrow] implies that subscripts have the full capabilities of functions, such as the ability to throw. If throwing functionality were to be added to accessors, it is likely the specific get/set accessor would be annotated. In

Re: [swift-evolution] Change subscripts to use colons

2016-07-11 Thread James Froggatt via swift-evolution
I've written up a draft proposal, suggestions or improvements are welcome, especially relating to the title. __Change subscript declarations to use a colon__ --Introduction-- Currently, subscript declarations follow the following model: subscript(externalName internalName: ParamType) -> Ele

Re: [swift-evolution] Change subscripts to use colons

2016-07-11 Thread James Froggatt via swift-evolution
This is an interesting idea, but probably deserves its own proposal. Personally, I like the reuse of parameter list syntax, and think that, if anything, subscripts should be updated at the call-site to use round brackets. There shouldn't be any ambiguity problems, though readability could drop

Re: [swift-evolution] Change subscripts to use colons

2016-07-11 Thread Sean Heber via swift-evolution
The only thing that really bugs me about subscript is that you declare it with (), but use it with []. I’ve never found the return indicator to be confusing here. I get the argument in favor of property-ness, though. Wouldn’t mind considering using square brackets instead, but perhaps that has

Re: [swift-evolution] Change subscripts to use colons

2016-07-11 Thread James Froggatt via swift-evolution
Interesting way to think of the ‘->’ operator. Perhaps a <-> operator could represent this two-way mapping? > On 11 Jul 2016, at 20:29, Erica Sadun wrote: > > On Jul 11, 2016, at 1:21 PM, James Froggatt via swift-evolution > mailto:swift-evolution@swift.org>> wrote: >> >> Thanks for letting m

Re: [swift-evolution] Change subscripts to use colons

2016-07-11 Thread Erica Sadun via swift-evolution
On Jul 11, 2016, at 1:21 PM, James Froggatt via swift-evolution wrote: > > Thanks for letting me know this has been tried before, I'm actually in the > process of drafting the proposal now. I'd hesitate to try to do something off-beat and "blend" them but it amuses me no end that the :-> oper

Re: [swift-evolution] Change subscripts to use colons

2016-07-11 Thread James Froggatt via swift-evolution
Thanks for letting me know this has been tried before, I'm actually in the process of drafting the proposal now. I agree about the issue of the colon's visual weight, it's not ideal. On the other hand, I still find myself doing a mental double-take when reading ‘->’ in subscript declarations.

Re: [swift-evolution] Change subscripts to use colons

2016-07-11 Thread Chris Lattner via swift-evolution
FWIW, we actually tried this at one point with exactly this rationale, but pulled it back out. In short, subscript decls are half way between func decls and var decls. Reasonable arguments can be made to align with either of them, but arrow “looks” better. The problem which caused us to pull

Re: [swift-evolution] Change subscripts to use colons

2016-07-11 Thread James Froggatt via swift-evolution
If I had to choose what subscripts are most like, I'd have to say properties. Subscripts don't support partial application, and do support setters. I agree with Patrick in that subscripts are more like a ‘parameterized property’. If everyone's in favour, I'd like to get a proposal submitted for

Re: [swift-evolution] Change subscripts to use colons

2016-07-10 Thread Jacob Bandes-Storch via swift-evolution
On Sun, Jul 10, 2016 at 10:42 PM, Erica Sadun via swift-evolution < swift-evolution@swift.org> wrote: > > On Jul 10, 2016, at 5:18 PM, James Froggatt via swift-evolution < > swift-evolution@swift.org> wrote: > > > > Currently, the signature is: > > subscript(_ example: Int) -> Element { > >get

Re: [swift-evolution] Change subscripts to use colons

2016-07-10 Thread Erica Sadun via swift-evolution
> On Jul 10, 2016, at 5:18 PM, James Froggatt via swift-evolution > wrote: > > Currently, the signature is: > subscript(_ example: Int) -> Element { >get { … } >set { … } > } > > The alternative, using a colon, would be: > subscript(_ example: Int) : Element { >get { … } >set {

Re: [swift-evolution] Change subscripts to use colons

2016-07-10 Thread Jacob Bandes-Storch via swift-evolution
+1, seems right to me. The original email wasn't clear to me, but this example is. FWIW, as a user of the language I'd hope that throwing subscript getters/setters would be written "set throws { ... }" and/or "set(newValue) throws { ... }" rather than "throwing set { ... }", for consistency with f

Re: [swift-evolution] Change subscripts to use colons

2016-07-10 Thread Xiaodi Wu via swift-evolution
+1 as well. It always feels a little weird to be writing a setter inside something that says it returns what should be the argument. On Mon, Jul 11, 2016 at 00:05 Patrick Pijnappel via swift-evolution < swift-evolution@swift.org> wrote: > Good point. A subscript basically a parameterized property,

Re: [swift-evolution] Change subscripts to use colons

2016-07-10 Thread Patrick Pijnappel via swift-evolution
Good point. A subscript basically a parameterized property, not a function. I'm in favor. On Mon, Jul 11, 2016 at 9:18 AM, James Froggatt via swift-evolution < swift-evolution@swift.org> wrote: > Currently, the signature is: > subscript(_ example: Int) -> Element { > get { … } > set { … }

Re: [swift-evolution] Change subscripts to use colons

2016-07-10 Thread James Froggatt via swift-evolution
Currently, the signature is: subscript(_ example: Int) -> Element { get { … } set { … } } The alternative, using a colon, would be: subscript(_ example: Int) : Element { get { … } set { … } } Sorry if that wasn't clear. This would be to better reflect the property-like nature of

Re: [swift-evolution] Change subscripts to use colons

2016-07-10 Thread Brent Royal-Gordon via swift-evolution
> On Jul 9, 2016, at 11:48 AM, James Froggatt via swift-evolution > wrote: > > 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. > > However, I think a colon is more

[swift-evolution] Change subscripts to use colons

2016-07-09 Thread James Froggatt via swift-evolution
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. However, I think a colon is more suitable, since it implies the possibility to set the value. In the future, if we add t