I have a function which takes lists as arguments. But it shall be evaluated only, if the elements in the lists are all numeric. Otherwise I want the function to remain unevaluated.
There is a function NumericQ, but if I apply it to a list, e.g.
NumericQ[{1, 2.1, Pi}]
gives False
and
NumericQ /@ {1, 2.1, Pi}
gives {True, True, True}
In the documentation it shows a nice example applying a NumericQ-Test to all Matrix elements MatrixQ[m, NumericQ]
where m is a matrix with NumericQ True for all its elements.
This gave me the idea to do the same with ListQ (unfortunately it is not in the documentation, although ?ListQ gives some information on it).
But unlike MatrixQ, ListQ does not have an optional parameter test, so ListQ[list, NumericQ] is not available.
Would it be possible to add such a capability to ListQ and how would one do that?
I looked up Attributes[ListQ]
which yields {Protected}
and Attributes[NumberQ]
which also yields {Protected}
, booth don't have Listable among their attributes.
Would there be adverse effects if one would add Listable to one of them?
Of course, the solution to my original problem, test if a list has all numerical entries, is solved by this function:
Apply[And, Map[NumericQ, #]] &
But my more genral questions are not answered by it.