I am having a problem with pattern testing on variables during function definition
nfun[M : Repeated[_?(test1&&test2||test3..)&, {10}]]:= N@(Norm@(Sin[#] & /@ M))
I want to have a few tests on the vectors M that I want to feed nfun. One example that does not work if I want to test if M has Integer entries using Repeated is the following.
nfun[M : Repeated[_?IntegerQ, {10}]]:= N@(Norm@(Sin[#] & /@ M))
Here goes another filed trial with the same aim.
nfun[M_?((VectorQ[#, IntegerQ]) && (Length[#] == 10)) &]:= N@(Norm@(Sin[#] & /@ M))
nfun[M : Repeated[_Integer, {10}]] :=N@(Norm@(Sin[#] & /@ M))does not work either if you trynfun[Range[10]]and same for thefyou defined with thetest. Tryf[M : Repeated[_?test, {4}]] := {{M}}; test[#] & /@ {2, 4, 6, 13}which gives all true. Butf[{2, 4, 6, 13}]does not evaluate! – PlatoManiac Jun 20 '12 at 15:54nfun @@ Range[10]or change you definition to account forList. – Mr.Wizard Jun 20 '12 at 16:10Repeatedwill take care of a list with length 10. I saw your answer (http://stackoverflow.com/questions/8255210/finding-equal-or-similar-sequences-in-a-list) before I posed my question. How can I use something likeListQin this context ofRepeatedso thatnfun[Range[10]]works. I am so dumb when it comes to use this fancy patterns :( – PlatoManiac Jun 20 '12 at 16:56Repeatedas being a bare "sequence" of elements like1, 2, 3without a head, therefore you need{ Repeated[ stuff ] }if you want to match aListwith repeated elements inside it. This is similar to:f[ x__ ] :=versusf[ {x__} ] :=– Mr.Wizard Jun 20 '12 at 17:31