Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: shadow warning with function parameters and local

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105024] Re: [mg104994] shadow warning with function parameters and local
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Wed, 18 Nov 2009 06:58:48 -0500 (EST)
  • References: <200911171013.FAA17202@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

Either of these strategies eliminates the shdw message:

BeginPackage["a`"];
Test1[t_] := Block[{v = t + 1}, t + v];
EndPackage[];
BeginPackage["b`"];
Test2[t_] := Block[{v = t + 2}, t + v];
EndPackage[];

or

BeginPackage["a`"];
Test1[t_] := Block[{a`Private`v = t + 1}, t + v];
EndPackage[];
BeginPackage["b`"];
Test2[t_] := Block[{b`Private`v = t + 2}, t + v];
EndPackage[];

but a more complete solution is

BeginPackage["a`"];
Test1::usage = "anything";
Begin["`Private`"];
Test1[t_] := Block[{v = t + 1}, t + v];
End[];
EndPackage[]

BeginPackage["b`"];
Test2::usage = "anything";
Begin["`Private`"];
Test2[t_] := Block[{v = t + 2}, t + v];
End[];
EndPackage[]

Variables created in the Private context don't shadow, and usage messages  
export what you need for use outside the package.

Bobby

On Tue, 17 Nov 2009 04:13:52 -0600, brien colwell <xcolwell at gmail.com>  
wrote:

> hi all,
>
> I have a set of fairly complex packages. Frequently I use the same
> variable names in function definitions and local modules across many
> packages. Sometimes I see this type of warning:
>
>     <varname>::shdw : Symbol <varname> appears in multiple contexts {*};
> definitions in context * may shadow or be shadowed ...
>
> This does not happen with symbols in the package context (already
> fixed); it happens only with function parameters and variables in local
> modules. I can recreate the warning with the following code snippet. It
> seems to me that the variable 'v' should be safely local to each module.
> Is there really a symbol conflict to worry about here?
>
> thanks,
> Brien
>
>
> In[1]:=
> BeginPackage["a`"];
> Test1[t_] := Module[{v = t + 1}, t + v];
> EndPackage[];
> BeginPackage["b`"];
> Test2[t_] := Module[{v = t + 2}, t + v];
> EndPackage[];
>
> Out[1]:=
> v$::shdw: Symbol v$ appears in multiple contexts {b`,a`}; definitions in
> context b` may shadow or be shadowed by other definitions. >>
>
>
>
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: shadow warning with function parameters and local module variables
  • Next by Date: Re: Re: Mathematica skill level snippet(s)
  • Previous by thread: shadow warning with function parameters and local module variables
  • Next by thread: Re: shadow warning with function parameters and local module variables