Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This seems like a very simple question, the answer to which should be obvious to me. So I won't be offended if this question is closed. But I'm having trouble figuring out the answer.

I would like to write a function that returns True if a list contains one or more numbers greater than 1. Why does MemberQ[{2, 1}, # > 1 &] return False? Thanks.

share|improve this question
2  
Select[{2, 1}, # > 1 &] != {} –  belisarius Oct 17 '12 at 16:13
1  
Catch[Scan[If[# > 1, Throw[True]] &, {1, 2, 6, 8}]] –  belisarius Oct 17 '12 at 16:19
2  
Simply put, the second argument of MemberQ[] should be a pattern, not a test. What does MatchQ[2, # > 1 &] return? –  J. M. Oct 17 '12 at 16:28
3  
The comment by @J.M. answers your question; if you insist on using MemberQ you can do MemberQ[{2, 1}, _?(# > 1 &)] to transform a test into a pattern. –  b.gatessucks Oct 17 '12 at 16:37
2  
The simplest way is clearly ! IntegerQ@Log2[1 + FromDigits[UnitStep[1 - {1, 2}]~Prepend~1, 2]] –  Rojo Oct 17 '12 at 18:44

1 Answer 1

up vote 5 down vote accepted

As J. M. kindly points out, I must specify form as a pattern, not a test. Thus, as b.gatessucks kindly points out, I must instead use:

MemberQ[{2, 1}, _?(# > 1 &)]

or one of the other suggestions given as comments to the original post.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.