Message Boards Message Boards

0
|
2534 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Different behavior of Switch when moved inside a package?

Posted 1 year ago

The following code runs as intended in Mathematica, but always runs the switch default value when moved into a package. Is there a problem with using a list as a switch argument in the Wolfram Language? Is there a more appropriate way to write this code for a Mathematica package?

DebugSwitch[{classification_,algorithm_}]:= Module[{},
   Echo[{classification,algorithm}];
   Switch[{classification,algorithm},
         {Parabolic,Native}, Echo["NativeParabolic[f,n,z,p,4]"],
         {Hyperbolic,Native}, Echo["NativeHyperbolic[f,n,z,p,4]"],
         {Parabolic,Symbolic}, Echo["SymbolicParabolic[f,n,z,p,4]"],
         {Hyperbolic,Symbolic}, Echo["SymbolicHyperbolic[f,n,z,p,4]"],   
         _, Echo["Symbolic[f,n,z,p,4]"]
      ]; 
  ]
POSTED BY: Daniel Geisler
2 Replies

Thank you Eric, I published all my symbols as you suggested and now the code works.

POSTED BY: Daniel Geisler
Posted 1 year ago

I suspect that this is a problem with the actual full names of your symbols Parabolic, Native, and so forth. How exactly did you move it "into a package"? If you used BeginPackage and then Begin to set a private context, then it's possible that your symbol Parabolic (as one example) actually has a full name something like Test'Private'Parabolic (those apostrophes should actually be backticks). In that case, you won't be able to access that symbol directly from the Global context unless you use its fullname.

The typical way to deal with this is to "publish" all the symbols you need the user to have access to by referencing them after BeginPackage and before Begin. You could also just always use a fully qualified name for each of these symbols.

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract