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

MathGroup Archive 2007

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

Search the Archive

Compile forgets assigned values inside Do unless they are initialised

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82126] Compile forgets assigned values inside Do unless they are initialised
  • From: "Andrew Moylan" <andrew.j.moylan at gmail.com>
  • Date: Sat, 13 Oct 2007 03:42:08 -0400 (EDT)

In the following example, although var is assigned a value, these are
"forgotten" and an error occurs when it is returned as the result of the
compiled function:

Compile[{},
  Module[
   {var},
   Do[
    var = 0.;,
    {10}
    ];
   var
   ]
  ][]

>> Compile::initvar: The variable var has not been initialized or has been
initialized to Null.


But if var is initialised (to any Real value at all), then all subsequents
assignments to it are "remembered":

Compile[{},
  Module[
   {var = 1.},
   Do[
    var = 0.;,
    {10}
    ];
   var
   ]
  ][]

>> 0.

Is this the expected behaviour?



  • Prev by Date: Re: Re: [Mathematica 6] Format->Magnification does not
  • Next by Date: Re: Re: [Mathematica 6] Format->Magnification does notwork on notebook
  • Previous by thread: Re: Re: [Mathematica 6] Format->Magnification does not
  • Next by thread: Re: Compile forgets assigned values inside Do unless they are initialised