17

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.

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
  • 2
    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}]. – Sjoerd C. de Vries Oct 08 '14 at 19:06
  • @Sjoerd Please see update. – Mr.Wizard Oct 08 '14 at 23:51
  • 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? – Mr.Wizard Oct 09 '14 at 12:23
  • AFAIC yes, and you were right with your update concerning the documentation. I hadn't seen the updates to these parts of the documenation. – Sjoerd C. de Vries Oct 09 '14 at 13:14
  • 2
    Reported and confirmed as a bug. – Daniel Lichtblau Nov 26 '14 at 17:54
  • In v 10.0.2, now I get this: I do not know if this is the correct output you expect or not, but here it is: Mathematica graphics – Nasser Dec 10 '14 at 23:36
  • @Nasser you used expr1 instead of expr2 which is needed to illustrate the problem. In 10.0.2 using Heads -> False in either MemberQ or FreeQ still causes Association to be checked against the pattern. – Mr.Wizard Dec 12 '14 at 20:26

1 Answers1

1

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

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371