I tried to test if a list has non-numeric elements using FreeQ
as follows:
FreeQ[{"sa", "sa", {"sa", "sa"}, x}, Except[_?NumericQ], {-1}]
which gives False
and apparently contradicts what I expect as the list doesn't contain any numeric element.
How can this behavior of FreeQ
be explained?
Edit
I realised the mistake I made in the previous example.
However, for the case below
{FreeQ[{1, 2, 2, 1}, Except[_?NumericQ], {-1}], FreeQ[{1, 2, 2, 1}, _?NumericQ, {-1}]}
I would expect {True,False}
but it gives {False,False}
.
Is there something I'm still missing?
Heads->False
... $\endgroup$Integer[1]
rather than1
? $\endgroup$Print
orSow
in the test - you'll see withoutHeads->False
, the list head itself is also passed to test... $\endgroup$