# SE-0243: Codepoint and Character Literals

**URL:** <https://forums.swift.org/t/se-0243-codepoint-and-character-literals/21188>\
**Category:** Proposal Reviews\
**Created:** [March 4, 2019, 3:45pm UTC](https://forums.swift.org/t/se-0243-codepoint-and-character-literals/21188 "2019-03-04T15:45:06Z")\
**Posts on this page:** 1\
**Showing post:** 239

<div class="post-metadata">

**Author:** ![taylorswift](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/taylorswift/32/43413_2.png) [@taylorswift](https://forums.swift.org/u/taylorswift)\
**Post date:** [March 11, 2019, 6:19pm UTC](https://forums.swift.org/t/se-0243-codepoint-and-character-literals/21188/239 "2019-03-11T18:19:54Z")

</div>

> [@Karl](#):
>
> For those complaining about optionals and performance/trapping: have you heard of the [`unsafelyUnwrapped` property](https://developer.apple.com/documentation/swift/optional/1641793-unsafelyunwrapped)? It doesn't check or trap in optimised builds:

Isn’t this one of those things they tell us never to use? aiming a gun at your foot shouldn’t be the price you have to pay for an ASCII literal

> [@RMJay](#):
>
> Single quoted literals should clearly default to Character, which is the contituent element of a string at the level of human interpretation, and is the most common character-like type. This is a particularly beginner visible part of Swift.

Counterpoint: beginner exercises tend to involve processing fixed-length, structured, machine-readable strings. Think of any old CS homework problem—does it involve UTF8 continuations or grapheme breaking? If you want to teach a beginner how to get the query out of a URL string, you don’t want to throw Unicode at them, you just want them to treat/convert the `String` as an array of ASCII characters. (ASCII characters are actually the only characters valid in a url). There’s been a lot of lament on the forum about how Swift `String`s and its unicode-correct indexing model are getting in the way of Swift education and adoption, and I’ve always considered better ASCII support to be [the most appropriate solution to this problem](https://forums.swift.org/t/why-are-string-offsets-so-complicated/19753/50).

Unicode is an advanced topic for advanced users, and `Character`s are Unicode, a lot more than `Unicode.Scalar`, ironically. Maybe placing this API on the higher shelf isn’t the worst idea in the world.

> [@RMJay](#):
>
> Character already has an `let a = c.asciiValue //Optional(Int)` property which is the correct form to use on an arbitrary character parameter. A trapping variant would only be useful when bound to a literal ie.
> 
> ```swift
> 'a'.ascii //useful
> arbitrary.ascii //not useful
> 
> ```

I agree, a trapping property is not appropriate on either `Character` or `Unicode.Scalar`. There would be no language precedent,, `.first` and `.last` are important, commonly used properties, and we do not make them trap.

> [@RMJay](#):
>
> It seems to me that Swift is missing a langauge feature that would let us have the best overall outcome. That feature being **Literal Bound Functions** these would allow us to write the following, which is making use of a hypothetical literal bound `ascii` property on character-literal.

I don’t know how I feel about abusing function call syntax (yes, `'a'.ascii` is a function call, just written without parentheses) for literal coercion. Why not the `'A' as UInt8` syntax? I think `as` is a natural fit for this role, given its current usage in the language, and the `literal | as` grammar is well-established in Swift, so we wouldn’t have to teach users a new rule “‘literal bound functions’ can only be called on literal values”.

---

_[View the full topic](https://forums.swift.org/t/se-0243-codepoint-and-character-literals/21188)._
