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.

Required fields*

5
  • $\begingroup$ I don't know if I'd call it more elegant, but you can use the x_Head notation and do pattern = {__?(# /. y_foo | y_bar -> True &)}. Is there any particular criterion you're interested in? $\endgroup$ Commented May 29, 2015 at 20:01
  • $\begingroup$ It is an alternative but I would not call it more elegant. Imagen a function prototype of the form f[x : {__?(# /. y_foo | y_bar -> True &)}] := test[x], Hiding the pattern in some function f[x : {__?patternTest}] would not be much better, as then one needs to look up pattern to see the format. $\endgroup$ Commented May 29, 2015 at 20:10
  • 2
    $\begingroup$ So are you looking for a better way to write the pattern? You could also do 'pattern = {(foo|bar)[__]..}` which is more readable to me. $\endgroup$ Commented May 29, 2015 at 20:45
  • 5
    $\begingroup$ Or even more readable pattern = {(_foo|_bar)..} $\endgroup$ Commented May 29, 2015 at 20:55
  • $\begingroup$ Thanks! I guess it can not be short than this. Could you turn it to answer? $\endgroup$ Commented May 29, 2015 at 21:02