How can I make


valid for a list of integers? For example:

f[nlist_Integer] := 2*nlist[[1]]

does not work because because nlist={1,3,2} is not an integer.

Edit: Same question with NumericQ (which does not work as Integer)?

  • $\begingroup$ Related: (6588) -- also see the many links therein. And performance notes here may be useful: (8650) $\endgroup$
    – Mr.Wizard
    Jun 16, 2015 at 7:11

1 Answer 1


The semicolon is just another way to name a pattern

  • 1
    $\begingroup$ By chance, I just found nList_ /; VectorQ[nList, IntegerQ] reading a question. Your suggestion is shorter. $\endgroup$
    – anderstood
    Jun 16, 2015 at 6:08
  • $\begingroup$ How would you make it work with NumericQ̀? $\endgroup$
    – anderstood
    Jun 16, 2015 at 6:10
  • 2
    $\begingroup$ F[listInt:{__Integer}]? $\endgroup$ Jun 16, 2015 at 6:11
  • $\begingroup$ @belisarius Absolutely. It does not work with Integers. $\endgroup$
    – anderstood
    Jun 16, 2015 at 6:12
  • 1
    $\begingroup$ @anderstood F[b : {__?NumericQ}]? $\endgroup$ Jun 16, 2015 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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