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

MathGroup Archive 2010

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

Search the Archive

Using 'Module' inside 'Compile'

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112152] Using 'Module' inside 'Compile'
  • From: "Scott D. Kasen" <sdk5n at virginia.edu>
  • Date: Thu, 2 Sep 2010 02:31:54 -0400 (EDT)

While I've worked with Mathematica for quite some time, I'm first 
learning the Compile function.  Keeping it brief...

Compile the function...

f1 = Compile[{},
   Module[{x, temp},
     x = 4.;
     If[3 > 2, temp = x; Print["temp in 'if' statement: ", temp]];
     Print["temp outside 'if' statement: ", temp];
     ];
   ];

Calling the function...

f1[]

Produces the following output:

temp in 'if' statement: 4.
temp outside 'if' statement: temp$3107

First, why does the function create a new local variable temp$3107 
outside of the 'If' statement?  Second, how can I bring the first value 
for "temp" outside of the if statement?

Thanks in advance,
Scott Kasen



  • Prev by Date: Using ChartStyle
  • Next by Date: Another question on ParallelDo
  • Previous by thread: Re: Using ChartStyle
  • Next by thread: Re: Using 'Module' inside 'Compile'