Module and database combined
- To: mathgroup at smc.vnet.net
- Subject: [mg48237] Module and database combined
- From: Goyder Dr HGD <h.g.d.goyder at cranfield.ac.uk>
- Date: Wed, 19 May 2004 02:42:14 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
What is the best way of mixing modules and databases so that one can
preserve the flexibility of data structures in a database and avoid the
clash of symbols as provided by a module?
Below is an example where I first construct a database in the global
environment where data may be added and withdrawn with no difficulty.
I then try to read the database into a module but, quite correctly, the
module prevents access to the data by setting up unique symbols.
The problem gets worse if an attempt is made to generate a unique database
within a module and then to work with this database in other modules.
In[18]:=
DataBase[theNumber] = 1;
DataBase[theRule] = PlotRange -> {{0, 1}, {0, 1}};
DataBase[theList] = {1, 2, 3};
In[21]:=
{DataBase, DataBase[theNumber], DataBase[theRule], DataBase[theList]}
Out[21]=
{DataBase, 1, PlotRange -> {{0, 1}, {0, 1}}, {1, 2, 3}}
In[22]:=
f[db_] := Module[{theNumber, theRule, theList}, p = {db, db[theNumber],
db[theRule], db[theList]}; Print[p]]
In[23]:=
f[DataBase]
Out[23]:=
{DataBase, DataBase[theNumber$17], DataBase[theRule$17],
DataBase[theList$17]}
In[24]:=
g := Module[{DataBase, theNumber, theRule, theList}, DataBase[theNumber] =
10;
DataBase[theRule] = PlotRange -> {{10, 20}, {10, 20}}; DataBase[theList]
= {10, 20, 30}; f[DataBase]]
In[25]:=
g
Out[25]:=
{DataBase$18, DataBase$18[theNumber$19], DataBase$18[theRule$19],
DataBase$18[theList$19]}
As may be seen the unique number given to the database and to the other
symbols by a module correctly prevents a clash of symbols. However, I want
to withdraw data from a database within a module environment, use it within
a module and not change global values. How do I do this?
Hugh Goyder
--
This message has been scanned for viruses and
dangerous content by the Cranfield MailScanner, and is
believed to be clean.