MathGroup Archive 2009

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

Search the Archive

Re: User Defined Global Variables - How to do it?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg95397] Re: User Defined Global Variables - How to do it?
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Sat, 17 Jan 2009 05:31:27 -0500 (EST)

On 1/16/09 at 6:07 AM, donabc at comcast.net (Donald DuBois) wrote:

>I am trying to define my own global variables which will be known to
>every function that I write just  like the system global variable
>"$HomeDirectory".  I have a function which has been written to read
>values from a disk file and using those values calculate the values
>of the global variables.

>I do not know where to put this fuhction so that, at the begiinning
>of a Mathematica session, these user defined global varialbes are
>available to be used by any function that I have written that is
>part of the packages that are autmatically loaded at the beginning
>of a session.

>I have previously defined my own global variables in a file called
>init.m and this file is located in directory:

>C:\Documents and Settings\Donald\Application
>Data\Mathematica\Autoload\Foo

<snip>

>(1) I don't know how
>to make these values globally available to all other functions that are us=
ed
>in the session and that are defined in the packages I created.

You can put any valid Mathematica code in an init.m file. There
is no restriction on the number of lines of code or the
complexity of the code put into the init.m files. However, it
should be obvious a very lengthy computation place in an init.m
file will mean an equivalently long start up time for any
Mathematica session.

>(2) I don't know how to get this function [the function which calculates t=
he values
>of the global variables) to "start up" automatically BEFORE I ever have to
>hit the first Shift + Enter.  This function which calculaes the values of =
global variables uses itself some of the other functions I defined in the p=
ackages I created which are automatically loaded at session start time.

You should realize there is more than one init.m file where
things can be put. In particular, there is an init.m file in the
directory returned by:

ToFileName[$UserBaseDirectory,"Kernel"]

code in this file will load and run *before* any thing in the
autoload directory is loaded. If you put your functions in this
file you should get the result you want.



  • Prev by Date: Re: Which editor do you use for math articles
  • Next by Date: Re: webMathematica - comments, opinions, user group (?)
  • Previous by thread: User Defined Global Variables - How to do it?
  • Next by thread: Trivial question