I'm trying to add a long list of pattern matching conditions to an existing function, which takes a variable number of arguments.
I know there are similar threads on this topic, but I was unable to make them work for the particular example I'd like to do.
Take the condition that says numerical objects should be factored out of the function argument.
lol[c_?NumericQ d_] := c lol[d]
lol[2]
lol[2 kk]
(* -> lol[2] *)
(* -> 2 lol[kk] *)
Now I would like it to be able to apply this condition to an arbitrary number of slots. For example I would like to write something like
lol[c_?NumericQ d__] := c lol[d]
lol[2]
lol[2 kk]
lol[2 kk, 3 jj]
(* -> lol[2] *)
(* -> 2 lol[kk] *)
(* -> 6 lol[kk,jj] *)
but instead
lol[2 kk, 3 jj]
simply returns
(* -> lol[2 kk, 3 jj] *)
Just to emphasise: it must be able to handle any number of inputs, I can't just code rules for 2 slots in addition to the rule for 1 slot. And the goal is to be able to update the properties of "lol" as a function, not just to produce a procedure that can factor Numeric objects out of functions (because I have an existing function that needs to have these properties but is too lengthy to paste her).
lol
should be lists. You may then also want to consider ReplaceAll. $\endgroup$