Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

Re: Question about Initialization Cells

  • To: mathgroup at smc.vnet.net
  • Subject: [mg126409] Re: Question about Initialization Cells
  • From: Alexei Boulbitch <Alexei.Boulbitch at iee.lu>
  • Date: Tue, 8 May 2012 04:10:41 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

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 at iee.lu<mailto:alexei.boulbitch at iee.lu>








  • Prev by Date: Re: Typesetting built-in functions without evaluating
  • Next by Date: Re: Norm, Normalize and column vectors
  • Previous by thread: Re: Question about Initialization Cells
  • Next by thread: webMathematica and Histogram3D