Re: Some non-obvious Swift goodies
Re: Some non-obvious Swift goodies
- Subject: Re: Some non-obvious Swift goodies
- From: Ron Hunsinger <email@hidden>
- Date: Thu, 05 Jun 2014 13:41:46 -0700
On Jun 3, 2014, at 8:59 PM, Jens Alfke <email@hidden> wrote:
> • 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.
Algol 60 had this feature also. The B6700 had hardware support for it. A function parameter could be passed by-value or by-name. A by-name parameter was actually passed as a reference. When the function body tried to de-reference it, the hardware would notice whether the reference pointed to data, a function, or another reference. If it pointed at a function, the function would be called with no arguments and the result (which could be another reference) examined. A reference would be de-referenced in turn. Eventually, you'd get to data.
The B6700 made the determination at run time, based on the tag that was present on every word, including whatever word the reference pointed to. It looks like Swift is making the determination at compile time, likely to be more efficient on a machine that doesn't have built-in tag support, and safer too.
However it's implemented, it turned out to be an extremely powerful tool. I'm delighted to see its re-emergence.
-Ron Hunsinger
_______________________________________________
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