Putting the same function name in multiple modules.
- To: mathgroup at smc.vnet.net
- Subject: [mg54779] Putting the same function name in multiple modules.
- From: Josef Karthauser <joe at tao.org.uk>
- Date: Tue, 1 Mar 2005 01:58:41 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
I'm trying to do a bit of "object orientation" with a number of modules and was wondering what the official way of doing it was. Imagine that I've got a couple of data types defined. Let us call them FooA[] and FooB[]. Each has it's own module, so that I can do something like: Needs["`FooA`"]; Needs["`FooB`"]; What I want is a function that can operate on both types, i.e. Doit[x_FooA] := ... and Doit[x_FooB] := ... and would like to define each of these in the relevant module. I would normally do something like: Module[... FooA ...] Doit::usage = "...."; Begin["`Private`"]; Doit[x_FooA] := ...; End[]; and Module[... FooB ...] Doit::usage = "...."; Begin["`Private`"]; Doit[x_FooB] := ...; End[]; Of course doing it this way each of the Doit[] functions is defined in a different context and so one of them gets overriden by the other. Does anyone know how I can fix things so that I can say make a FooC module and define a Doit[x_FooC] in it without having to change the FooA and FooB modules to accomodate it. Thanks, Joe -- Josef Karthauser (joe at tao.org.uk) http://www.josef-k.net/ FreeBSD (cvs meister, admin and hacker) http://www.uk.FreeBSD.org/ Physics Particle Theory (student) http://www.pact.cpes.sussex.ac.uk/ ================ An eclectic mix of fact and theory. =================