Re: Types in Mathematica

*To*: mathgroup at smc.vnet.net*Subject*: [mg62194] Re: Types in Mathematica*From*: John Doty <jpd at whispertel.LoseTheH.net>*Date*: Mon, 14 Nov 2005 00:38:39 -0500 (EST)*References*: <200511120833.DAA19252@smc.vnet.net> <43762529.7060603@math.umass.edu> <dl8s4g$n41$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Steven T. Hatton wrote: > On Saturday 12 November 2005 12:23 pm, 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. > > > Looking at the builtin types is what got me thinking about this topic. I > wanted a type Boolean for variables and boolean values. It seems that in > Mathematica, a variable, in and of itself, does not really have a type in the > sense of c++. That is, you don't say > > Integer a=1; > > You just say > > a=1; > > and that makes it an integer. FORGET CC++. You will *never* understand Mathematica by analogy with C++. Mathematica's more like sed than C++: it works by recognizing patterns in input and replacing them. a=1; simply means whenever you see "a", replace it with "1". That's all. No type. > > You can reassign to that variable an change the type bound to it. In that > sense Mathematica seems more like Lisp. Mathematica has, in general, no idea what a variable is. "a" is a Symbol. It might be a variable, it might be something else. For specific tthings like Integrate, you get to designate particular Symbols as variables (using the meaning of the word "variable" in mathematics, *not* computer science). > I guess I can do something like > > BooleanQ[b_]:= b==True||b==False||Head[b]==Boolean > > I'll admit, that really isn't something that has a C++ counterpart. FORGET C++. > > > One thing about your example of VectorQ is that it requires the members of the > List to be Number types. What happens if they are functions which will > evaluate to numbers? You get to specify this behavior at whatever level of detail you wish. Or not: much Mathematica code is evaluated only a handful of times. Get the answer, the notebook becomes documentation for how you got it. > > >>Sections 2.3.4 and 2.3.5 of The Mathematica Book are two places to find >>this subject discussed. > > > This is not the discussion I had in mind. Somewhere there is an example of > creating an expression with a head Vector, and using the head of the > expression as a "type". > > >>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. > > > I may be mistaken, but I believe 5.2 comes with an independent indexing > facility which acts something like htdig. I have the usual helpbrowser index > functionality, but I don't believe that provides a full text search. Stop trying to make Mathematica behave like tools you know. Use it on its own terms: in its domain it's better than anything you know. -jpd

**References**:**Types in Mathematica***From:*"Steven T. Hatton" <hattons@globalsymmetry.com>