Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #9992

Re: Question about Initialization Cells

From Alexei Boulbitch <Alexei.Boulbitch@iee.lu>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Question about Initialization Cells
Date 2012-05-08 08:13 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <joakig$nji$1@smc.vnet.net> (permalink)

Show all headers | View raw


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>





Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Question about Initialization Cells Alexei Boulbitch <Alexei.Boulbitch@iee.lu> - 2012-05-08 08:13 +0000

csiph-web