Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a Package I am writing, I'm trying to define a function with an Optional parameter in it that is set to a global variable.


However, the Optional value IndexLoopPlot is not set until after the package is loaded and other functions are run. Therefore PlotIndex is read in as,


In other words, IndexLoopPlotMtx is set to Null, and when the function is run later it tries to plot {} instead of the matrix IndexLoopPlot. Is there a way to get it delay setting the Default until the function is called for the first time from the package?

share|improve this question

migrated from Apr 12 '12 at 2:42

This question came from our site for people studying math at any level and professionals in related fields.

You'll have to point to the global variable using its full context path as Global`IndexLoopPlot. Otherwise, the optional variable will be interpreted as YourPackage`IndexLoopPlot. The following example shows how:

Quiet@Remove[a, "test`*"];
f[x_: Global`a] := {x}

enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.