17
$\begingroup$

Bug introduced in 10.0.0 and fixed in 10.1.0.


While answering Pattern match for nested Association I came across behavior of MemberQ and FreeQ in 10.0.1 that I believe is incorrect. The option Heads -> False does not work properly:

expr1 = foo[bar, baz];
expr2 = <|1 -> a, 2 -> b|>;

MemberQ[expr1, _?Print, Heads -> False];

bar

baz

MemberQ[expr2, _?Print, Heads -> False];

Association

a

b

FreeQ[expr1, _?Print, Heads -> False];

bar

baz

foo[bar,baz]

FreeQ[expr2, _?Print, Heads -> False];

Association

a

b

<|1->a,2->b|>

Observe that in both cases Association is checked against the pattern even though foo is not.


Sjoerd wrote:

I believe the error is not the printing of Association but that it prints anything at all. Association is atomic and it should have no (visible) members. Compare with expr3=Graph[{1->2}].

The 10.0.1 documentation says:

MemberQ works on associations, testing values but not keys.

FreeQ works on associations, testing values but not keys.

Therefore this overloading is documented and I believe options should work propertly.

$\endgroup$
  • 2
    $\begingroup$ I believe the error is not the printing of Association but that it prints anything at all. Association is atomic and it should have no (visible) members. Compare with expr3=Graph[{1->2}]. $\endgroup$ – Sjoerd C. de Vries Oct 8 '14 at 19:06
  • $\begingroup$ @Sjoerd Please see update. $\endgroup$ – Mr.Wizard Oct 8 '14 at 23:51
  • $\begingroup$ I see that this Question has six votes. Shall I read that to mean that people agree that this appears to be a bug, and tag it as such? $\endgroup$ – Mr.Wizard Oct 9 '14 at 12:23
  • $\begingroup$ AFAIC yes, and you were right with your update concerning the documentation. I hadn't seen the updates to these parts of the documenation. $\endgroup$ – Sjoerd C. de Vries Oct 9 '14 at 13:14
  • 2
    $\begingroup$ Reported and confirmed as a bug. $\endgroup$ – Daniel Lichtblau Nov 26 '14 at 17:54
1
$\begingroup$

Daniel Lichtblau confirmed that this was a bug. It has been corrected in version 10.1.0.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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