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

MathGroup Archive 2010

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

Search the Archive

Re: Context Problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109421] Re: Context Problem
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Mon, 26 Apr 2010 07:32:23 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

BeginPackage["PackageContext`"];
Rule1::usage = "Rule1 is a test exported rule.";
Begin["`Private`"];
Rule1 = Cos[x_]^2 + Sin[x_]^2 -> 1;
End[];
EndPackage[];

ToExpression[
 StringReplace[ToString[InputForm[Rule1]], 
  "PackageContext`Private`" -> ""]]

Sin[x_]^2 + Cos[x_]^2 -> 1


Bob Hanlon

---- David Park <djmpark at comcast.net> wrote: 

=============
I would like to export rules from a package in such a way that the pattern
symbols did not include any contexts and in which I also did not have to
export the symbols used in the pattern. In addition, If possible, I would
like this to work even if the package was loaded from a notebook that had
something other than the Global` context.

 

Here is a sample package and exported rule:

 

BeginPackage["PackageContext`"];  

 

Rule1::usage = "Rule1 is a test exported rule.";  

 

Begin["`Private`"]; 

 

Rule1 = Cos[x_]^2 + Sin[x_]^2 -> 1; 

 

End[];  

 

EndPackage[]; 

 

Then, if we evaluate Rule1 we obtain a very clumsy version of the rule,
although I suppose it will work. 

 

Rule1 

Cos[PackageContext`Private`x_]^2 + Sin[PackageContext`Private`x_]^2 ->  1

 

What I would like is the rule as written in the package. Is there a way to
do this?

 

 

David Park

djmpark at comcast.net

 <http://home.comcast.net/~djmpark> http://home.comcast.net/~djmpark/  




  • Prev by Date: 3D visulaisation of 3D matrix for a 3D CA
  • Next by Date: Re: Context Problem
  • Previous by thread: Re: Context Problem
  • Next by thread: Re: Context Problem