Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1997
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1997

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

Search the Archive

Re: Order of execution of initialization cells

  • To: mathgroup at smc.vnet.net
  • Subject: [mg8929] Re: [mg8884] Order of execution of initialization cells
  • From: David Withoff <withoff>
  • Date: Sat, 4 Oct 1997 22:08:07 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

> Using 3.0.1, consider the two commands:
>
> <<Calculus`VectorAnalysis`
> SetCoordinates[Cartesian[x,y,z]]
>
> Each of these is in its own cell, which is an Initialization Cell. I want
> to load the package and then change the coordinates from the default {Xx,
> Yy,Zz} to the more usual {x,y,z} (which incidentally were the default in
> 2.2). When the first cell is evaluated, what should happen?  After I
> indicate that I do want to evaluate all Initialization Cells, In[1] appears
> before the first command, then In[2] appears before the second command, and
> there is the expected output to the second command, and then In[3] appears
> before the first command, and then execution is complete.  But the
> coordinates have been set back to the default {Xx, Yy,Zz} instead of to
> {x,y,z}.  I've tried this both on a Mac and a Sparc, with the same result.
>
> It appears that the second command was executed before the first command
> was completed, and so was later overridden.  Shouldn't we expect the
> consecutive cells to be completely evaluated consecutively?  Why weren't
> they?  How can I make the Initialization Cells execute completely in the
> right order?   In general, when will Initialization Cells evaluate
> consecutively?

One way to determine the order in which the inputs were effectively
entered is to check ??In, which for your example will probably give

In[1] := << "Calculus`VectorAnalysis`"

In[2] := SetCoordinates[Cartesian[x, y, z]]

In[3] := << "Calculus`VectorAnalysis`"

I am guessing here that you selected the first cell (the cell that
contained <<Calculus`VectorAnalysis`) and asked for it to be evaluated
before you got the dialog box that asked whether or not to evaluate
the initialization cells.  The Calculus`VectorAnalysis` package was
loaded once when the initialization cells were evaluated, and a second
time during evaluation of the selected cell.  Reloading the package
reset the names of the coordinates.

To answer your questions, yes, you can expect that the cells would be
evaluated consecutively and completely during initialization.  That is
in fact what happens.  One way to evaluate the initialization cells
without evaluating anything else is to select "Evaluate Initialization"
from the Kernel/Evaluation menu.  In this example you could also avoid
the problem by using Needs["Calculus`VectorAnalysis`"] in place
of <<Calculus`VectorAnalysis`, or by selecting some other cell for the
first evaluation, so that the package doesn't get loaded a second time.

Dave Withoff
Wolfram Research


  • Prev by Date: Re: a[[2]][[3]] = 1 error? why?
  • Next by Date: Re: Piecewise functions
  • Previous by thread: Re: LabVIEW front end
  • Next by thread: Re: Order of execution of initialization cells