Re: Types in Mathematica

• To: mathgroup at smc.vnet.net
• Subject: [mg62894] Re: Types in Mathematica
• From: "Steven T. Hatton" <hattons at globalsymmetry.com>
• Date: Thu, 8 Dec 2005 00:04:22 -0500 (EST)
• References: <dn38ed\$3l7\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

Bill Rowe wrote:

> On 12/5/05 at 3:37 AM, hattons at globalsymmetry.com (Steven T. Hatton)
> wrote:
>
>>I have come to realize that there are (or appear to be) certain
>>limitations as to what can be done with type conversions in
>>comparison to how they are used in C++.  For example, in C++ it is
>>possible to create type conversion operators which will be invoked
>>according to the parameters accepted by a function.  For example,
>>you might have some kind of counter object which automatically
>>converts to an integer when passed as a variable of integer type.
>
>>I don't believe I could do something similar with Mathematica.  For
>>instance, if I have a type Vector3D[x,y,z], I don't see a way of
>>getting that to convert to a List[x,y,z] when passed to an
>>arbitrary function taking a List as an argument.
>
> I don't understand your comment here. I can easily do the following:
>
> In[3]:=
> a = Vector3D[x, y, z];
> b = List @@ a;
>
> Out[5]=List
>
> Given this, why shouldn't Apply (@@) be considered a "type" conversion in
> this context? --

It is not an automatic type conversion.  You had to explicitly invoke it.

Let's assume Vector3d has a conversion operator that returns a string
representation.  I could simply pass it to an output stream that takes a
string type, and the Vector3d would be converted to a string and put onto
the stream.  No need to explicitly call a conversion function explicitly.

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

• Prev by Date: Re: Re: Re: Threading 'Append'
• Next by Date: Re: Types in Mathematica thread
• Previous by thread: Types in Mathematica
• Next by thread: Re: Types in Mathematica