[swift-evolution] [swift-evolution-announce] [Returned for revision] SE-0089: Renaming String.init<T>(_: T)
Chris Lattner
clattner at apple.com
Sun May 29 14:27:31 CDT 2016
Fantastic, thanks to both of you. I merged it here:
https://github.com/apple/swift-evolution/blob/master/proposals/0089-rename-string-reflection-init.md <https://github.com/apple/swift-evolution/blob/master/proposals/0089-rename-string-reflection-init.md>
Please let me know if you’d like any other changes, I’ll kick off the review on Tuesday.
-Chris
> On May 28, 2016, at 3:33 PM, Brent Royal-Gordon <brent at architechies.com> wrote:
>
>> If anyone is curious, the revised proposal can be found here: https://github.com/austinzheng/swift-evolution/blob/2b31df6163f5c5d1975a37e72c6996b82d61a5c6/proposals/0089-rename-string-reflection-init.md
>
> This is great. My only suggestion is that `init?(description: String)` should be `init?(_ description: String)`, since by definition the conversion is fullwidth. But you may already be planning to incorporate that change, since Chris mentioned it.
>
> Just quickly scanning the docs on swiftdoc.org, here are protocols which I think should conform to LosslessStringConvertible:
>
> * FloatingPoint
> * Integer
> * Boolean?
>
> And here are concrete types:
>
> * Bool (if not Boolean)
> * Character
> * String (kind of circular, but I think it's a good idea) and its views
> * String.Index? (Not sure how to represent this; UTF-8 offset, maybe?)
> * UnicodeScalar
>
> Protocols which would require conditional conformances:
>
> * RangeReplaceableCollection where Iterator.Element == Character or UnicodeScalar
> * SetAlgebra where Iterator.Element == Character or UnicodeScalar
>
> These protocols were chosen because they include `init<S: Sequence where S.Iterator.Element == Iterator.Element>(_: S)` initializers.
>
> Generic types which would require conditional conformances:
>
> * ClosedRange where Bound: LosslessStringConvertible
> * CountableClosedRange where Bound: LosslessStringConvertible
> * CountableRange where Bound: LosslessStringConvertible
> * Range where Bound: LosslessStringConvertible
>
> These would be non-trivial, but useful. They could have a serialization like:
>
> var description: String {
> let operator = "..<" // or "..." for the closed ranges
> func escape(_ string: String) -> String {
> let escapedOperator = String(operator.characters.flatMap { ["\\", $0] })
> return string.replacingOccurrences(of: "\\", with: "\\\\").replacingOccurrences(of: operator, with: escapedOperator)
> }
>
> return escape(String(lowerBound)) + " " + operator + " " + escape(String(upperBound))
> }
>
> The `init(_: String)` method would need to handle the escapes—hence the nontrivial-ness.
>
> Technically possible, but probably unwise:
>
> * ObjectIdentifier
> * UnsafePointer and friends
> * Set.Index and Dictionary.Index
>
> --
> Brent Royal-Gordon
> Architechies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160529/f50f9f6d/attachment.html>
More information about the swift-evolution
mailing list