Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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}, ,]"

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

This is interesting too:

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

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

share|improve this question
Interesting. If you Apply List to the DeleteDuplicates, results are peachy. – ciao Feb 3 '14 at 21:00
@Murta: Might want to change title to Row instead of DeleteDuplicates... a bit less alarming ;-) – ciao Feb 3 '14 at 21:14
please don't use the bugs tag when asking a question... if users (or WRI support/devs) confirm in the comments that it is indeed a weird behaviour/bug, then it can be retagged as such. – R. M. Feb 3 '14 at 21:24
@rm-rf It was confirmed by Wolfram Support. We can tag it. – Murta Feb 3 '14 at 21:43
Appears to have been fixed in V10 – Mike Honeychurch Jul 16 '14 at 4:09
up vote 12 down vote accepted

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.

share|improve this answer
Tks @Szabolcs, just reported (CASE:628688). Reproduced in V10 beta too. Let's see if final version 10 solves that. – Murta Feb 3 '14 at 21:14
Quick-draw analysis! +1 – ciao Feb 3 '14 at 22:14

As Szabolcs notes this occurs only when the first argument of Row is a packed array. In this case DeleteDuplicates returns a packed array while Union does not, which explains that difference:

<< Developer`
a = {1, 2};
b = Union @ a;
c = DeleteDuplicates @ a;
PackedArrayQ /@ {b, c}
{False, True}

One can see that this is not an issue of Row itself as these render as expected:

Row[b, ","]
Row[c, ","]
1, 2
1, 2

Rather, The variance occurs in OutputForm, which is normally not used in the Notebook interface, but which is the format that ToString defaults to:

Row[b, ","] // OutputForm
Row[c, ","] // OutputForm

Row[{1, 2}, ,]

I suspect that since Row was introduced in version 6, and it is ostensibly a 2D formatting function (it is not merely a string concatenation utility), someone forgot to update OutputForm to work in this edge case. For the case at hand one can easily avoid the problem by specifying the default Notebook format, StandardForm:

ToString[Row[b, ","], StandardForm]
ToString[Row[c, ","], StandardForm]
"1, 2"
"1, 2"
share|improve this answer
Much better use StandardForm instead of FromPackedArray as I was doing. Tks – Murta Feb 4 '14 at 10:41
Change my mind.. Now using StringJoin@Riffle[ToString /@ a, ","] – Murta Feb 4 '14 at 10:53

Your Answer


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.