Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

Context Woes (questions!) in application design...

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115731] Context Woes (questions!) in application design...
  • From: Jason Ledbetter <jasonbrent at gmail.com>
  • Date: Wed, 19 Jan 2011 05:28:32 -0500 (EST)

(sorry for the length...)

Folk,

I'm looking for pointers on general design principles for Context management
in mathematica applications.

The workflow I'm looking to enable is:

1) user loads base package: <<myPackage`
2) The init.m for myPackage sets up some shared data in Global` context,
like SQL connection pool and manages clean shutdown on exit ($Epilog, etc).
3) From the same notebook step 1 was run in, a function is run that opens a
new, custom notebook: foo[].

"foo" is defined in the Private` section of myPackage` and exported in the
public section with a usage statement.

4) The notebook that is opened via foo[] has a custom-ish UI using a docked
cell that I'll call "system1".
5) user enters some data in the customUI and data is populated in that
notebook via SQL queries/etc that analytically describes attributes of a
physical system "system1". A palette based toolbar for running pre-defined
functions can be opened from the docked Cell and all output goes to the
"system1" notebook.

That functionality basically works as I'm expecting...

However, this model breaks when another "instance" of "foo[]" is run. An
additional notebook is opened and variables are basically isolated, however
data sharing between unique notebooks is somewhat difficult.

I was thinking that the solution would be to specify a custom CellContext
when the notebook was created via the foo[] function.

And this is where I begin to lose comprehension of M and Contexts...

In the notebook I ran "foo[]" from, $ContextPath still shows the full path I
expected, e.g., DatabaseLink, myPackage, etc.However, In the notebook
created by "foo[]", shows a $ContextPath of JUST the specific CellContext I
set and "System`". According to the documentation, $ContextPath is a global
variable. According to my two notebooks, both are referring to
System`$ContextPath.

So how do they each have a unique value?

My thought was to somehow specify $ContextPath as well as CellContext when I
create the new notebook via the "foo[]" function.. but I can't figure that
part out.

(ultimately my thinking is by using Cases, Contexts[], Names[], etc I can
"manage" data cleanup, data sharing, isolate unique instances by looking at
myPackage`instances`, etc...)

Questions:

A) Is there a simpler way?
B) Is there a solution to programmatically specifying $ContextPath on a
created notebook (InitializationCell doesn't seem to do it because as best I
can tell it doesn't autorun)?
C) How can what is apparently a global variable ($ContextPath) have two
different values? (As best I can tell, I'm only running 1 instance of M on
my machine).

Thanks,

-jbl


  • Prev by Date: Re: Using FindRoot on an equation involving Log terms
  • Next by Date: Re: Array of arrays of various sizes and compile
  • Previous by thread: The new (v.8.0) distribution plots using a numerical or date labeled X-axis
  • Next by thread: Re: Context Woes (questions!) in application design...