Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Is this a bug or my MMA went insane or I'm missing something?

LengthWhile[Reverse@IntegerDigits[1000], # == 0 &]

works fine, but with SameQ instead of Equal, or with PossibleZeroQ it doesn't

In[32]:= LengthWhile[Reverse@IntegerDigits[1000], # === 0 &]

Out[32]= 0

In[33]:= LengthWhile[Reverse@IntegerDigits[1000], PossibleZeroQ]

Out[33]= 0

It doesn't particularly happen with 1000, it was just an example.

share|improve this question
    
must be your version. with 8.0.4 on mac 10.6.8 both inputs return 3 –  Mike Honeychurch Feb 1 '12 at 3:55
8  
Bug in V8.0.0 that was fixed in V8.0.1. –  Brett Champion Feb 1 '12 at 3:57
    
@Artes Yeah, I'm testing it in 8.0.0.0 W7. Funny thing is that it works if I evaluate in place the list and write {0, 0, 0, 1} instead... Even when it isn't HoldFirst or anything. Anyway, I'm happy it has been fixed –  Rojo Feb 1 '12 at 4:00
    
@BrettChampion Ok, shouldn't you put that as an answer? Or should I just close this cause it was fixed? Answers won't get better than yours –  Rojo Feb 1 '12 at 4:14
    
You may also find the comments to this answer: stackoverflow.com/questions/4181470/… interesting. –  Leonid Shifrin Feb 1 '12 at 7:43
show 3 more comments

1 Answer

up vote 11 down vote accepted

Looks like a bug in V8.0.0 that was fixed in V8.0.1.

Seems to be triggered in part when the argument is a packed array:

(* V8.0.0 *)
In[2]:= digits = Reverse@IntegerDigits[1000]; 

In[3]:= LengthWhile[digits, 0 === #&]

Out[3]= 0

In[4]:= LengthWhile[Developer`FromPackedArray[digits], 0 === #&]

Out[4]= 3

which would explain why it worked when you used Evaluate in Place.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.