RE: Contexts and Naming of Things
- To: mathgroup at smc.vnet.net
- Subject: [mg25739] RE: [mg25691] Contexts and Naming of Things
- From: "David Park" <djmp at earthlink.net>
- Date: Sat, 21 Oct 2000 14:42:49 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Mike, {foo[x, HSSV`cavity`Private`bar], foo[x, HSSV`cavity`Private`nebbish]} {1, 2} But you probably want to do your package this way: BeginPackage["HSSV`cavity`"] foo::usage = "now is the time..."; bar::usage = "A control parameter for foo"; nebbish::usage = "A control parameter for foo"; Begin["`Private`"] foo[x_, y_] := 1 /; y === bar; foo[x_, y_] := 2 /; y === nebbish; End[] EndPackage[] {foo[x, bar], foo[x, nebbish]} {1, 2} Or you could also do this: BeginPackage["HSSV`cavity`"] foo::usage = "now is the time..."; Begin["`Private`"] foo[x_, y_] := 1 /; y === Global`bar; foo[x_, y_] := 2 /; y === Global`nebbish; End[] EndPackage[] {foo[x, bar], foo[x, nebbish]} {1, 2} David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ > -----Original Message----- > From: Mike Yukish [mailto:may106 at psu.edu] To: mathgroup at smc.vnet.net > I have the following code which does not work as I had hoped. I first > declare a function in a package... > > BeginPackage["HSSV`cavity`"] > foo::usage = "now is the time..." > Begin["`Private`"] > bar; > nebbish; > foo[x_, y_] := 1 /; y === bar; > foo[x_, y_] := 2 /; y === nebbish; > End[] > EndPackage[] > > And then try to run the following simple commands... > > foo[1, bar] > foo[1, cavity`bar] > foo[1, HSSV`cavity`bar] > > I had thought that the first one would have given me the correct answer, > as it works OK when I do not embed the function definition in a package. > The others were desperate second efforts that also failed. What am I > missing here? > > > > > >