On 3/23/10 at 4:23 AM, hemmecke@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

0 |

3/24/2010 9:32:37 AM

> >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. I prepared my message for a short demonstration. Of course, I don't use just A` as a context name. But, actually, what's wrong with A` except for a name that is not conveying any meaning. It's a proper name for a Mathematica context. Am I wrong? > >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. OK, let me make my point clearer. Suppose we are in 2008 or even 2007. http://www.wolfram.com/news/mathwire/mw-01-2009.html That is, I am using Mathematica 6 and I'm writing a package that deals with q- binomials. Since I know, how to define them, I create a package and define a function MyPackage`QBinomial that takes 3 parameters. Of course, everything works fine, every test passes and I release it to the public. Then in 2009 Mathematica 7 come out and suddenly my package is broken. You can also assume that I don't export my QBinomial, but just have it in a `Private` context. Still, I don't want that any new Mathematica version should influence my definition. So replace Array in my previous code by QBinomial and appropriate definitions and then maybe you know what the problem is. And no matter what, but don't you find In[5]:= `Array[c,3] General::dupsym: The symbol Array with context A` already exists. Out[5]= Removed[Array][c, 3] a bit strange? Why "Removed[Array]"? I've never entered a "Remove" command. Ralf

0 |

3/25/2010 9:27:38 AM