[Adium-devl] HOM

Ofri Wolfus ofri.wolfus at gmail.com
Sat Nov 11 13:18:07 UTC 2006


Hi guys,

As some of you may know, I've been working on a higher order  
messaging (HOM) implementation[1] for some time now, and I'd like to  
suggest it for Adium. For those of you who are not familiar with the  
HOM concept, it's basically a way to pass messages as arguments to  
other messages (see http://www.metaobject.com/papers/ 
Higher_Order_Messaging_OOPSLA_2005.pdf for the OOPSLA paper about  
HOM). In practice, probably the most common usage pattern for HOM is  
in iterations over collections. Instead of writing:
NSEnumerator *e = [someCollection objectEnumerator];
NSString *str;
NSMutableArray *r = [NSMutableArray array];
while ((str = [e nextObject]))
	if ([str hasPrefix:@"a"])
		[r addObject:str];

you'd just do NSMutableArray *r = [someCollection selectWhere:MSG 
(hasPrefix:@"a"), nil]; where -selectWhere: is a method that accepts  
variable number of messages, sends them by order to each member of  
the collection, and returns the objects that returned YES for the  
last message. Another example for it will be NSArray  
*availableContacts = [contacts selectWhere:MSG(status), MSG 
(isEqualToString:@"Available"), nil];.
As you might have guessed, MSG() is a macro that returns an  
autoreleased Message instance ("Message" is the class's name) which  
can then be passed around like any other object.

In my experience, using HOM can greatly simplify code in some common  
cases, which I think will do only good to Adium's huge code-base.

What do you think?
- Ofri

- - - - - - - - - - - - - - - - - - -
http://www.dpompa.com
- - - - - - - - - - - - - - - - - - -

[1] http://www.dpompa.com/?page_id=4

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://adium.im/pipermail/devel_adium.im/attachments/20061111/ce7a2093/attachment-0001.html>


More information about the devel mailing list