Re: Types in Mathematica, a practical example

*To*: mathgroup at smc.vnet.net*Subject*: [mg62845] Re: Types in Mathematica, a practical example*From*: "Steven T. Hatton" <hattons at globalsymmetry.com>*Date*: Tue, 6 Dec 2005 23:10:13 -0500 (EST)*References*: <200512051841.NAA21133@smc.vnet.net> <dn36n9$2tv$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

I'm still working on my first pot of coffee, so I can claim full mental acuity. Nonetheless, I will offer my observations. Andrzej Kozlowski wrote: > It seems to me that you are looking here at Mathematica from the > wrong view point. Although Mathematica is not a strict "functional" > language, it is "functional" at least in the sense that it is > "functions" and not "objects" that play the central role (I am being > deliberately vague here but I have run out of patience with long > discussions of programming languages and general design issues.). You aren't obligated to participate in this discussion, as I'm sure you know. I will acknowledge that discussing Mathematica in terms of a programming language can be a bit frustrating. Part of that is due to the inexact way in which it is documented at the fundamental level. > In > this case the issue is with the function Plus and not with the nature > or "type" of x etc. Plus has the attribute Listable, which is > responsible for the behaviour you see (and it does [not?] really matter if > Mathematica assumes that x is a number or not, for the same thing > will happen, for example, if you use the string "x" instead of the > symbol x). Hence the natural way to deal with your problem is by > temporarily blocking the Listable attribute Here I will say that Plus could be viewed as an instance of a class Symbol with a member variable Listable. I would probably implement attributes as a single bit field. [10101110], or whatever, where one means the attribute is set. > like this: > > In[10]:= > a = {{1, 2}, {3, 4}}; > > In[11]:= > Block[{Plus}, x - a /. x -> a] That is certainly an interesting trick. If I understand correctly, you have basically shadowed the "definition" of Plus, and within the context of the Block, "Plus" is just a vacant symbol. > Out[11]= > {{0, 0}, {0, 0}} > > As far as I am concerned this works just as I would wish and I see no > benefit in adding any kind of "types" to deal with this sort of > problems. This really is the kind of answer I was trying to get at by bringing up the topic of typing. That is to say, in other languages we expect certain kinds of behavior. Some of these behaviors are based on a type system in the other language. What we have here is a person who came to Mathematica with certain expectations of behavior which seem "type related". Your suggestions seems like an insightfull means of accomplishing the original objective of Ingolf's example. As for adding any kind of type system to Mathematica, that could mean different things. It could mean modifying the core Mathematica language to add a type system. That is not something I expect to happen in the next few thousand years, at least not in the sense of types in C++, etc. It could also mean implementing a type system using the current Mathematica language. That is something which people (e.g., Roman Maeder) have done, by their own definition of types. It also seems to be something WRI is promoting in their training courses. -- The Mathematica Wiki: http://www.mathematica-users.org/ Math for Comp Sci http://www.ifi.unizh.ch/math/bmwcs/master.html Math for the WWW: http://www.w3.org/Math/

**References**:**Types in Mathematica, a practical example***From:*"Ingolf Dahl" <ingolf.dahl@telia.com>