Bug in LengthWhile?


Bug introduced in 8.0.0 and fixed in 8.0.1

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.


Posted 2012-02-01T03:42:55.347

Reputation: 40 993

must be your version. with 8.0.4 on mac 10.6.8 both inputs return 3 – Mike Honeychurch – 2012-02-01T03:55:48.080

8Bug in V8.0.0 that was fixed in V8.0.1. – Brett Champion – 2012-02-01T03:57:02.740

@Artes Yeah, I'm testing it in 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 – 2012-02-01T04:00:55.473

@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 – 2012-02-01T04:14:46.493

You may also find the comments to this answer: http://stackoverflow.com/questions/4181470/custom-function-with-non-standard-evaluation-behaves-like-table/4181983#4181983 interesting.

– Leonid Shifrin – 2012-02-01T07:43:03.120

Please do not use the tag [tag:bugs] for new questions! (See tag description) It will be added if the problem turns out to be indeed a bug. – Szabolcs – 2012-02-01T08:43:24.890

@Szabolcs, ok. But now it turned out to be a bug, that was fixed already. So tag stays or goes? – Rojo – 2012-02-01T12:56:29.503

@Rojo Stays, of course. But now I'm wondering if the original intention of not using this tag for new questions can work in practice at all. It'll probably end up manually removing the tag where not appropriate. – Szabolcs – 2012-02-01T13:05:21.740



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.

Brett Champion

Posted 2012-02-01T03:42:55.347

Reputation: 19 284