[cfe-dev] "Blocks" in Clang (aka closures)
csdavec at swansea.ac.uk
Wed Sep 3 11:02:34 PDT 2008
On 2 Sep 2008, at 17:01, Bill Bumgarner wrote:
> On Sep 2, 2008, at 8:27 AM, David Chisnall wrote:
>> 1) In Seaside (Smalltalk web-app framework) blocks are used as a way
>> of implementing continuation passing. This requires support for re-
>> binding variables in the closure. Smalltalk does this via the
>> BlockContext object. Is there an equivalent of it here?
> I'm not familiar with Seaside, so generically...
> All local variables are const-copied into the block (if used, of
> course -- if not, nothing happens) unless marked with __block.
> int x = 3;
> __block int y = 4;
> // effectively 'const int x;' here
> x = 4; // error
> y = 5; // works fine
> Global variables work just like they do everywhere else.
I don't think I explained this one properly. Say I have the block
you defined here, and I store it somewhere. Later, I want to reuse
the block, but have Y point to a different __block-scope variable.
This pattern is very important for a lot of the stuff that Seeside
uses to turn a sequence of HTTP requests into something that looks
like a normal GUI application to the programmer. The general
question here is are the blocks reflective, like Smalltalk blocks, or
are the opaque like GCC nested functions?
More information about the cfe-dev