Re: Putting the same function name in multiple modules.
- To: mathgroup at smc.vnet.net
- Subject: [mg54790] Re: Putting the same function name in multiple modules.
- From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
- Date: Wed, 2 Mar 2005 01:26:37 -0500 (EST)
- Organization: Uni Leipzig
- References: <firstname.lastname@example.org>
- Sender: owner-wri-mathgroup at wolfram.com
Hi, set the context explicit ? Something like Begin["`Private`"]; Global`Doit[x_FooA] := ...; End; and in the second context Begin["`Private`"]; Global`Doit[x_FooB] := ...; End; Regards Jens "Josef Karthauser" <joe at tao.org.uk> schrieb im Newsbeitrag news:d0154m$ovc$1 at smc.vnet.net... > > 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. ================= >