Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Re: Example straight from the book does not work' topicStudent Support Forum > General > Archives > "Re: Example straight from the book does not work"

Help | Reply To Topic
Author Comment/Response
Forum Moderator
email me
01/24/97 12:40pm

Reply to message #57 from Stephen R. Samms: > In[1]:= > <<Statistics`DescriptiveStatistics`;
> Mean[{5,4,3}] > > Mean::''shdw'': > ''Symbol \!\(\''Mean\''\) appears
in multiple contexts \ > \!\({\''Statistics`DescriptiveStatistics`\'',
\''Global`\''}\); definitions in \ > context \!\(\''Statistics`DescriptiveStatistics`\''\)
may shadow or be shadowed \ > by other definitions.'' > > Out[1]= >
Mean[{5,4,3}] > Stephen, The first part of this is not meant to slam
your note. Rather I am making suggestions for improving submissions
which will reduce turn around time. ====================================
Some notes to all Forum readers regarding Forum submissions: When
referring to an example in the documentation, please include the name
of the book (the book mentioned in the message title could be any
edition of the Mathematica Book, the Student Book, or the Standard
Packages books) and a page reference. That will save time and encourage
others to answer your question. If you are showing the results from
a session, please show as much of the session as is relevant and practical.
Stephen did this. Include what version of Mathematica you are using
and what kind of machine and system you are running Mathematica under.
The readers of the Forum do not have access to a way to find this
out independently. The reply to this question revolves a bit around
this issue as is often the case. Finally, I encourage each of your
to submit replies to any question. This site is intended as a forum
and several of you have already posted replies that are just as good
as any I could submit. At times your replies will add the new user/outside
of Wolfram perspective that we at Wolfram can not provide. ====================================
Now for the reply. From the fact that you found this example in a
book on Mathematica yet evaluated it in V3.0, makes me suspect that
the book was written for an earlier version of Mathematica. If you
found this example in a Version 3.0 based book, please let us know.
I put your question to one of our developers. Here is his response:
---------------------- The behavior of <<Statistics`DescriptiveStatistics`;
Mean[{5,4,3}] in a single input cell will depend on the format type
of the cell. To desribe this difference, it is necessary to recall
that input is processed in two stages: first the input is read (parsed)
to construct an expression, and after that, the expression is evaluated.
Symbols are created in the first stage, when the input is parsed.
The package will be loaded in the second stage, when the input is
evaluated. If this input cell is parsed all at once, and then evaluated
all at once, the symbol Mean will be created before the package is
loaded, and you will get a message about a shadowed symbol. This is
what happens when the format type of the cell is StandardForm or TraditionalForm,
which are the two format types that have been added for Version 3.0.
If the first line in this input cell is parsed and evaluated before
the second line is parsed and evaluated, then the package will be
loaded and the symbol Mean will be created in the proper context before
the second line parsed, so there will be no problem with shadowing.
This is what happens when the format type of the cell is InputForm.
InputForm is the only format type that was was available in Version
2.2. This is not considered a bug. My personal opinion is that it
is bad programming style to take advantage of the idiosyncracies of
the system to put more than one distinct expression into a single
cell, especially into a typeset cell. ----------------------------
So, to make this example work as it does in the book you are using,
you either need to convert the cell to InputForm (using the Cell menu)
or put the two lines in a separate cell. Tom Zeller Forum Moderator


URL: ,
Help | Reply To Topic