Re: Some non-obvious Swift goodies
Re: Some non-obvious Swift goodies
- Subject: Re: Some non-obvious Swift goodies
- From: Chris Lattner <email@hidden>
- Date: Wed, 04 Jun 2014 00:06:12 -0700
> On Jun 3, 2014, at 8:59 PM, Jens Alfke <email@hidden> wrote:
>
> 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.
Fun fact: all class/struct/enum methods are curried over self.
> • 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.
Fun fact: deferred evaluation is what allows short circuiting &&/|| to be defined in the library, as well as “assert” and various XCTest functionality to be implemented without a macro system.
> • 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.
Yep, this is because basic operators like + are part of the standard library, not hard coded into the compiler.
> 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.
This is explicitly mentioned in the release notes as “not yet enabled, but coming soon”.
-Chris
_______________________________________________
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