I'm figuring how to implement a function behavior based on the Head of its argument.
I mean
Unprotect@Head;
Head[p_[x]]:= Kind;
Protect@Head;
function[h_]:= 0;
function[p_Kind]:= 1;
Head[f[x]]
function[f[x]]
function[f]
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
function[p_ /; Head@p === Kind] := 1;
$\endgroup$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. $\endgroup$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. $\endgroup$