MathGroup Archive 2005

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

Search the Archive

mathematica expressions in Compile


Hello -

I was wondering what is happening in the following example :

Compile[{}, Module[{i =  0, nums}, nums = {0, 0, 0}; i =
First[Ordering[{1., 2., 3.}]]; nums[[i]]++; nums]];

I get an error when trying to evaluate this statement because
Mathematica complains about assigning i the value of the
First[Ordering[_]] expression - Compile seems to think
First[Ordering[_]] in this example is a real number whereas I
initialized i to be an integer. I can solve this simply by

Compile[{}, Module[{i =  0, nums}, nums = {0, 0, 0}; i =
Round[First[Ordering[{1., 2., 3.}]]]; nums[[i]]++; nums]];

My question is - how come Compile knows that the value of Round is an
integer, but does not know that the First[Ordering[_]] is an integer?

Thank you.


  • Prev by Date: Re: Running the kernel as a daemon?
  • Next by Date: Re: Mathematica 1
  • Previous by thread: Re: Bug in pattern parsing?
  • Next by thread: Re: mathematica expressions in Compile