[PEAK] Dispatching without generic functions.

Gabriel Jägenstedt gabriel.j at telia.com
Tue Jul 25 06:33:16 EDT 2006


Hi!

I have a situation where I am trying to figure out how one would add
dispatches on a dispatch.generic function. Using the regular @drink.when
 and such proves easy enough and I thing I understand how to utilize the
befores and afters.

In a system built around components it might not be possible to use
generic functions since the target method that needs the functionality
may well be changed in the game.

import dispatch

@dispatch.generic()
def drink(n):
    """"""

@drink.when("n is 1")
def drink1(n):
    print 'You choose 1'

@drink.when("n is 2")
def drink2(n):
    print 'You choose 2'

def drink3(n):
    print 'You choose 3'

How would this last method be added to drink? The rule that should be
passed can easily be stored in a dictionary or list or tuple or whatever
but I don't know how to make it work.
What I am trying to do may well be an ugly hack but I feel that it is
either that or I scratch the idea of using dispatch all together since
it won't be flexible at all in a component driven system if you can't do
something like it.

Cheers



More information about the PEAK mailing list