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


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

Re: Question about Initialization Cells

Started byAlexei Boulbitch <Alexei.Boulbitch@iee.lu>
First post2012-05-08 08:13 +0000
Last post2012-05-08 08:13 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

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

#9992 — Re: Question about Initialization Cells

FromAlexei Boulbitch <Alexei.Boulbitch@iee.lu>
Date2012-05-08 08:13 +0000
SubjectRe: Question about Initialization Cells
Message-ID<joakig$nji$1@smc.vnet.net>
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>





[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web