Some non-obvious Swift goodies
Some non-obvious Swift goodies
- Subject: Some non-obvious Swift goodies
- From: Jens Alfke <email@hidden>
- Date: Tue, 03 Jun 2014 20:59:09 -0700
A couple of non-obvious things I gleaned from the Swift book*:
• Currying! A weird functional-programming technique involving partial evaluation, in functions-that-return-functions.
• Deferred evaluation of parameters — the “auto_closure” attribute on a function parameter causes the corresponding expression in the function call to be wrapped up in a closure and passed in that way, instead of being evaluated. Then the function implementation can call the closure. This is a bit of black magic I’ve only seen in Haskell and C# before.
• You can not only overload arithmetic operators (like + or *), you can make up your own like “<-!-*” (the Prince operator?) and assign them custom associativity and precedence.
and one baddie:
• There’s no notion of private or protected methods — all methods are fair game for anyone to call. This is apparently a known omission in the language that will be remedied in the future.
—Jens
* which is publicly available in iBooks and thus not under FNDA
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden