Suppose I have a property associated with two functions using TagSet
:
f1 /: type[f1[n_][x_]] := n
f2 /: type[f2[n_, m_][x_]] := m
But the function are related by
f2[n_, m_] := f1[n]
In other words, I use a second argument in f2
to distinguish the property differences.
Now if we do
type[f2[1, 2][x]]
(* 1 *)
we get 1
instead of 2
. this is because f2[1,2]
get evaluated into f1[1]
. We can fix this by setting the attribute of type:
SetAttributes[type, HoldAll]
and now it behaves as what we desire
type[f2[1, 2][x]]
(* 2 *)
However, think about the situation that f2
is some very long expression with many arguments, and instead of writing the long expression every time, I would like to assign it to a short variable for connivence:
myf := f2[1,2]
But now we are not be able to get the type correctly:
type[myf[x]]
type[Evaluate@myf[x]]
(* type[myf[x]] *)
(* 1 *)
So how should I deal with this?