I downloaded the source code for a Wolfram Demonstrations Project; this one:
http://demonstrations.wolfram.com/ComparingAlgorithmsForTheTravelingSalesmanProblem/
The first three cells, all initialization cells, each contain a simple
one-liner, for example:
dist[p1_, p2_] := Norm[p1 - p2]
When I evaluate any of these cells, it appears to define the function, but
when I try (in a second, new notebook window) to evaluate the function
(e.g., to evaluate "dist[4.5]}), the function is undefined. It is blue i
the second window, even though it is black in the first window.
But If I type "dist[4,5]" in the demonstration project window itself, all
works as expected.
The demo project does not appear to be a package; 'dist' does not seem to
be private. What am I missing?
|
|
0
|
|
|
|
Reply
|
james4271 (10)
|
5/5/2012 8:16:14 AM |
|
Evaluate the following in the notebook:
Options[EvaluationNotebook[], CellContext]
If the result is
{CellContext -> Notebook}
then that means that the notebook has been set so that any function
defined in it is defined in a Context unique to that notebook. If so,
then those functions will not be in the context path for Mathematica
to find them in another notebook and would need to be called there by
their full context path.
--David
On May 5, 4:16 am, James Stein <ja...@stein.org> wrote:
> I downloaded the source code for a Wolfram Demonstrations Project; this one:http://demonstrations.wolfram.com/ComparingAlgorithmsForTheTravelingS...
>
> The first three cells, all initialization cells, each contain a simple
> one-liner, for example:
> dist[p1_, p2_] := Norm[p1 - p2]
> When I evaluate any of these cells, it appears to define the function, but
> when I try (in a second, new notebook window) to evaluate the function
> (e.g., to evaluate "dist[4.5]}), the function is undefined. It is blue i
> the second window, even though it is black in the first window.
>
> But If I type "dist[4,5]" in the demonstration project window itself, all
> works as expected.
>
> The demo project does not appear to be a package; 'dist' does not seem to
> be private. What am I missing?
|
|
0
|
|
|
|
Reply
|
dbreiss (537)
|
5/8/2012 8:07:27 AM
|
|
I downloaded the source code for a Wolfram Demonstrations Project; this one:
http://demonstrations.wolfram.com/ComparingAlgorithmsForTheTravelingSalesmanProblem/
The first three cells, all initialization cells, each contain a simple
one-liner, for example:
dist[p1_, p2_] := Norm[p1 - p2]
When I evaluate any of these cells, it appears to define the function, but
when I try (in a second, new notebook window) to evaluate the function
(e.g., to evaluate "dist[4.5]}), the function is undefined. It is blue in
the second window, even though it is black in the first window.
But If I type "dist[4,5]" in the demonstration project window itself, all
works as expected.
The demo project does not appear to be a package; 'dist' does not seem to
be private. What am I missing?
The function, dist[p1,p2] that you describe here has two variables according to definition. Mathematica distinguishes functions not only by their heads (i.e. the name "dist"), but also by the number of variables. For Mathematica, therefore, the functions dist[1,2] and dist[1] are two absolutely different functions. In your case the first of them is already defined, but not the second. Finally 4.5 is for Mathematica one rational number equal to four and a half, rather than two numbers. Thus, Mathematica understands dist[4.5] as a new, yet undefined function of a one variable.
Have fun, Alexei
Alexei BOULBITCH, Dr., habil.
IEE S.A.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG
Office phone : +352-2454-2566
Office fax: +352-2454-3566
mobile phone: +49 151 52 40 66 44
e-mail: alexei.boulbitch@iee.lu<mailto:alexei.boulbitch@iee.lu>
|
|
0
|
|
|
|
Reply
|
Alexei.Boulbitch (367)
|
5/8/2012 8:13:04 AM
|
|
That's something good to know: from time to time there have been posts
to this list asking about how to arrange exactly the same restriction --
typically by somebody used to another CAS system and expecting
definitions in one notebook, by default, to be confined to that
notebook's context.
On 5/8/12 4:06 AM, David Reiss wrote:
> Evaluate the following in the notebook:
>
> Options[EvaluationNotebook[], CellContext]
>
> If the result is
>
> {CellContext -> Notebook}
>
> then that means that the notebook has been set so that any function
> defined in it is defined in a Context unique to that notebook. If so,
> then those functions will not be in the context path for Mathematica
> to find them in another notebook and would need to be called there by
> their full context path.
>
> --David
>
>
> On May 5, 4:16 am, James Stein<ja...@stein.org> wrote:
>> I downloaded the source code for a Wolfram Demonstrations Project; this one:http://demonstrations.wolfram.com/ComparingAlgorithmsForTheTravelingS...
>>
>> The first three cells, all initialization cells, each contain a simple
>> one-liner, for example:
>> dist[p1_, p2_] := Norm[p1 - p2]
>> When I evaluate any of these cells, it appears to define the function, but
>> when I try (in a second, new notebook window) to evaluate the function
>> (e.g., to evaluate "dist[4.5]}), the function is undefined. It is blue i
>> the second window, even though it is black in the first window.
>>
>> But If I type "dist[4,5]" in the demonstration project window itself, all
>> works as expected.
>>
>> The demo project does not appear to be a package; 'dist' does not seem to
>> be private. What am I missing?
>
>
--
Murray Eisenberg murray@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305
|
|
0
|
|
|
|
Reply
|
murray (1862)
|
5/9/2012 7:52:58 AM
|
|
|
3 Replies
30 Views
(page loaded in 0.174 seconds)
Similiar Articles: LPT initialization - comp.soft-sys.matlab... MATLABVersion: '7.8 (R2009a)' InstalledAdaptors: {2x1 cell ... MPI beginners question - comp.parallel.mpi LPT initialization - comp.soft-sys.matlab MPI beginners question ... How to run Mathematica nb file in command line in windows? - comp ...... Post Question | Groups ... Hello Timedcy: I thought if you make all of the cells into "initialization" cells. Array of something - comp.lang.java.help... Hi, I am defining a `Tableau' array of `Cell ... You need a intro textbook to answer such questions. ... Usage of an array variables in initialization list - comp ... NIDAQ dll error - comp.soft-sys.matlab... Post Question | Groups ... A dynamic link library (DLL) initialization routine failed. ... Dev1' 'Dev2'} ObjectConstructorName: {2x3 cell ... Dot notation in struct - comp.lang.cYou cannot use this form of initialization for members in ... Global Variable vs Struct Variable Question - comp.lang ... Looking at the Structure of Cells in the Microscope ... Expression templates and array indexing - comp.lang.c++.moderated ...... Post Question | Groups ... Bitwise copy during aggregate initialization (a compiler bug?) ... Find elements in a cell array and index ... //In our ... Forcing matlab to print underscore as it is - comp.soft-sys.matlab ...... Post Question | Groups | Stream ... Hello everybody, I am trying to print a filename on a plot title but the file ... changing size of array - comp.soft-sys.matlab... Post Question | Groups ... rows by 300 columns What is ... way is to use a cell ... array object, obtained once during loop initialization, and an ... Matlab GUI bar graph with different colors and stacked - comp.soft ...... by GUIDE v2.5 19-Jun-2010 16:01:43 % Begin initialization ... hObject, eventdata, handles) % varargout cell ... bar and barseries question: how to change color of ... data structures on shared memory? - comp.unix.programmer ...... nested on my structure to use the memory cells ust ... en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization ... If it happens like this my question is, why is there a ... ios - UITableView cells not nil at initialization - Stack OverflowDid you create cell(s) with the identifier @"SearchResultCell" elsewhere in your code (in a separate class, for instance)? – titaniumdecoy Apr 21 at 0:00 front end - How to make a parallel auto-generated .m package from ...according to the documentation at ref/InitializationCell, When you first save a notebook that contains initialization cells, you have the option to make a parallel ... 7/8/2012 11:15:43 PM
|