Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: Compile

  • To: mathgroup at smc.vnet.net
  • Subject: [mg45349] Re: Compile
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Fri, 2 Jan 2004 04:23:40 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

On 1/1/04 at 5:54 AM, dontsendhere@. (Maxim) wrote:

> If you tried to actually do some testing --

I did but did not try such odd code
 
> Module[{y := If[Print[x];NumericQ[x], x, 1]},
>   Plot[x y, {x, 0, 1}, Compiled -> True]
> ]

The documentation specifically states only inline functions get compiled not user defined functions. So when you write code such as the above, you should expect things to be a bit unpredictable.

> you would notice that y is evaluated for each step Plot takes and it prints symbol x.

No, I don't think that is what is happening. I believe y is evaluated once to 1 since x is not numeric at the time y is evaluated. But since you have wrapped x in a Print statement what is compiled is a literal Print[x] followed by x which causes the symbol x to be printed each time the function x is sampled to be plotted.

If y were evaluated at each step, I would expect numeric values to be printed instead of the symbol x and a parabola which is exactly what you get if you choose Compiled->False in the above code.
 
> And of course, Compile doesn't evaluate its second argument -- do you really think that to execute 
> Compile[{}, Print[x]] Print[x] should be evaluated?

I don't know why anyone would write code like this, but if they did why should they expect Print[x] not to be evaluated in this example?
--
To reply via email subtract one hundred and four



  • Prev by Date: Re: Printing "Alias" Definitions
  • Next by Date: Re: Function interpolation
  • Previous by thread: Re: Re: Compile
  • Next by thread: Re: Compile