[swift-evolution] Allow ' in variable/constant names?

Joe Groff jgroff at apple.com
Wed Jan 11 15:41:47 CST 2017


> On Jan 11, 2017, at 5:16 AM, Charlie Monroe via swift-evolution <swift-evolution at swift.org> wrote:
> 
> -1. Why? Why not use foo2 instead? Is ' so much better?
> 
> Instead, I'd personally love better character support in Swift in the future and allow a Character literals using ' - just like in C, except with Unicode support:
> 
> let myChar = 'x' // Character
> let myChar2 = '∃' // Character
> let myChar3 = '\0' // NUL Character
> let myChar4 = 'xyz' // Error from compiler

These aren't necessarily mutually exclusive. If we require that an identifier can't start with an apostrophe, then we can support identifiers named `x'` and `'x'` as some kind of literal simultaneously.

I'm sympathetic to this since I personally find x', x'', etc. more attractive than x2, x3, etc. for totally superficial math weenie reasons, but although the surface level language design is fairly straightforward, the downstream tooling impact is nontrivial—we'd need a mangling for ' in symbol names, simplified parsing tools would need to cope with ', tools that attempt to parse out identifiers from error messages would have to deal with apostrophe-unsafe output, etc. Not sure it's worth it.

-Joe


More information about the swift-evolution mailing list