Fun with decorators and unification dispatch

Paul Rubin http
Sat Sep 10 20:26:43 EDT 2005


"talin at acm dot org" <viridia at gmail.com> writes:
> # Declare that "Factor" is a generic function
> Factorial = Function()

Was the comment a typo for Factorial?

> # Define Factorial( 0 )
> @Arity( 0 )
> def Factorial():
>     return 1

Overriding old definition of Factorial

> # Define Factorial( x )
> @Arity( MatchInteger.x )
> def Factorial( x ):
>     return x * Factorial( x - 1 )

Overriding it again

> print Factorial( 12 )

I'm confused, how did it know what to do?  Are you using some reflection
hack in the MatchInteger decorator to figure out the function name?



More information about the Python-list mailing list