Dept. of Wheel Reinvention
From the brief on Apple's new concurrency framework, Grand Central Dispatch:
Blocks are a simple extension to C (as well as Objective-C and C++) that make it easy for you to define self-contained units of work. A block in code is denoted by a caret at the beginning of a function. For example, you could declare a block and assign it to x by writing:
x = ^{ printf("hello world\n"); }This turns the variable x into a way of calling the function so that callingx( );
in the code would print the words hello world.What’s really powerful about blocks is that they enable you to wrap much more complex functions—as well as their arguments and data—in a way that can be easily passed around in a program, much as a variable can be easily referenced and passed.
Underneath this is a diagram showing that a block is like a function with some associated data.
I think I've seen this idea before somewhere. :-)
Ah, but a closure by any other name would smell as sweet...