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

Jay Abbott jay at abbott.me.uk
Wed Jan 11 20:46:13 CST 2017

As Rob Mayoff pointed out, you can use MODIFIER LETTER PRIME - or PRIME,
DOUBLE PRIME, and TRIPLE PRIME - which makes more sense than an apostrophe.
Now if only there were a keyboard that had a touch-screen at the top which
could be used for typing context-sensitive characters that would otherwise
be difficult to type. So yeah, solution is to make characters easier to
type, not modify the language. If like me you don't have such a keyboard,
you can always use ctrl+⌘+<space> and type ‘PRIME’ to find it, then pick it
from recently used/favourites.

Regarding the other point, I agree that character literals would be handy,
but again I’m not sure if apostrophe is the right character to indicate it.
Although it is familiar, perhaps LEFT SINGLE QUOTATION MARK and RIGHT
SINGLE QUOTATION MARK would be better, they can be relatively easily typed
with ⎇+] and ⎇+⇧+] respectively. Xcode could also convert two apostrophes
into ‘’ for you and your fingers would quickly learn to type ' ' ← ‹char›.

On Wed, 11 Jan 2017 at 22:07 David Sweeris via swift-evolution <
swift-evolution at swift.org> wrote:

> On Jan 11, 2017, at 15:41, Joe Groff via swift-evolution <
swift-evolution at swift.org> wrote:
>> 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.

Out of curiosity, instead of coming up with another mangling scheme, how
hard would it be to add ' support to the downstream tooling? It's all open
source, right?

- Dave Sweeris

swift-evolution mailing list
swift-evolution at swift.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170112/5f4d8030/attachment.html>

More information about the swift-evolution mailing list