Re: math =!= mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg108576] Re: math =!= mathematica
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Wed, 24 Mar 2010 04:41:28 -0500 (EST)
On 3/23/10 at 4:23 AM, hemmecke at gmail.com (hemmecke) wrote: >Does somebody know why I get different behaviour for the following >General::dupsym: The symbol Array with context A` already exists. >message? Why does that message appear at all? If A`Array exists, >then Mathematica should just use it, shouldn't it? >According to >http://reference.wolfram.com/mathematica/tutorial/Contexts.html we >have: >`name a symbol in the current context >So why is Mathematica complaining? The message is not telling you the symbol exists in the current context. It is simply telling you that symbol exists in some context. In particular, that symbol exists in the System context. It is definitely a bad idea to try an use built-in symbols for something else or redefine built-in symbols. >In[1]:= BeginPackage["A`"] >Out[1]= A` This is acceptable syntax. But do you really want a context with a one letter uppercase name? That practice will almost certainly cause you grief at some point. >In[2]:= {$ContextPath, $Context} >Out[2]= {{A`, System`}, A`} >In[3]:= `Array[c,3]=17 What is it you want to do here? Redefine the built-in symbol Array? Definitely not a good idea. Create an array 3 elements long and assign the value 17 to each? That is In[1]:= Array[c, 3] Out[1]= {c(1),c(2),c(3)} and doing In[2]:= Array[c, 3] = 17 Out[2]= 17 generates an error message saying Array is protected as it should. To assign the value 17 to each element of an array use Table, i.e., In[3]:= Table[c[n] = 17, {n, 3}] Out[3]= {17,17,17} In[4]:= c[1] Out[4]= 17 Assign the value 17 to the third element of array c? Try c[3]=17 Note, in calling c an array here I am being very loose with terms. In truth, c is a function. And when you do c[3]=17 you are defining c to have the value 17 when given the argument 3. Note, In[5]:= c[3.] Out[5]= c(3.) Since no value for a real argument has been defined. And it is possible to do: In[6]:= c[3.23] = 18; c[3.23] Out[7]= 18 In terms of a function, this clearly makes sense. In terms of an array, it is hard to make since of an index with value 3.23