Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

Blocks in Objective-C. Closures are coming soon to Objective-C—interesting syntax, a regular curly brace block preceded by a caret ^{ ... }.

Tagged , , , ,

4 comments

  1. It looks like one (of the many) variations proposed for the lambda syntax in Javascript, though who knows what syntax Javascipt will eventually end up with... ;)

    Andy - 29th December 2008 20:42 - #

  2. I don't know that they're closures, just blocks. You can't use local variables defined at the call-site right?

    Koz - 30th December 2008 02:23 - #

  3. As far as I can tell from that post and its comments they're proper closures in that they capture variables from their enclosing scope. It looks like there's a bit extra you have to do if you want to be able to modify variables in the enclosing scope from within the block (which is also true of Python prior to Python 3.0). I wonder if they only work if you are using Objective-C's garbage collector? Closures don't seem like something that would work well with manual memory management.

    Simon Willison - 30th December 2008 08:12 - #

  4. My understanding is that the Block runtime library will use manual reference counting when not linked into a garbage-collected Objective-C application. I don’t remember exactly where this understanding comes from, but I’m pretty sure it’s from public primary sources.

    Ahruman - 12th January 2009 18:48 - #

Comments are closed.
A django site