Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Pattern: x_List with conditions on elements

  • To: mathgroup at smc.vnet.net
  • Subject: [mg110863] Re: Pattern: x_List with conditions on elements
  • From: Peter Breitfeld <phbrf at t-online.de>
  • Date: Thu, 8 Jul 2010 20:34:43 -0400 (EDT)
  • References: <i13tqo$7h7$1@smc.vnet.net>

telefunkenvf14 wrote:

> Group:
>
> 1. Can someone provide a clearer way of implementing the following
> example? (Goal: I want a pattern that accepts only a list of real
> numbers and what I have seems hacky.)
>
> MatchQ[{1, 2, 2.2},x_?(VectorQ[#,(NumericQ[#]&&Im[#]==0)&]&)]
>
> 2. Could someone show me how to create a second pattern which accepts
> only a list (vector) of symbols? I feel like I'm spinning my wheels a
> bit on this one...
>
> 3. Does anyone else think it would be nice to compile a list of
> favorite/useful patterns, along with a very brief explanation of the
> intent? (And yes, I know there are a bunch of examples in the
> documentation(!), but I'm thinking more in terms of assembling a list
> of recipes.) I guess I'm just craving more guided examples.
>
> -RG
>
>
The answer to question 1 could be:
realpatt={_Real..}

Question 2 could be done by:
vectorpatt=v:{_Symbol..}/;VectorQ[v]


There is a plethora of combinations of patterns, but in my opinion some
of the fundamental ones are included in the examples above. Mostly it's
possible to achieve the same goal in different ways. 


-- 
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de


  • Prev by Date: Re: FindMinimum numerical constraint functions
  • Next by Date: Re: More flexibility in placement of ChartLegend
  • Previous by thread: Re: Pattern: x_List with conditions on elements
  • Next by thread: Re: Pattern: x_List with conditions on elements