commas optional

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.

a semicolon is a purely syntactic delimiter, the comma on the other hand
corresponds to physical elements in a collection. I think the two are more
different than you suggest.

···

On Thu, Oct 12, 2017 at 1:50 PM, Dave Yost via swift-evolution < swift-evolution@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@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Single elements can legally span multiple lines; this would be hugely
source breaking. What problem are you trying to solve?

···

On Thu, Oct 12, 2017 at 13:50 Dave Yost via swift-evolution < swift-evolution@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@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Hi Dave,

I agree with you that this is an analogous technical problem to semicolon inference, and that Swift has a well developed solution for it which would probably work well enough.

That said, this is a pure sugar proposal, one which can make future evolution more difficult. Getting this into Swift 5 will be very very difficult to justify, even if the community somehow agreed that it was the right thing to do. It is just the conservatively correct default to say “no” to these sorts of changes now, because there are other bigger moving pieces that have to be sorted first.

-Chris

···

On Oct 12, 2017, at 11:50 AM, Dave Yost via swift-evolution <swift-evolution@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@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

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 2017-10-12, at 12:03 PM, Xiaodi Wu <xiaodi.wu@gmail.com> wrote:

On Thu, Oct 12, 2017 at 13:50 Dave Yost via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@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@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

a semicolon is a purely syntactic delimiter, the comma on the other hand corresponds to physical elements in a collection. I think the two are more different than you suggest.

I very much agree^

Josh

Joshua Parmenter | Engineering Lead, Apple Technologies

T 248 777 7777
C 206 437 1551
F 248 616 1980
www.vectorform.com<http://www.vectorform.com/&gt;

Vectorform
2211 5th Ave Suite 201
Seattle, WA 98121 USA

Think Tank. Lab. Studio.
We invent digital products and experiences.

SEATTLE | DETROIT | NEW YORK | MUNICH | HYDERABAD

···

On Oct 12, 2017, at 12:17 PM, Kelvin Ma via swift-evolution <swift-evolution@swift.org<mailto:swift-evolution@swift.org>> wrote:

I don't really expect this sort of syntactic sugar to be popular enough to make it through swift-evolution, and I don't think it's worth the distraction from more important priorities at this time, but for what it's worth, I've enjoyed this feature in other languages that support it. It plays a small part in making code more focused by eliminating unnecessary syntax.

I could be wrong, but I'm not so sure that this would actually be source breaking. Even if you have something like this:

let points = [
Point(
x: 1.0,
y: 2.0
),
Point(
x: 3.0,
y: 4.0
)
]

Proper implementation of this feature wouldn't suddenly interpret `Point(` as its own element.

Jarod

···

On Oct 12, 2017, 12:23 -0700, Josh Parmenter via swift-evolution <swift-evolution@swift.org>, wrote:

On Oct 12, 2017, at 12:17 PM, Kelvin Ma via swift-evolution <swift-evolution@swift.org<mailto:swift-evolution@swift.org>> wrote:

a semicolon is a purely syntactic delimiter, the comma on the other hand corresponds to physical elements in a collection. I think the two are more different than you suggest.

I very much agree^

Josh

Joshua Parmenter | Engineering Lead, Apple Technologies

T 248 777 7777
C 206 437 1551
F 248 616 1980
www.vectorform.com<http://www.vectorform.com/

Vectorform
2211 5th Ave Suite 201
Seattle, WA 98121 USA

Think Tank. Lab. Studio.
We invent digital products and experiences.

SEATTLE | DETROIT | NEW YORK | MUNICH | HYDERABAD
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

I don't really expect this sort of syntactic sugar to be popular enough to
make it through swift-evolution, and I don't think it's worth the
distraction from more important priorities at this time, but for what it's
worth, I've enjoyed this feature in other languages that support it. It
plays a small part in making code more focused by eliminating unnecessary
syntax.

I could be wrong, but I'm not so sure that this would actually be source
breaking. Even if you have something like this:

let points = [
    Point(
        x: 1.0,
        y: 2.0
    ),
    Point(
        x: 3.0,
        y: 4.0
    )
]

Proper implementation of this feature wouldn't suddenly interpret `Point(`
as its own element.

There are those of us who respect the 80-character line and break
expressions across lines:

let x = [
  NSVeryVeryVeryLongType
    .veryVeryVeryLongProperty +
      NSVeryVeryVeryLongType2
        .veryVeryVeryLongProperty2,
]

It would be a pleasant surprise if a grammar with optional commas can avoid
blowing up existing code; I'm quite doubtful.

···

On Thu, Oct 12, 2017 at 2:47 PM, Jarod Long via swift-evolution < swift-evolution@swift.org> wrote:

On Oct 12, 2017, 12:23 -0700, Josh Parmenter via swift-evolution < > swift-evolution@swift.org>, wrote:

On Oct 12, 2017, at 12:17 PM, Kelvin Ma via swift-evolution < > swift-evolution@swift.org<mailto:swift-evolution@swift.org>> wrote:

a semicolon is a purely syntactic delimiter, the comma on the other hand
corresponds to physical elements in a collection. I think the two are more
different than you suggest.

I very much agree^

Josh

Joshua Parmenter | Engineering Lead, Apple Technologies

T 248 777 7777 <(248)%20777-7777>
C 206 437 1551 <(206)%20437-1551>
F 248 616 1980 <(248)%20616-1980>
www.vectorform.com<http://www.vectorform.com/

Vectorform
2211 5th Ave Suite 201
Seattle, WA 98121 USA

Think Tank. Lab. Studio.
We invent digital products and experiences.

SEATTLE | DETROIT | NEW YORK | MUNICH | HYDERABAD
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

An argument against optional commas,, or an indictment of overly verbose
Foundation APIs… :thinking::thinking::thinking:

···

On Thu, Oct 12, 2017 at 6:20 PM, Xiaodi Wu <xiaodi.wu@gmail.com> wrote:

On Thu, Oct 12, 2017 at 2:47 PM, Jarod Long via swift-evolution < > swift-evolution@swift.org> wrote:

I don't really expect this sort of syntactic sugar to be popular enough
to make it through swift-evolution, and I don't think it's worth the
distraction from more important priorities at this time, but for what it's
worth, I've enjoyed this feature in other languages that support it. It
plays a small part in making code more focused by eliminating unnecessary
syntax.

I could be wrong, but I'm not so sure that this would actually be source
breaking. Even if you have something like this:

let points = [
    Point(
        x: 1.0,
        y: 2.0
    ),
    Point(
        x: 3.0,
        y: 4.0
    )
]

Proper implementation of this feature wouldn't suddenly interpret
`Point(` as its own element.

There are those of us who respect the 80-character line and break
expressions across lines:

let x = [
  NSVeryVeryVeryLongType
    .veryVeryVeryLongProperty +
      NSVeryVeryVeryLongType2
        .veryVeryVeryLongProperty2,
]

It would be a pleasant surprise if a grammar with optional commas can
avoid blowing up existing code; I'm quite doubtful.

Ahh, yeah, that does seem like a much trickier case to avoid breaking. My instinct says it's still possible to avoid, but maybe not without lots of complexity.

Jarod

···

On Oct 12, 2017, 16:21 -0700, Xiaodi Wu <xiaodi.wu@gmail.com>, wrote:

On Thu, Oct 12, 2017 at 2:47 PM, Jarod Long via swift-evolution <swift-evolution@swift.org> wrote:
> > I don't really expect this sort of syntactic sugar to be popular enough to make it through swift-evolution, and I don't think it's worth the distraction from more important priorities at this time, but for what it's worth, I've enjoyed this feature in other languages that support it. It plays a small part in making code more focused by eliminating unnecessary syntax.
> >
> > I could be wrong, but I'm not so sure that this would actually be source breaking. Even if you have something like this:
> >
> > let points = [
> > Point(
> > x: 1.0,
> > y: 2.0
> > ),
> > Point(
> > x: 3.0,
> > y: 4.0
> > )
> > ]
> >
> > Proper implementation of this feature wouldn't suddenly interpret `Point(` as its own element.
>
> There are those of us who respect the 80-character line and break expressions across lines:
>
> let x = [
> NSVeryVeryVeryLongType
> .veryVeryVeryLongProperty +
> NSVeryVeryVeryLongType2
> .veryVeryVeryLongProperty2,
> ]
>
> It would be a pleasant surprise if a grammar with optional commas can avoid blowing up existing code; I'm quite doubtful.
>
>
> > On Oct 12, 2017, 12:23 -0700, Josh Parmenter via swift-evolution <swift-evolution@swift.org>, wrote:
> > >
> > >
> > > On Oct 12, 2017, at 12:17 PM, Kelvin Ma via swift-evolution <swift-evolution@swift.org<mailto:swift-evolution@swift.org>> wrote:
> > >
> > > a semicolon is a purely syntactic delimiter, the comma on the other hand corresponds to physical elements in a collection. I think the two are more different than you suggest.
> > >
> > >
> > > I very much agree^
> > >
> > > Josh
> > >
> > >
> > >
> > > Joshua Parmenter | Engineering Lead, Apple Technologies
> > >
> > > T 248 777 7777
> > > C 206 437 1551
> > > F 248 616 1980
> > > www.vectorform.com<http://www.vectorform.com/
> > >
> > > Vectorform
> > > 2211 5th Ave Suite 201
> > > Seattle, WA 98121 USA
> > >
> > > Think Tank. Lab. Studio.
> > > We invent digital products and experiences.
> > >
> > > SEATTLE | DETROIT | NEW YORK | MUNICH | HYDERABAD
> > > _______________________________________________
> > > swift-evolution mailing list
> > > swift-evolution@swift.org
> > > https://lists.swift.org/mailman/listinfo/swift-evolution
> >
> > _______________________________________________
> > swift-evolution mailing list
> > swift-evolution@swift.org
> > https://lists.swift.org/mailman/listinfo/swift-evolution
> >

Ahh, yeah, that does seem like a much trickier case to avoid breaking. My instinct says it's still possible to avoid, but maybe not without lots of complexity.

We already have whitespace sensitive rules to handle this. There is no fundamental implementation difference that I see between separating the elements of lists (which are expressions) and the elements of statements (which can be expressions):

func foo() -> Int { … }

func statements() {
  foo()
  foo()
}

let list = [
  foo()
  foo()
]

That said, I still believe that it would be premature to "syntax optimize" this at this point in Swift’s evolution.

-Chris

···

On Oct 13, 2017, at 10:43 AM, Jarod Long via swift-evolution <swift-evolution@swift.org> wrote:

Jarod

On Oct 12, 2017, 16:21 -0700, Xiaodi Wu <xiaodi.wu@gmail.com>, wrote:

On Thu, Oct 12, 2017 at 2:47 PM, Jarod Long via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
I don't really expect this sort of syntactic sugar to be popular enough to make it through swift-evolution, and I don't think it's worth the distraction from more important priorities at this time, but for what it's worth, I've enjoyed this feature in other languages that support it. It plays a small part in making code more focused by eliminating unnecessary syntax.

I could be wrong, but I'm not so sure that this would actually be source breaking. Even if you have something like this:

let points = [
    Point(
        x: 1.0,
        y: 2.0
    ),
    Point(
        x: 3.0,
        y: 4.0
    )
]

Proper implementation of this feature wouldn't suddenly interpret `Point(` as its own element.

There are those of us who respect the 80-character line and break expressions across lines:

let x = [
  NSVeryVeryVeryLongType
    .veryVeryVeryLongProperty +
      NSVeryVeryVeryLongType2
        .veryVeryVeryLongProperty2,
]

It would be a pleasant surprise if a grammar with optional commas can avoid blowing up existing code; I'm quite doubtful.

On Oct 12, 2017, 12:23 -0700, Josh Parmenter via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>>, wrote:

On Oct 12, 2017, at 12:17 PM, Kelvin Ma via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org><mailto:swift-evolution@swift.org <mailto:swift-evolution@swift.org>>> wrote:

a semicolon is a purely syntactic delimiter, the comma on the other hand corresponds to physical elements in a collection. I think the two are more different than you suggest.

I very much agree^

Josh

Joshua Parmenter | Engineering Lead, Apple Technologies

T 248 777 7777 <tel:(248)%20777-7777>
C 206 437 1551 <tel:(206)%20437-1551>
F 248 616 1980 <tel:(248)%20616-1980>
www.vectorform.com <http://www.vectorform.com/&gt;&lt;http://www.vectorform.com/

Vectorform
2211 5th Ave Suite 201
Seattle, WA 98121 USA

Think Tank. Lab. Studio.
We invent digital products and experiences.

SEATTLE | DETROIT | NEW YORK | MUNICH | HYDERABAD
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution