Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Re: Types in Mathematica

Murray Eisenberg wrote:

>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
>>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?
How about something like this
List3Q[m_List] := (Length[m] === 3)
Vector3[m_?List3Q] := Norm[m]


 >Vector3[{1, 2, 4, 5}]

Hope this helps

Pratik .

Pratik Desai
Graduate Student
Department of Mechanical Engineering
Phone: 410 455 8134

  • Prev by Date: Re: 5.2 on suse 10.0 error
  • Next by Date: Re: Types in Mathematica
  • Previous by thread: Re: Types in Mathematica
  • Next by thread: Re: Types in Mathematica