MathGroup Archive 2010

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

Search the Archive

Re: Replace list element based on a condition how to

  • To: mathgroup at
  • Subject: [mg106747] Re: Replace list element based on a condition how to
  • From: Bill Rowe <readnews at>
  • Date: Fri, 22 Jan 2010 05:40:26 -0500 (EST)

On 1/21/10 at 4:53 AM, canopus56 at (Canopus56) wrote:

>Another newbie type question.  Several responders recommended:

>>In[18]:= lst1 /. n_Integer :> fncHourFix[n]

>Q1.  What is the "_Integer" part of "n_Integer"?

This and more is answered in the documentation. See
tutorial/PatternsOverview for various details about patterns and
pattern matching. For a the specific answer to the question
above, see the fourth entry which can be directly accessed as tutorial/Spec=

>Is that just declaring a variable name "n_Integer" or is that a way
>to declare a datatype "Integer".

Neither is quite accurate. The pattern n_h has three parts,

n a local name for what ever is matched by the pattern,
_ essentially a place holder
h the head of the thing to be matched. So, n_Integer will match
anything with Head = Integer and give it a local name n. This
isn't really the same as declaring n to be an integer as you
might do in say C or some other computer programming language.

>If that syntax is a way to declare a datatype, where is that
>referenced in Mathematica documentation?  I really scoured the
>Documentation trying to find how to force a datatype, e.g. - VBA's
>equivalent to CStr, CDbl, CInt, etc.

As far as I know, there is no Mathematica syntax for declaring
the datatype of variables.

  • Prev by Date: Re: Re: More /.{I->-1} craziness. Schools are conservative.
  • Next by Date: Finding and changing strings in a matrix
  • Previous by thread: BezierCurve vs. BezierFunction
  • Next by thread: Re: Re: Replace list element based on a condition how to