discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ANN] Blocks/Closures in Objective-C


From: Shawn Erickson
Subject: Re: [ANN] Blocks/Closures in Objective-C
Date: Wed, 1 Sep 2004 14:26:40 -0700


On Sep 1, 2004, at 1:41 PM, Martin Häcker wrote:

Hi there,

after being annoyed long enough that ObjC doesn't support Blocks on the gcc-compiler I tried to implement them - and with a bit of luck on my part got a result.

So, head over to <http://dwt.de.vu/> or download the code directly from <http://user.cs.tu-berlin.de/~mhaecker/website/data/ BlockGenerator.zip>.

Some comments:
This is currently a proof of concept implementation to find out how far I could push the compiler with some macros and a simple class to emulate the block concept from Smalltalk (and have easy access to closures :).

I succeeded and now have an implementation that works.

Here's some teasers of what you can do with them:

--- snip ---
id aBlock = BLOCK(id, id each, return [each doSomethingThatReturnsAnID]);
id result = [aBlock value: someObject];

id aBlock = TestBlock(return [each isMaried]);
BOOL result = [aBlock test: somePerson];

id someObject = [self getAnotherObject];
id aBlock = UnaryBlock(if ([each isThisTrue]) {
                                        return [someObject getThis];
                                } else {
                                        return [self getThatOtherThing];
                                });
id result = [aBlock value: thatObject];
--- snap ---

So I long for your comments and suggestions on how to improve this. :-)

<http://www.macdevcenter.com/pub/a/mac/2004/07/16/hom.html>
<http://www.cocoadev.com/index.pl?HigherOrderMessaging>

- Shawn





reply via email to

[Prev in Thread] Current Thread [Next in Thread]