[swift-evolution] Idea: Allow/require "let" in property setter name declarations
Chris Lattner
clattner at apple.com
Fri May 6 20:00:08 CDT 2016
On May 6, 2016, at 4:09 AM, Ian Partridge via swift-evolution <swift-evolution at swift.org> wrote:
> Currently, the syntax for explicitly naming property setters is:
>
> set(newPerimeter) { // declares newPerimeter parameter, "let" not allowed
> sideLength = newPerimeter / 4.0
> }
> Compare this with how extraction of associated values from enumerations looks:
>
> switch response {
> case .Failure(let reason): // let is required here
> print(reason)
> case .Result(let code):
> print(code)
> }
I understand what you’re saying, and this would be a logical direction for ML or Haskell, which use patterns for their parameter grammars. In Swift, function parameters (including setter parameters, subscript indexes, etc) do not allow the general pattern matching or destructuring grammar that you can use in ‘case’ patterns, and thus you don’t have to write:
func f(let x : Int) {}
This is one of the reasons that led to SE-0003.
-Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160506/5da5be50/attachment.html>
More information about the swift-evolution
mailing list