Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • $\begingroup$ You could also write this as: f[a_List, pat:{(0|1)..}] := Pick[a, PadRight[pat, Length@a, pat], 1] $\endgroup$ Commented Mar 13, 2013 at 15:25
  • $\begingroup$ @Mr.Wizard thanks - PadRight doesn't do much to the speed in v8 but the {(0|1)..} pattern is GREATLY appreciated. I really need to learn to declare my functions better. $\endgroup$ Commented Mar 13, 2013 at 15:36
  • 1
    $\begingroup$ Since you're interested in the subject, if that argument was a long vector and you wanted speed (with a valid argument) you might write it as pat:{__Integer} /; 0 <= Min[pat] && 1 >= Max[pat] or something similar, to avoid patten matching every element independently. $\endgroup$ Commented Mar 13, 2013 at 15:41
  • $\begingroup$ +1, this turned out to be really useful for some complicated situation I had. $\endgroup$ Commented May 23, 2013 at 21:55