[Python-3000] Discussions with no PEPs

Phillip J. Eby pje at telecommunity.com
Tue Mar 13 16:06:46 CET 2007


At 10:16 AM 3/13/2007 -0400, Barry Warsaw wrote:
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>On Mar 13, 2007, at 10:12 AM, Nick Coghlan wrote:
>
> > Generics can live quite happily inside modules and as methods on
> > objects.
> >
> > The important aspect is the ability to tell the generic function
> > "here's how to frobnicate a doodad", even though the basic
> > frobnicator knows nothing about doodads, and doodads know nothing
> > about frobnicating. That machinery can be designed to work for any
> > callable.
>
>Are generics then just a way of doing adaptation on a per-function
>basis rather than a per-object basis?

I prefer to think of adaptation as being a way to provide a namespace for 
generic functions.  :)

See http://mail.python.org/pipermail/python-3000/2006-November/004717.html 
for an implementation of this idea.  Basically, you define an interface by 
creating generic functions in the body of an 'Interface' subclass...  and 
the resulting Interface can then  be used to adapt any object to it.  The 
26 lines of code I gave can be used are not specific to any particular 
generic function implementation, so they could be used with simplegeneric, 
RuleDispatch, PEAK-Rules, Guido's prototype, or anything else you might 
come up with.



More information about the Python-3000 mailing list