Re: Types in Mathematica

• To: mathgroup at smc.vnet.net
• Subject: [mg62175] Re: [mg62152] Types in Mathematica
• From: "Steven T. Hatton" <hattons at globalsymmetry.com>
• Date: Sun, 13 Nov 2005 21:16:11 -0500 (EST)
• References: <200511120833.DAA19252@smc.vnet.net> <43762529.7060603@math.umass.edu>
• Sender: owner-wri-mathgroup at wolfram.com

```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.

You can reassign to that variable an change the type bound to it.  In that
sense Mathematica seems more like Lisp.  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.

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?

> 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.

Steven

```

• Prev by Date: Re: extract from list and keep track
• Next by Date: Re: extract from list and keep track
• Previous by thread: Re: Types in Mathematica
• Next by thread: Re: Re: Types in Mathematica