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
Associationbut that it prints anything at all.Associationis atomic and it should have no (visible) members. Compare withexpr3=Graph[{1->2}].
The 10.0.1 documentation says:
MemberQworks on associations, testing values but not keys.
FreeQworks on associations, testing values but not keys.
Therefore this overloading is documented and I believe options should work propertly.
Associationbut that it prints anything at all.Associationis atomic and it should have no (visible) members. Compare withexpr3=Graph[{1->2}]. – Sjoerd C. de Vries Oct 08 '14 at 19:06expr1instead ofexpr2which is needed to illustrate the problem. In 10.0.2 usingHeads -> Falsein eitherMemberQorFreeQstill causesAssociationto be checked against the pattern. – Mr.Wizard Dec 12 '14 at 20:26