higher order messaging hom
play

Higher Order Messaging (HOM) Marcel Weiher www.metaobject.com - PowerPoint PPT Presentation

Higher Order Messaging (HOM) Marcel Weiher www.metaobject.com Overview Intro Motivation/Development Usage and Implementation Outlook HOM in a Nutshell Message taking a Message as an Argument Example [[stringArray


  1. Higher Order Messaging (HOM) Marcel Weiher www.metaobject.com

  2. Overview •Intro •Motivation/Development •Usage and Implementation •Outlook

  3. HOM in a Nutshell •Message taking a Message as an Argument •Example [[stringArray collect ] stringByAppendingString:@"suffix"]; (this returns the result of sending the message "stringByAppendingString" with the argument @"suffix" to each of theobjects in stringArray)

  4. Motivation •Pattern avoidance (laziness) •The "loop" pattern id nextObject; id enumerator=[ array objectEnumerator]; id result =[NSArray array]; while ( nil!=(nextObject=[enumerator nextObject] ) { [result addObject:[nextObject stringByAppendingString:@"suffix"] ]; } (most of this code is unchanging, it gets repeated in every 'invocation' of the pattern. We should be able to write it once and then 'call' it with the arguments given in bold )

  5. Inspiration •Iteration in Smalltalk, ST-72 • forall in Postscript •Functors in FP (HOF) •Unix Pipes and Filters •NSEnumerator

  6. Perspiration •makeObjectsPerformSelector: •Filter-Enumerators: enumerator- based, stackable, practical result =[ array filterWithSelector: @selector( stringByAppendingString:) withObject: @"suffix" withObjet:nil];

  7. Problems •proliferation of filter-methods •dispersed message-send result =[ array filterWithSelector: @selector( stringByAppendingString:) withObject: @"suffix" withObjet:nil]; (the parts in bold together form a message send) •order obscured result =[ array filterArgumentWithSelector: @selector( stringByAppendingString:) withTarget: @"prefix" withObjet:nil]; (@"prefix" is the receiver of the dispersed message send, array is the argument, but the order is reversed in code)

  8. Insight •use existing syntax result=[object stringByAppendingString:@"suffix"]; •generalize message send •use runtime as 'parser'

  9. HOM •prefix message (the HOM) [ [array collect ] stringByAppendingString:@"suffix"]; •argument-message [ [array collect] stringByAppendingString:@"suffix"];

  10. Usage •HOMs: do,collect,select,selectWhere:,reduce •Arbitrary multiple iterations [ [prefixes collect ] stringByAppendingString:@"suffix"]; (iterates through receiver array, single argument) [ [@"prefix" collect ] stringByAppendingString:[suffixes each]]; (single receiver, iterates through argument array) [ [prefixes collect ] stringByAppendingString:[suffixes each]]; (iterates through both receiver array and argument array in lock-step)

  11. Advantages •Saves code •Declarative, intentional style •Chunk more, do more •Easy conceptual model •Works across bridges

  12. Implementation •Trampolines •Filter Enumerators •Optimization

  13. Trampolines •NSInvocation •forwardInvocation: •Target + selector to bounce

  14. Filter-Enumerators •Setup •nextObject •Results Processing •Running the Iteration

  15. Optimization •Aggressive IMP-caching •Encapsulated/Localized •Compensate Overhead

  16. Issues •Overhead •Obfuscation •Portability • select and calling conventions

  17. Outlook •Expose stackability •Optimize implementation •Eliminate more patterns •DBs, Threads, Futures, •Idea of message transport

  18. Availability •Part of MPWFoundation •unit tests, heavy use, > 4 years (PS/PDF Interpreter, Workflow-Engine, etc.) •Free for the asking www.metaobject.com

  19. Summary •EnumFilters eliminate loops •Obvious interface via HOM •Very general technique •Tested, free: www.metaobject.com

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend