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