One can write functions which depend on the type of actual parameter before they are actually called. E.g.:
Clear[f,g,DsQ]; DsQ[x_]:=MatchQ[x,{String__}]; f[i_Integer, ds_?DsQ] :=Print["called with integer i and DsQ[ds]==True"]; f[i_String, ds_?DsQ] :=Print["called with String i and DsQ[ds]==True"]; f[i_?NumberQ, ds_?DsQ]:=Print["called with numerical parameter"]; f[i_?NumberQ]:=Print["only a numerical parameter"]; (* Tests *) ds={"string"}; DsQ[ds] f[1,ds] f[1.,{""}] f[999] yields
True called with integer i and DsQ[ds]==True called with numerical parameter only a numerical parameter Now I want to write another function g, which gets a function like f as parameter. But the functional parameter’s definition’s left hand side shall have a defined form, e.g. only the one from the first definition of f
f[i_Integer, ds_?DsQ] Is such a check for the right pattern of a functional parameter possible? How do I do that? Writing
g[p_Symbol[i_Integer, ds_?DsQ]]:=Print["g called with first type of definition"] does not work.


g? Asg[f]? What should happen iffhas multiple different definitions (like in your example)? What do you ultimately want to use this for? $\endgroup$gso that it holds its argument. Something likeSetAttributes[g, HoldAll]. Try it out and see if it works:g[f[1, {""}]]prints "g called with first type of definition" butg[f[0.1, {""}]]returns unevaluated. If that's what you want, I can write a quick answer. $\endgroup$g[p_Symbol[i_Integer, ds_?DsQ]]instead ofg[f[i_Integer, ds_?DsQ]], I'm inferring that what you mean by "type" is something like signature. Is that correct? I.e. the functiongdoesn't actually know about the functionfexplicitly, but will do something for anypthat has a particular signature. If this is on the right track, it would be very helpful to have more context. What do you needgto do withpand with the arg pattern? $\endgroup$f[i_Integer, ds_?DsQ]to be a sort of canonical form for that signature. Indeed, something likef[i_Integer, ds : {__String}]might be more expected. $\endgroup$