MathGroup Archive 2005

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

Search the Archive

Re: String[bring] vs "bring"

  • To: mathgroup at smc.vnet.net
  • Subject: [mg59377] Re: [mg59350] String[bring] vs "bring"
  • From: stephen layland <layland at wolfram.com>
  • Date: Sun, 7 Aug 2005 03:47:10 -0400 (EDT)
  • References: <200508060530.BAA01232@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

and thus spake Kristen W Carlson [2005.08.06 @ 01:00]:
> Hi,
> 
> Question: What is the difference between "bring" and String[bring] ?
> What is the utility of making them different?

Strings in Mathematica are Atoms.  String[blah] is not really the full
form of "blah", just as Integer[2] is not the full form of 2 .  

Everything in Mathematica falls into one of two categories:
    * normal expression : h[elems...]
    * atomic expression : atom

Obviously, normal expressions are built out of atoms.  Strings and
numbers, (Reals, Integer,Complex) are atoms.  

If "blah" was really String[blah], then it would no longer be an atomic
expression.

Pattern matching still needs to have a way of matching atomic
expressions.  For normal expressions, Head[expr] returns just that:

    Head[f[2]] => f
    Head[x+y] => Plus
    Head[{a,b}] => List

For atomic expressions, Head[atom] returns atom type:

    Head[2] => Integer
    Head[234.32] => Real
    Head[2+4I] => Complex
    Head["blah"] => String

This allows one to make patterns like s_String, or x_Integer, etc.  

--
/*------------------------------*\
|        stephen layland         |
|    Documentation Programmer    |
| http://members.wri.com/layland |
\*------------------------------*/


  • Prev by Date: Re: String[bring] vs "bring"
  • Next by Date: Exp-Trig Manipulation
  • Previous by thread: String[bring] vs "bring"
  • Next by thread: Re: String[bring] vs "bring"