[PEAK] generic functions question
Phillip J. Eby
pje at telecommunity.com
Thu Nov 18 12:54:21 EST 2004
At 06:14 PM 11/18/04 +0200, Vladimir Iliev wrote:
>Hi,
>
>I have an use case like this:
>
>import dispatch
>[dispatch.generic()]
>def f(arg):
> ''
>[f.when("arg == 'blabla'")]
>def f1(arg):
> print 1
>[f.when("arg != 'blabla'")]
>def f2(arg):
> print 2
>f('blabla')
>f('lala')
>
>it works just well, but I wonder is there a way to register f2() as
>default/fallback func ?
For now, use this:
from dispatch.strategy import Signature
default = Signature() # empty test
[f.when(default)]
# etc.
It's a bit awkward, so I'm considering having some better way to express
this. You could use 'f.when("True")', except that it would then be
considered ambiguous when any other guard expression is true, because the
system doesn't "know" that a constant truth value is implied by any true
expression, and that therefore the other expression has precedence.
More information about the PEAK
mailing list