Skip to main content

bugs - Strange behavior when using Row with packed arrays


Bug fixed in 10.0.0




Today I lost a lot of time with a strange behavior and I narrowed it down to this small piece of code:


a = {1, 2};
ToString@Row[DeleteDuplicates[a], ","]
ToString@Row[Union[a], ","]



"Row[{1, 2}, ,]"
"1,2"

Can someone explain this bizarre behavior? Is this a bug?


This is interesting too:


a = {1, 2};
l1 = DeleteDuplicates[a];
l2 = Union[a];

l1==l2
s1 = ToString@Row[l1, ","]
s2 = ToString@Row[l2, ","]
s1==s2


True
"Row[{1, 2}, ,]"
"1,2"
False


There is some "memory" in l1 created using DeleteDuplicates.



Answer



Actually this happens when Row contains a packed array. DeleteDuplicates packs the array. Union doesn't. A simpler way to replicate the behaviour:


ToString@Row[Developer`ToPackedArray[{1,2}], ","]

(* ==> "Row[{1, 2}, ,]" *)

The default form used by ToString is OutputForm and the following also exhibits the problem:


OutputForm[Row[Developer`ToPackedArray[{1, 2}], ","]]


(* ==> Row[{1, 2}, ,] *)

I can reproduce it in both 8.0.4 and 9.0.1. I'd say it's a bug and you should report it to support.


Comments