Fun with decorators and unification dispatch

Paul Rubin http
Sun Sep 11 02:26:43 CEST 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