Pattern to match a list of non-negative integers
- To: mathgroup at smc.vnet.net
- Subject: [mg108919] Pattern to match a list of non-negative integers
- From: Leo Alekseyev <dnquark at gmail.com>
- Date: Wed, 7 Apr 2010 03:20:21 -0400 (EDT)
This seems like a very basic pattern-matching question, but somehow
the answer eludes me at the moment. I want to match a list of
non-negative integers. Something like MatchQ[{1,2},{(x_Integer /; x
>= 0)..}] doesn't work -- do named patterns simply not play well with
Repeated[]?..
After starting to write this message, the following pattern, occurred to me:
MatchQ[{2, 3}, x : {_Integer ..} /; ! MemberQ[x, y_ /; Negative[y]]]
-- this works, but seems needlessly complex -- so I'll send the
message on, in hopes that there is a cleaner way of writing the
pattern.