"I have a mind like a steel... uh... thingy." Patrick Logan's weblog.

Search This Blog

Monday, November 01, 2004

Smalltalk and Predicate Dispatch

Danny Ayers writes about implementing Predicate Dispatch or Selective Inheritance in Smalltalk. The concern is the level of detail (VM?) required. Method Wrappers might be the best level of attack, at least initially.


PJE said...

FYI, there's a prototype Python implementation of predicate dispatch; see the announcement at:

http://www.eby-sarna.com/pipermail/peak/2004-July/001598.htmlIt uses the Chambers and Chen dispatch algorithm, with some modifications to handle Python's more-dynamic nature, and with some extensions of my own to index range and equality tests rather than treating them as opaque boolean tests. It also supports pluggable method combination (ala CLOS method combining), but there's only one or two simple combiners implemented.

verbat said...

the python impl seem quite interesting, thanks for sharing. BTW, did you actually put it in it's own pkg?
Also, reading the msg it seem you're going to parse a string.. can't you simply connect functions like:

def do_something(x,y):


PJE said...

It's going to go in its own package eventually; see:

http://www.eby-sarna.com/pipermail/peak/2004-November/001903.htmlAs for the reasoning behind parsing, it's to support indexing and optimization that would be *much* harder to do using functions. For example, equality tests and range tests are indexed. Also, 'expr in TypeOrProtocol' is equivalent to '@' in other predicate dispatch syntaxes. Finally, common subexpressions are recognized between different cases, and computed only once per dispatch. Really, when it comes down to it, my choices were to make people use a bunch of Lisp-like invocations of primitive functions and objects, or just create a parser.

Note that the parsing takes place at function *definition* time, and a partial index gets updated as each case is added. A final dispatch DAG (see the Chambers and Chen paper) is built lazily at dispatch time based on the current state of the master indexes.

Anyway, the point is that I wanted to have something that was very readable; how can you do better than using Python syntax, if what you're expressing are Python conditions? Since Python doesn't have an "AST literal" type, strings are the next best thing.

verbat said...

thanks for taking time to explain. Anyway notice that My sample was a simple mock up with the pie-decorator syntax, I understood it was at definition time :)

Blog Archive

About Me

Portland, Oregon, United States
I'm usually writing from my favorite location on the planet, the pacific northwest of the u.s. I write for myself only and unless otherwise specified my posts here should not be taken as representing an official position of my employer. Contact me at my gee mail account, username patrickdlogan.