MathGroup Archive 2004

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

Search the Archive

Re: Mathematica language issues

  • To: mathgroup at
  • Subject: [mg53002] Re: Mathematica language issues
  • From: Bill Rowe <readnewsciv at>
  • Date: Sun, 19 Dec 2004 06:14:49 -0500 (EST)
  • Sender: owner-wri-mathgroup at

On 12/18/04 at 3:59 AM, ruebenko at (Oliver
Ruebenkoenig) wrote:

>Dear Maxim,

>>All the typical issues with the Mathematica programming language
>>are still present in version 5.1:

>> Compile[{},
>>   Module[{x = 0},
>>     While[x++; EvenQ[x] ];
>>     x
>> ]][]

>Compile[{}, Module[{x = 0}, x++; While[EvenQ[x]];
>      x]][]

>x++; EvenQ[x] is CompoundExpression[ x++, EvenQ[ x ] ]

>While[ test ] needs a test not a CompoundExpression

The usual syntax of While is While[test, expr] but While[test] is also allowed and test can be a compound expression. The issue is clearly related to how Mathematica evaluates the compound expression.

Compile[{}, Module[{x = 0}, 
    While[EvenQ[x], x++]; x]][]

outputs 1 as expected


Compile[{}, Module[{x = 0}, 
    While[x++, EvenQ[x]]; x]][]

also outputs 1. I suspect if test becomes more complex, say a compound expression, deviating from the indicated syntax order won't continue to get the same result as using the expected order.


Compile[{}, Module[{x = 0}, 
    While[x++; EvenQ[x]]; x]][]
outputs 2

This indicates EvenQ[x] is being evaluated with the current value of x rather than the updated value resulting from x++. However, I still don't understand why Maxim's original code outputs 3. But I also don't see an issue. I am never surprised by unexpected output when I deviate from expected syntax.
To reply via email subtract one hundred and four

  • Prev by Date: Re: please solve
  • Next by Date: Re: infinite sum problem
  • Previous by thread: Re: Mathematica language issues
  • Next by thread: Re: Re: Mathematica language issues