by fleitz · 15y ago · 0 comments
[[^ (Foo*) (Foo* bar) { return bar; } copy] autorelease]
is a pretty ugly way of writing a lambda. It's like arguing that java can pass functions via anonymous classes. Yes, technically you can but it's pretty ugly.Another underlying problem is that the only language that can call Obj-C libraries is Obj-C.
.NET and the JVM solved this problem long ago, I know that Python/Perl/Ruby also have this problem outside of the JVM/CLR.
As far as GC, Obj-C effectively doesn't have it as most Obj-C outside of Apple is written for iOS which doesn't support GC.
You could create a point system and call Obj-C a modern language but working with it feels anything but. Apple doesn't need any serious rewrite, they need to make MacRuby work on the iPhone. That's it.
A more real-world example employing blocks with GCD would be:
dispatch_queue_t queue =
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
// do some time-consuming work
dispatch_async(dispatch_get_main_queue() ^{
// do stuff on the main thread, like updating UI
});
});
That's actually pure C. Typical block usage with Cocoa would be something like: [myArray enumerateObjectsWithOptions:NSEnumerationConcurrent
usingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
// do something with obj concurrently
}]; [array transformFoos:^(Foo*) (Foo* bar) {
return bar;
}];
I'm not sure there is a more succinct way to write a lambda with typed arguments and a typed return value.But I see it as a good alternative for apple development in a near future, let's just hope Apple sees it as well.
In practice this is the case, but the Etoile guys have written AppKit applications in Io and Smalltalk, and they have an ObjC -> JavaScript compiler running thanks to LLVM. So given time, I think this statement will come to be eroded away.
Lua is already on the iPhone, and will probably give you an order of magnitude performance advantage over Ruby.