[Twisted-Python] Generic functions using PyProtocols (was Re: Components)

Christopher Armstrong radix at twistedmatrix.com
Sat Feb 28 00:21:05 EST 2004


Phillip J. Eby wrote:
> At 09:58 AM 2/27/04 -0500, Phillip J. Eby wrote:

>> At 12:40 AM 2/27/04 -0500, Glyph Lefkowitz wrote:
>> Not at the moment.  What I'd like to do at some point is add 
>> single-dispatch generic functions, though.
> 
> Just for the heck of it, I thought I'd try whipping up a single-dispatch 
> generic function using PyProtocols.  It turned out to be much easier 
> than I thought; only 19 lines, in fact!

> # Quick test/demo
...

> def gA(ob):
>     print ob, "is an A"
> g.add(gA,[A])
> def gB(ob):
>     print ob, "is a B"
> g.add(gB,[B])

Wow. glyph explained to me what he wanted before with the 
no-instantiation IFoo.meth(x), but I didn't realize that it really _is_ 
like generic functions. That's awesome. :-)

-- 
  Twisted | Christopher Armstrong: International Man of Twistery
   Radix  |          Release Manager,  Twisted Project
---------+           http://radix.twistedmatrix.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20040228/705dd4bc/attachment.pgp 


More information about the Twisted-Python mailing list