Discussion: new operators for numerical computation

Michael Hudson mwh21 at cam.ac.uk
Wed Aug 2 03:21:40 EDT 2000


Greg Ewing <see at my.signature> writes:

> Edward Jason Riedy wrote:
> > 
> > Assume the generic function route to multiple dispatch...
> 
> I'm going to need a concrete example before I can see
> how this works out. Suppose there is a type Wibble
> and module Frobulation which provides a generic
> function frobulate(x,y) and a method frobulate(Wibble,Wibble).
> 
> In module Frisbee, I import Frobulation and proceed
> to frobulate some Wibbles. 
> 
> Now someone creates a class SuperWibble which inherits from
> Wibble, and defines a method frobulate(SuperWibble, SuperWibble). 
> Nobody tells me this, and I don't make any changes to what Frisbee
> imports. But one day someone passes me some SuperWibbles
> and I try to frobulate them.
> 
> What happens? Does frobulate(SuperWibble, SuperWibble)
> get called? 

I'd have thought so.

> If so, how do I know this, and how do I know where to look for its
> definition?

Not sure; maybe generic functions would themselves have a member
function "get_most_applicable_method" or something (which would return
a Python function).

WRT the "how do I know" question, do you care?  Surely the point of
generic functions is that they're extensible ... how often do you
check whether the instance you've been passed is an instance of a
specific class and not merely an instance of a subclass?

> If it doesn't get called (i.e. I have to import the
> specific method from somewhere) it doesn't seem much
> more useful than static overloading.
> 
> > How is this significantly more painful than the object factory pattern?
> 
> The factory has control over what kinds of objects it creates,
> and those objects in turn have control over what operations
> can be done with them. But with generic functions and
> multimethods, it seems like anyone anywhere can change the
> meaning of anything anywhere else. That makes me uneasy.

The CLOS & Dylan people seem to cope.

I still can see it fitting into Python, but if I found a way, I'd be
pushing for it as hard as I can.

Cheers,
M.

-- 
  Some people say that a monkey would bang out the complete works
  of Shakespeare on a typewriter give an unlimited amount of time.
  In the meantime, what they would probably produce is a valid
  sendmail configuration file.                    -- Nicholas Petreley



More information about the Python-list mailing list