Why would this work:
Clear[f]
f[a : PatternSequence[b_, c_]] := {a};
f[1, 2]
(* {1, 2} *)
and this also works:
Clear[f]
f[a : PatternSequence[_, _] ..] := {a};
f[1, 2, 3, 4]
(* {1, 2, 3, 4} *)
but this does not work?
Clear[f]
f[a : PatternSequence[b_, c_] ..] := {a};
f[1, 2, 3, 4]
(* f[1, 2, 3, 4] *)
Edit: Now that @RunnyKine's answer and @kguler's comment have perfectly answered my original question, I have another related question: is there a pattern-based way that I could extract the first element of the repeated pattern sequence without doing this?
Clear[fNew]
fNew[a : PatternSequence[_, _] ..] := Partition[{a}, 2][[All, 1]]
fNew[1, 2, 3, 4]
(* {1, 3} *)
f[3, 4, 3, 4]
andf[1, 2, 1, 2]
works suggests whyf[1,2,3,4]
does not work, no? $\endgroup$Set
orSetDelayed
is to allow the evaluator to determine which, if any, down-values can be used for further evaluation of the expression. It is not intended to be and can not be use as a kind macro preprocessor for modifying the argument sequence. So the answer to latest question is: no. $\endgroup$fNew[a : (PatternSequence[_, _] ..)] := {a}[[1 ;; ;; 2]]
will do it efficiently.fNew[a : (PatternSequence[_, _] ..)] := Downsample[{a}, 2]
will do the same. $\endgroup$