• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Some non-obvious Swift goodies
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Some non-obvious Swift goodies
      • From: Jens Alfke <email@hidden>
References: 
 >Some non-obvious Swift goodies (From: Jens Alfke <email@hidden>)

  • Prev by Date: Some non-obvious Swift goodies
  • Next by Date: Re: swift and objective-c
  • Previous by thread: Some non-obvious Swift goodies
  • Next by thread: Re: Some non-obvious Swift goodies
  • Index(es):
    • Date
    • Thread