Re: Re: Types in Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg62185] Re: [mg62161] Re: [mg62152] Types in Mathematica
- From: Pratik Desai <pdesai1 at umbc.edu>
- Date: Sun, 13 Nov 2005 21:16:27 -0500 (EST)
- References: <200511120833.DAA19252@smc.vnet.net> <200511130708.CAA08912@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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 >>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? >> >> > > > How about something like this Clear[List3Q] List3Q[m_List] := (Length[m] === 3) Vector3[m_?List3Q] := Norm[m] Vector3[{1,2,4}] >>Sqrt[21] Vector3[{1,2,4,5}] >Vector3[{1, 2, 4, 5}] Hope this helps Pratik . -- Pratik Desai Graduate Student UMBC Department of Mechanical Engineering Phone: 410 455 8134
- References:
- Types in Mathematica
- From: "Steven T. Hatton" <hattons@globalsymmetry.com>
- Re: Types in Mathematica
- From: Murray Eisenberg <murray@math.umass.edu>
- Types in Mathematica