[swift-evolution] Change subscripts to use colons

Jacob Bandes-Storch jtbandes at gmail.com
Mon Jul 11 00:56:15 CDT 2016


On Sun, Jul 10, 2016 at 10:42 PM, Erica Sadun via swift-evolution <
swift-evolution at swift.org> 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


But isn't it the getter and setter which are really function-y? That's why
you can write "set(myVariableName) { ... }"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160710/6e527f97/attachment.html>


More information about the swift-evolution mailing list