MathGroup Archive 2005

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

Search the Archive

Re: Types in Mathematica

  • To: mathgroup at
  • Subject: [mg62161] Re: [mg62152] Types in Mathematica
  • From: Murray Eisenberg <murray at>
  • Date: Sun, 13 Nov 2005 02:08:40 -0500 (EST)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <>
  • Reply-to: murray at
  • Sender: owner-wri-mathgroup at

Every function you write can be made to type its variables.  E.g.,

   f[x_?NumberQ] := x^2

   g[lis_List] := Most[lis]

   normalize[v_ /; VectorQ[v, NumberQ]] := v/Norm[v]

use: the built-in NumberQ function to test a property of the input x, 
and the pattern test for having a head of List, respectively.

Sections 2.3.4 and 2.3.5 of The Mathematica Book are two places to find 
this subject discussed.

I don't understand why you don't have access to search in your Linux 
installation: Whenever I've installed in Linux and selected to install 
the documentation, the usual HelpBrowser becomes available, including 
its search capability.

The difficulty is, of course, in figuring out what to search for.  To 
find section 2.3.4, I searched for "Types" in the MasterIndex of the 
HelpBrowser; the relevant entry was for "Types, using patterns to 
constrain".  To find section 2.3.5, I looked for "Constraints"; the 
relevant entry was for "Constraints, on transformation rules, Condition".

Steven T. Hatton wrote:
> I know there are reasons for Mathematica not being a strongly typed
> language, but I'm wondering if there are places where a type system might
> be of use, and how it might be implemented, or simulated. 
>  One suggestion from The Mathematica Book is that we could create something
> like 
> Vector3[x_,y_,z_], and test the head of variables to determine if they are
> Vector3. I'm not sure exactly where in the book that is, and the Linux
> version does not have a desktop search, AFAIK.
> Observations?  Suggestions?

Murray Eisenberg                     murray at
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305

  • Prev by Date: Re: extract from list and keep track
  • Next by Date: Absolute value of a symbolic complex expression
  • Previous by thread: Types in Mathematica
  • Next by thread: Re: Re: Types in Mathematica