RE: question on changing 'type' of numbers
- To: mathgroup at smc.vnet.net
- Subject: [mg69495] RE: [mg69473] question on changing 'type' of numbers
- From: "David Park" <djmp at earthlink.net>
- Date: Thu, 14 Sep 2006 06:55:44 -0400 (EDT)
Nasser,
You can't change the Head of anything that gives True to AtomQ. You cannot
access the stored data of an atom and in most cases this is for good reason.
However, there seem to be cases where this is only partly true. For example
with complex numbers...
AtomQ[2 + 3 I]
True
We can't change the Head
Head[List @@ (2 + 3 I)]
Complex
but we can certainly access the parts
2 + I 3 /. Complex[a_, b_] -> {a, b}
{2, 3}
Maybe others will point out other 'in between' objects.
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
From: Nasser Abbasi [mailto:nma at 12000.org]
To: mathgroup at smc.vnet.net
I think of a the Head of expression as its 'type'.
One is supposed to be able to use Apply[f,expr] to change head of expression
to f.
But Why can't I use this to change the head of a Real number to Integer?
In[122]:=
Remove["Global`*"]
x = 0.1
Head[x]
-------------->Real
Apply[Integer,x]
Head[x]
------------------->Real. I was expecting Intger
x = Integer[x]
Head[x]
----------------> Now it says Integer
any idea?
ofcourse the question as to what should happen to the value of the variable
if for example I change the head of 0.5 from Real to Integer is another
matter. It seems in this case x remained 0.1 but only the head said Integer
x
----->Integer[0.1]
Now sure what the above really means :)
Nasser
- Follow-Ups:
- Re: RE: question on changing 'type' of numbers
- From: Sseziwa Mukasa <mukasa@jeol.com>
- Re: RE: question on changing 'type' of numbers