[swift-evolution] [Idea] Allowing most keywords after "."

Radosław Pietruszewski radexpl at gmail.com
Sat Feb 27 10:38:46 CST 2016


I do like `else` — it still reads naturally with the list of cases, maybe is even superior to `default`.

I think part of `default`s appeal (vs just removing it and mandating `case _`), is that default is familiar and used in a lot of languages (I don’t know of anything but Ruby that would use else in this context)

Still, `else` doesn't require understanding of wildcards or other pattern matching syntax details, which is good on this axis, and is also familiar, just isn’t used in this context in most languages.

> 2. Could the parser scan the leading `.` to prevent the need for escaping cases named "default", or would this unnecessarily complicate the compiler?

I’m sorry, I’m confused — I thought that was the whole point of the OP’s idea?

— Radek

> On 27 Feb 2016, at 15:05, Stephen Celis <stephen.celis at gmail.com> wrote:
> 
>> On Feb 27, 2016, at 8:37 AM, Radosław Pietruszewski via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> +1, that makes a lot of sense.
>> 
>> Q: Is `case default` in enum context ambiguous? In case I’m forgetting something, `default` is only used in `switch` contexts. So… couldn’t we make the keyword context dependent?
> 
> According to the grammar, `default` is indeed only used in `switch`: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/swift/grammar/default-label
> 
> I have two thoughts:
> 
> 1. Is it possible to reconsider reusing another keyword, `else`, as Ruby does?
> 
> 2. Could the parser scan the leading `.` to prevent the need for escaping cases named "default", or would this unnecessarily complicate the compiler?
> 
> --
> Stephen



More information about the swift-evolution mailing list