[swift-evolution] commas optional

Dave Yost Dave at Yost.com
Thu Oct 12 15:11:13 CDT 2017


> On 2017-10-12, at 12:03 PM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
> 
> Single elements can legally span multiple lines; this would be hugely source breaking. What problem are you trying to solve?

The same problem that is solved by the precedent of semicolons being optional (clutter). I don’t see anything substantive about the analogy that does not hold.

Plus there is the meta-problem of inconsistency, where the analogy is apt but not expressed in the language.

> On Thu, Oct 12, 2017 at 13:50 Dave Yost via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> 
> Speaking as a huge fan of optional semicolons...
> 
> 
> This seems clear:
> 
>      semicolon : sequence of statements
>   :: comma     : sequence of elements in an array literal
> 
> and so it occurred to me that this should hold:
> 
>      A semicolon : the last statement     on a line.
>   :: A comma     : the last array element on a line.
> 
>   ∴  A comma after the last array element on a line should be optional.
> 
> and these should be legal Swift:
> 
>   let list = [
>       1
>       2
>   ]
> 
>   let dict = [
>       1 : 2
>       2 : 3
>   ]
> 
> equivalent to:
> 
>   let list = [ 1, 2 ] ; let dict = [ 1 : 2, 2 : 3 ]
> 
> 
> Or, as the Language Reference would say:
> 
> A semicolon (;) can optionally appear after any statement and is used to separate multiple statements if they appear on the same line.
> 
> A comma (,) can optionally appear after any element of an array literal and is used to separate multiple elements if they appear on the same line.
> 
> Or:
> 
> A semicolon (;) separates statements but is optional after the last statement on a line.
> 
> A comma (,) separates elements of an array literal but is optional after the last element on a line.
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171012/41e96c48/attachment.html>


More information about the swift-evolution mailing list