Maybe this is a bad idea: I want to inject some conditions into Set
associated to specfic symbols, like
clear@{f,g}
f/:Set[f[x_],y_]:=
If[
!IntegerQ@x,
Print["non-integer"],
(*pre-codes;*)
f[x]=y;
(*post-codes;*)
]
but this try fails:
Set[f[1],2]
(*
$IterationLimit::itlim: Iteration limit of 4096 exceeded.
Hold[f[1]=2]
*)
I also tried (but failed) adding some pre-codes and post-codes (like ValueQ
) to escape from the infinite loop, except trivially changing Set
to some other symbol like,
fSet[f[x_],y_]:=
If[
!IntegerQ@x,
Print["non-integer"],
f[x]=y;
]
Are there other ways to solve this problem, or should I abandon this idea?