food for thought - swift 5 released - bottom types, string interpolation, and stuff.
aliak
something at something.com
Tue Apr 9 06:23:26 UTC 2019
I personally love swift as a language because it's just a
pleasure to write _and_ read. Swift 5 was released recently [0]
and has a few interesting additions, particularly the additions
they've added to string interpolation [1] so that you could do
things like
let a: MyType = "this is an \(type: .interpolated) string"
The "this is a" part is parsed separately by 'a' and the
interpolated part "\(min: 1) is parsed as a type that is expected
by your StringInterpolation implementation
// member function that implements string interpolation
mutating func appendInterpolation(min: Int) {
//...
}
And then as is usual with swift, they try and make it as readable
as easy to reason with as possible, so they added things like
isOdd, isEven, and isMultiple(of:) [2] so that you don' t have to
mentally parse something like "% x == 0" or any bit operation
magic that tries to be too clever to do the same thing.
And another cool thing was they took their bottom type and made
it conform to a hashable and equatable type [3]. It would be the
equivalent if D had an Expect(SuccessType, ErrorType) type and if
either success or error type could never happen, could be
replaced by Bottom:
alias NeverError(SuccessType) = Expect!(SuccessType, bottom_t);
alias NeverSuccess(ErrorType) = Expect!(bottom_t, ErrorType);
[0] https://swift.org/blog/swift-5-released/
[1]
https://github.com/apple/swift-evolution/blob/master/proposals/0228-fix-expressiblebystringinterpolation.md
[2]
https://github.com/apple/swift-evolution/blob/master/proposals/0225-binaryinteger-iseven-isodd-ismultiple.md
[3]
https://github.com/apple/swift-evolution/blob/master/proposals/0215-conform-never-to-hashable-and-equatable.md
Cheers,
- Ali
More information about the Digitalmars-d
mailing list