Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm figuring how to implement a function behavior based on the Head of its argument.

I mean

Head[p_[x]]:= Kind;
function[h_]:= 0;
function[p_Kind]:= 1;


the first instance of function should evaluate to 1 whereas the second instance should evaluate to 0. However, both evaluate to 0. Notice that Head[f[x]] evaluate to Kind as expected.

Where am I doing mistake(s)?

Thank you very much

share|improve this question
Try function[p_ /; Head@p === Kind] := 1; –  rasher Mar 21 at 8:10
@rasher Thank you now it works. –  Fabio Mar 21 at 8:19
@kuba your solution failed though I expected it works too... strange –  Fabio Mar 21 at 8:20
Yes, but pay heed to Kuba's comment - in general, doing things requiring Unprotect on system stuff is either not required, a bad idea, or both. There are times when that's the only viable way, but there's usually a better/cleaner/safer way. –  rasher Mar 21 at 8:21
I didn't say it will work. This was about Unprotecting important things ;) I've deleted my comment because I find myself a newbie in internals so let's wait for someone competent. @Rasher's solution works but I think it's not how one may want to do this. –  Kuba Mar 21 at 8:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.