[swift-evolution] Change subscripts to use colons

James Froggatt james.froggatt at me.com
Mon Jul 11 03:50:29 CDT 2016


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 this. I can have a go when I have some time, though I'm not yet familiar with the process. If anyone with experience wants to take this on, that'd be a great help. I think the change in question is pretty straightforward.


From James F

On 11 Jul 2016, at 06:42, Erica Sadun <erica at ericasadun.com> wrote:

>> On Jul 10, 2016, at 5:18 PM, James Froggatt via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> 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 access.
> 
> It all depends on whether a subscript is more function-y or property-y, and don't forget subscripts can take parameters and labels.
> 
> let y = myArrayOfStrings[safeIndex: 2, fallback: "foo"]
> 
> -- E
> 


More information about the swift-evolution mailing list