6
$\begingroup$

Since x is an alphabet not an integer,

Clear[x];IntegerQ[x]

gives

False

But sometimes I want to leave it as it is

I want to construct function IntegerQ2 :

Clear[x];{IntegerQ2[22],IntegerQ2[4.915],IntegerQ2[x]}

would give

{True,False,IntegerQ2[x]}

Can you help me? This problem is not just confined to IntegerQ. It applies to almost every predicate function.

$\endgroup$
2
  • 1
    $\begingroup$ small note: the kind of thing x is is a Symbol, not an alphabet! (just to help you search documentation) :) $\endgroup$
    – thorimur
    Commented Sep 11, 2021 at 19:08
  • 2
    $\begingroup$ Predicate functions are supposed to behave that way (maybe you knew this but stating it in case not). $\endgroup$ Commented Sep 12, 2021 at 4:26

1 Answer 1

12
$\begingroup$
ClearAll[IntegerQ2]
IntegerQ2[x_?NumericQ] := IntegerQ[x]

IntegerQ2 /@ {2, 4.95, x}
{True, False, IntegerQ2[x]}
$\endgroup$
2
  • $\begingroup$ Thank you! General solution for BlahblahQ is related to my another question. Constructing DeterminedQ : mathematica.stackexchange.com/questions/242142/… $\endgroup$
    – imida k
    Commented Sep 11, 2021 at 13:14
  • 1
    $\begingroup$ I think replacing NumericQ with DeterminedQ would improve the code. Note that the question with URL in the comment is not perfectly solved. $\endgroup$
    – imida k
    Commented Sep 11, 2021 at 13:18

Your Answer

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

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