[swift-evolution] Change subscripts to use colons
Tim Vermeulen
tvermeulen at me.com
Mon Jul 11 17:00:02 CDT 2016
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 subscripts and computed properties closer together, which also seems to be the goal of your proposal. Perhaps the two ideas could be combined?
> 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 throwing getters/ setters:
>
> subscript(_ position: Int) ->Element {
> get {
> return …
> }
> throwing set {
> …
> }
> }
>
> Should this require ‘throws ->Element’? Using a colon also removes this potentially confusing case.
>
>
> Thoughts?
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160712/b922f6c2/attachment.html>
More information about the swift-evolution
mailing list