[swift-evolution] [Review] SE-0144: Allow Single Dollar Sign as a Valid Identifier

Kevin Ballard kevin at sb.org
Wed Oct 19 14:59:24 CDT 2016

On Mon, Oct 17, 2016, at 11:25 PM, Jean-Denis Muys via swift-evolution wrote:
> Now for the elephant in the room: '$' is a currency symbol. As such it
> should be handled like any other currency symbol. Thinking otherwise
> would be very culturally offensive.
> So can I use € as an variable name in Swift? According to Xcode
> 8.1B3, yes.
> Can I use any currency symbol as an variable name in Swift? According
> to Xcode 8.1B3, not quite, but almost all of them.
> [snip]
> Of course, this is just a data point, and Xcode8.1B3 should not be the
> arbiter here. But I believe whether Swift accepts currency symbols as
> variable names should be consistent. Either it accepts all of them, or
> it includes all of them.
> I see no reason to exclude them. On the contrary, it was a design
> feature of Swift to relieve use from the shackles of the ASCII
> character set.
> In conclusion, I believe this proposal must be accepted, and actually
> expanded to include ¥, ¢, £, and also to make it explicit that
> currency symbols can be used in variable names as first and only
> character, as first of many characters, and at any position.

Swift doesn't care about currency symbols. The Currency_Symbol general
category is not special to Swift. And the fact that $, ¥, ¢, and £ (and
don't forget about ¤, which you didn't list) aren't valid identifiers is
a consequence of how they're categorized by Unicode, not some
intentional decision by Swift. Specifically, all of the currency symbols
that are in the Basic Latin block (e.g. any currency symbol in the range
U+0000–U+00FF) have the Pattern_Syntax property. And the Pattern_Syntax
property is defined by Unicode (see UAX #31) as a stable set of
characters that are appropriate to use for syntax in
patterns/expressions (e.g. programming language syntax, regular
expressions, ICU number formats, etc). I don't have a good way to test
this (UnicodeChecker has no way to search for all characters with the
Pattern_Syntax property), but AFAIK all Pattern_Syntax characters are
not legal identifiers in Swift, with any character not already reserved
for use by the Swift grammar (e.g. $ being used for positional
parameters) being available for operators.

-Kevin Ballard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161019/03be5038/attachment.html>

More information about the swift-evolution mailing list