Does somebody know why I get different behaviour for the following commands in a commandline session of mathematica 7 or inside a notebook? It also seems to be different in different Mathematica versions for the notebook format. See http://www.risc.jku.at/people/hemmecke/mathematica/ for the notebook files for Mathematica 5.2, 6.0, 7.0. Can someone explain the 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? Ralf >math Mathematica 7.0 for Linux x86 (32-bit) Copyright 1988-2008 Wolfram Research, Inc. In[1]:= BeginPackage["A`"] Out[1]= A` In[2]:= {$ContextPath, $Context} Out[2]= {{A`, System`}, A`} In[3]:= `Array[c,3]=17 Array::shdw: Symbol Array appears in multiple contexts {A`, System`} ; definitions in context A` may shadow or be shadowed by other definitions. Out[3]= 17 In[4]:= Array[c,3] Out[4]= 17 In[5]:= `Array[c,3] General::dupsym: The symbol Array with context A` already exists. Out[5]= Removed[Array][c, 3] In[6]:= A`Array[c,3] Out[6]= 17

0 |

3/23/2010 9:23:02 AM

Hi Ralf, in Mathematica it is usage that user identifier should always start with a lower case letter. System names always start with a capital. This prevents any conflicts. A further mean is the usage of BeginPackage, Begin, End, EndPackage, but I think you know about this. Daniel On 24.03.2010 13:09, Ralf Hemmecke wrote: > Oh, it was exactly what I wanted. Suppose, I write a big Mathematica package > with lots of new names that I export in my context. > Everything works fine for Mathematica up to version 7. Now assume in version 8 > one of my identifiers is suddenly a member of Mathematica's System` > context. > > Using Array in my proposed code was just an example of this situation. > You can even suppose that I don't want to export my identifier, i.e. my > Array would only appear in the A`Private` context. > > Of course, I don't want that the internals of my code suddenly break, > because an identifier I use in a private context is exposed from System` > and thus probably protected and not changable. > > What can I do? > > Ralf > > > On 03/24/2010 12:28 PM, dh wrote: >> Hi Ralf, >> if you say: `Array[c,3]=17 you are not calling the function "Array" that >> lives in the System context, but you create a new symbol in the context >> "A". Hardly what you want. >> Daniel >> >> >> On 23.03.2010 10:23, hemmecke wrote: >>> Does somebody know why I get different behaviour for the following >>> commands in a commandline session of mathematica 7 or inside a notebook? >>> It also seems to be different in different Mathematica versions for the >>> notebook format. >>> See http://www.risc.jku.at/people/hemmecke/mathematica/ for the >>> notebook files for Mathematica 5.2, 6.0, 7.0. >>> >>> Can someone explain the >>> >>> 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? >>> >>> Ralf >>> >>>> math >>> Mathematica 7.0 for Linux x86 (32-bit) >>> Copyright 1988-2008 Wolfram Research, Inc. >>> >>> In[1]:= BeginPackage["A`"] >>> >>> Out[1]= A` >>> >>> In[2]:= {$ContextPath, $Context} >>> >>> Out[2]= {{A`, System`}, A`} >>> >>> In[3]:= `Array[c,3]=17 >>> >>> Array::shdw: Symbol Array appears in multiple contexts {A`, System`} >>> ; definitions in context A` may shadow or be shadowed by other >>> definitions. >>> >>> Out[3]= 17 >>> >>> In[4]:= Array[c,3] >>> >>> Out[4]= 17 >>> >>> In[5]:= `Array[c,3] >>> >>> General::dupsym: The symbol Array with context A` already exists. >>> >>> Out[5]= Removed[Array][c, 3] >>> >>> In[6]:= A`Array[c,3] >>> >>> Out[6]= 17 >>> >> >> > > > -- Daniel Huber Metrohm AG International Headquarters Oberdorfstr. 68, CH-9101 Herisau / Switzerland Phone +41 71 353 8606, Fax +41 71 353 89 01 Mail <mailto:dh@metrohm.com> Web <http://www.metrohm.com

0 |

3/25/2010 9:22:03 AM

Hi Ralf, if you say: `Array[c,3]=17 you are not calling the function "Array" that lives in the System context, but you create a new symbol in the context "A". Hardly what you want. Daniel On 23.03.2010 10:23, hemmecke wrote: > Does somebody know why I get different behaviour for the following > commands in a commandline session of mathematica 7 or inside a notebook? > It also seems to be different in different Mathematica versions for the > notebook format. > See http://www.risc.jku.at/people/hemmecke/mathematica/ for the > notebook files for Mathematica 5.2, 6.0, 7.0. > > Can someone explain the > > 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? > > Ralf > >> math > Mathematica 7.0 for Linux x86 (32-bit) > Copyright 1988-2008 Wolfram Research, Inc. > > In[1]:= BeginPackage["A`"] > > Out[1]= A` > > In[2]:= {$ContextPath, $Context} > > Out[2]= {{A`, System`}, A`} > > In[3]:= `Array[c,3]=17 > > Array::shdw: Symbol Array appears in multiple contexts {A`, System`} > ; definitions in context A` may shadow or be shadowed by other > definitions. > > Out[3]= 17 > > In[4]:= Array[c,3] > > Out[4]= 17 > > In[5]:= `Array[c,3] > > General::dupsym: The symbol Array with context A` already exists. > > Out[5]= Removed[Array][c, 3] > > In[6]:= A`Array[c,3] > > Out[6]= 17 > -- Daniel Huber Metrohm Ltd. Oberdorfstr. 68 CH-9100 Herisau Tel. +41 71 353 8585, Fax +41 71 353 8907 E-Mail:<mailto:dh@metrohm.com> Internet:<http://www.metrohm.com>

0 |

3/25/2010 9:23:56 AM

Dear Daniel, > in Mathematica it is usage that user identifier should always start with a lower > case letter. And what if I have to maintain a system where that convention (is that written somewhere, actually?) is not followed? I cannot easily change the user interface of that package. > System names always start with a capital. This prevents any > conflicts. Well, yes, but I haven't written those packages and people don't always follow conventions. And as written at http://reference.wolfram.com/mathematica/tutorial/DefiningVariables.html under "A useful principle in using Mathematica": """ Mathematica uses both uppercase and lowercase letters. There is a convention that built-in Mathematica objects always have names starting with uppercase (capital) letters. To avoid confusion, you should always choose names for your own variables that start with lowercase letters. """ It doesn't say that may code is forbidden to use capital letters or "words starting with capital letters are reserved Mathematica identifiers". So Mathematica should behave properly even when I use idenifiers that are already defined in the System` context. > A further mean is the usage of BeginPackage, Begin, End, EndPackage, but > I think you know about this. As you have seen in my code, shielding something with BeginPackage does not always help. I still don't know why my code behaves so strangely. In particular, I don't understand the "Removed[Array]" part. I don't see that I have entered a "Remove" command. Mathematica clearly does not behave according its own specification and this is what bothers me. Ralf > Daniel > > On 24.03.2010 13:09, Ralf Hemmecke wrote: >> Oh, it was exactly what I wanted. Suppose, I write a big Mathematica package >> with lots of new names that I export in my context. >> Everything works fine for Mathematica up to version 7. Now assume in version 8 >> one of my identifiers is suddenly a member of Mathematica's System` >> context. >> >> Using Array in my proposed code was just an example of this situation. >> You can even suppose that I don't want to export my identifier, i.e. my >> Array would only appear in the A`Private` context. >> >> Of course, I don't want that the internals of my code suddenly break, >> because an identifier I use in a private context is exposed from System` >> and thus probably protected and not changable. >> >> What can I do? >> >> Ralf >> >> >> On 03/24/2010 12:28 PM, dh wrote: >>> Hi Ralf, >>> if you say: `Array[c,3]=17 you are not calling the function "Array" that >>> lives in the System context, but you create a new symbol in the context >>> "A". Hardly what you want. >>> Daniel >>> >>> >>> On 23.03.2010 10:23, hemmecke wrote: >>>> Does somebody know why I get different behaviour for the following >>>> commands in a commandline session of mathematica 7 or inside a >>>> notebook? >>>> It also seems to be different in different Mathematica versions for the >>>> notebook format. >>>> See http://www.risc.jku.at/people/hemmecke/mathematica/ for the >>>> notebook files for Mathematica 5.2, 6.0, 7.0. >>>> >>>> Can someone explain the >>>> >>>> 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? >>>> >>>> Ralf >>>> >>>>> math >>>> Mathematica 7.0 for Linux x86 (32-bit) >>>> Copyright 1988-2008 Wolfram Research, Inc. >>>> >>>> In[1]:= BeginPackage["A`"] >>>> >>>> Out[1]= A` >>>> >>>> In[2]:= {$ContextPath, $Context} >>>> >>>> Out[2]= {{A`, System`}, A`} >>>> >>>> In[3]:= `Array[c,3]=17 >>>> >>>> Array::shdw: Symbol Array appears in multiple contexts {A`, System`} >>>> ; definitions in context A` may shadow or be shadowed by other >>>> definitions. >>>> >>>> Out[3]= 17 >>>> >>>> In[4]:= Array[c,3] >>>> >>>> Out[4]= 17 >>>> >>>> In[5]:= `Array[c,3] >>>> >>>> General::dupsym: The symbol Array with context A` already exists. >>>> >>>> Out[5]= Removed[Array][c, 3] >>>> >>>> In[6]:= A`Array[c,3] >>>> >>>> Out[6]= 17 >>>> >>> >>> >> >> >> > >

0 |

3/25/2010 9:24:53 AM

Hi Ralf, If you insist on using the same identifiers that are already defined in System`, you may set the $ContextPath to your own context. But if you then want to use a function from System, you need to qualify it like: System`... Daniel On 24.03.2010 22:31, Ralf Hemmecke wrote: > Dear Daniel, > >> in Mathematica it is usage that user identifier should always start with a lower >> case letter. > > And what if I have to maintain a system where that convention (is that > written somewhere, actually?) is not followed? I cannot easily change > the user interface of that package. > >> System names always start with a capital. This prevents any >> conflicts. > > Well, yes, but I haven't written those packages and people don't always > follow conventions. > > And as written at > http://reference.wolfram.com/mathematica/tutorial/DefiningVariables.html > under "A useful principle in using Mathematica": > > """ > Mathematica uses both uppercase and lowercase letters. There is a > convention that built-in Mathematica objects always have names starting > with uppercase (capital) letters. To avoid confusion, you should always > choose names for your own variables that start with lowercase letters. > """ > > It doesn't say that may code is forbidden to use capital letters or > "words starting with capital letters are reserved Mathematica > identifiers". So Mathematica should behave properly even when I use > idenifiers that are already defined in the System` context. > >> A further mean is the usage of BeginPackage, Begin, End, EndPackage, but >> I think you know about this. > > As you have seen in my code, shielding something with BeginPackage does > not always help. I still don't know why my code behaves so strangely. In > particular, I don't understand the "Removed[Array]" part. I don't see > that I have entered a "Remove" command. > > Mathematica clearly does not behave according its own specification and > this is what bothers me. > > Ralf > >> Daniel >> >> On 24.03.2010 13:09, Ralf Hemmecke wrote: >>> Oh, it was exactly what I wanted. Suppose, I write a big Mathematica package >>> with lots of new names that I export in my context. >>> Everything works fine for Mathematica up to version 7. Now assume in version 8 >>> one of my identifiers is suddenly a member of Mathematica's System` >>> context. >>> >>> Using Array in my proposed code was just an example of this situation. >>> You can even suppose that I don't want to export my identifier, i.e. my >>> Array would only appear in the A`Private` context. >>> >>> Of course, I don't want that the internals of my code suddenly break, >>> because an identifier I use in a private context is exposed from System` >>> and thus probably protected and not changable. >>> >>> What can I do? >>> >>> Ralf >>> >>> >>> On 03/24/2010 12:28 PM, dh wrote: >>>> Hi Ralf, >>>> if you say: `Array[c,3]=17 you are not calling the function "Array" >>>> that >>>> lives in the System context, but you create a new symbol in the context >>>> "A". Hardly what you want. >>>> Daniel >>>> >>>> >>>> On 23.03.2010 10:23, hemmecke wrote: >>>>> Does somebody know why I get different behaviour for the following >>>>> commands in a commandline session of mathematica 7 or inside a >>>>> notebook? >>>>> It also seems to be different in different Mathematica versions for >>>>> the >>>>> notebook format. >>>>> See http://www.risc.jku.at/people/hemmecke/mathematica/ for the >>>>> notebook files for Mathematica 5.2, 6.0, 7.0. >>>>> >>>>> Can someone explain the >>>>> >>>>> 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? >>>>> >>>>> Ralf >>>>> >>>>>> math >>>>> Mathematica 7.0 for Linux x86 (32-bit) >>>>> Copyright 1988-2008 Wolfram Research, Inc. >>>>> >>>>> In[1]:= BeginPackage["A`"] >>>>> >>>>> Out[1]= A` >>>>> >>>>> In[2]:= {$ContextPath, $Context} >>>>> >>>>> Out[2]= {{A`, System`}, A`} >>>>> >>>>> In[3]:= `Array[c,3]=17 >>>>> >>>>> Array::shdw: Symbol Array appears in multiple contexts {A`, System`} >>>>> ; definitions in context A` may shadow or be shadowed by other >>>>> definitions. >>>>> >>>>> Out[3]= 17 >>>>> >>>>> In[4]:= Array[c,3] >>>>> >>>>> Out[4]= 17 >>>>> >>>>> In[5]:= `Array[c,3] >>>>> >>>>> General::dupsym: The symbol Array with context A` already exists. >>>>> >>>>> Out[5]= Removed[Array][c, 3] >>>>> >>>>> In[6]:= A`Array[c,3] >>>>> >>>>> Out[6]= 17 >>>>> >>>> >>>> >>> >>> >>> >> >> > > > -- Daniel Huber Metrohm AG International Headquarters Oberdorfstr. 68, CH-9101 Herisau / Switzerland Phone +41 71 353 8606, Fax +41 71 353 89 01 Mail <mailto:dh@metrohm.com> Web <http://www.metrohm.com

0 |

3/25/2010 9:27:17 AM

Oh, it was exactly what I wanted. Suppose, I write a big Mathematica package with lots of new names that I export in my context. Everything works fine for Mathematica up to version 7. Now assume in version 8 one of my identifiers is suddenly a member of Mathematica's System` context. Using Array in my proposed code was just an example of this situation. You can even suppose that I don't want to export my identifier, i.e. my Array would only appear in the A`Private` context. Of course, I don't want that the internals of my code suddenly break, because an identifier I use in a private context is exposed from System` and thus probably protected and not changable. What can I do? Ralf On 03/24/2010 12:28 PM, dh wrote: > Hi Ralf, > if you say: `Array[c,3]=17 you are not calling the function "Array" that > lives in the System context, but you create a new symbol in the context > "A". Hardly what you want. > Daniel > > > On 23.03.2010 10:23, hemmecke wrote: >> Does somebody know why I get different behaviour for the following >> commands in a commandline session of mathematica 7 or inside a notebook? >> It also seems to be different in different Mathematica versions for the >> notebook format. >> See http://www.risc.jku.at/people/hemmecke/mathematica/ for the >> notebook files for Mathematica 5.2, 6.0, 7.0. >> >> Can someone explain the >> >> 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? >> >> Ralf >> >>> math >> Mathematica 7.0 for Linux x86 (32-bit) >> Copyright 1988-2008 Wolfram Research, Inc. >> >> In[1]:= BeginPackage["A`"] >> >> Out[1]= A` >> >> In[2]:= {$ContextPath, $Context} >> >> Out[2]= {{A`, System`}, A`} >> >> In[3]:= `Array[c,3]=17 >> >> Array::shdw: Symbol Array appears in multiple contexts {A`, System`} >> ; definitions in context A` may shadow or be shadowed by other >> definitions. >> >> Out[3]= 17 >> >> In[4]:= Array[c,3] >> >> Out[4]= 17 >> >> In[5]:= `Array[c,3] >> >> General::dupsym: The symbol Array with context A` already exists. >> >> Out[5]= Removed[Array][c, 3] >> >> In[6]:= A`Array[c,3] >> >> Out[6]= 17 >> > >

0 |

3/25/2010 9:28:34 AM

Hi, if you don't want to use the lower case trick, use fully qualified names. This is include the context in the name. Daniel On 25.03.2010 10:28, Ralf Hemmecke wrote: > Oh, it was exactly what I wanted. Suppose, I write a big Mathematica package > with lots of new names that I export in my context. > Everything works fine for Mathematica up to version 7. Now assume in version 8 > one of my identifiers is suddenly a member of Mathematica's System` context. > > Using Array in my proposed code was just an example of this situation. > You can even suppose that I don't want to export my identifier, i.e. my > Array would only appear in the A`Private` context. > > Of course, I don't want that the internals of my code suddenly break, > because an identifier I use in a private context is exposed from System` > and thus probably protected and not changable. > > What can I do? > > Ralf > > > On 03/24/2010 12:28 PM, dh wrote: >> Hi Ralf, >> if you say: `Array[c,3]=17 you are not calling the function "Array" that >> lives in the System context, but you create a new symbol in the context >> "A". Hardly what you want. >> Daniel >> >> >> On 23.03.2010 10:23, hemmecke wrote: >>> Does somebody know why I get different behaviour for the following >>> commands in a commandline session of mathematica 7 or inside a notebook? >>> It also seems to be different in different Mathematica versions for the >>> notebook format. >>> See http://www.risc.jku.at/people/hemmecke/mathematica/ for the >>> notebook files for Mathematica 5.2, 6.0, 7.0. >>> >>> Can someone explain the >>> >>> 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? >>> >>> Ralf >>> >>>> math >>> Mathematica 7.0 for Linux x86 (32-bit) >>> Copyright 1988-2008 Wolfram Research, Inc. >>> >>> In[1]:= BeginPackage["A`"] >>> >>> Out[1]= A` >>> >>> In[2]:= {$ContextPath, $Context} >>> >>> Out[2]= {{A`, System`}, A`} >>> >>> In[3]:= `Array[c,3]=17 >>> >>> Array::shdw: Symbol Array appears in multiple contexts {A`, System`} >>> ; definitions in context A` may shadow or be shadowed by other >>> definitions. >>> >>> Out[3]= 17 >>> >>> In[4]:= Array[c,3] >>> >>> Out[4]= 17 >>> >>> In[5]:= `Array[c,3] >>> >>> General::dupsym: The symbol Array with context A` already exists. >>> >>> Out[5]= Removed[Array][c, 3] >>> >>> In[6]:= A`Array[c,3] >>> >>> Out[6]= 17 >>> >> >> > -- Daniel Huber Metrohm Ltd. Oberdorfstr. 68 CH-9100 Herisau Tel. +41 71 353 8585, Fax +41 71 353 8907 E-Mail:<mailto:dh@metrohm.com> Internet:<http://www.metrohm.com>

0 |

3/26/2010 10:36:57 AM

Perhaps don't start `Private` names with a capital letter? It wouldn't be that much work to change any over. David Park djmpark@comcast.net http://home.comcast.net/~djmpark/ From: Ralf Hemmecke [mailto:hemmecke@gmail.com] Oh, it was exactly what I wanted. Suppose, I write a big Mathematica package with lots of new names that I export in my context. Everything works fine for Mathematica up to version 7. Now assume in version 8 one of my identifiers is suddenly a member of Mathematica's System` context. Using Array in my proposed code was just an example of this situation. You can even suppose that I don't want to export my identifier, i.e. my Array would only appear in the A`Private` context. Of course, I don't want that the internals of my code suddenly break, because an identifier I use in a private context is exposed from System` and thus probably protected and not changable. What can I do? Ralf On 03/24/2010 12:28 PM, dh wrote: > Hi Ralf, > if you say: `Array[c,3]=17 you are not calling the function "Array" that > lives in the System context, but you create a new symbol in the context > "A". Hardly what you want. > Daniel > > > On 23.03.2010 10:23, hemmecke wrote: >> Does somebody know why I get different behaviour for the following >> commands in a commandline session of mathematica 7 or inside a notebook? >> It also seems to be different in different Mathematica versions for the >> notebook format. >> See http://www.risc.jku.at/people/hemmecke/mathematica/ for the >> notebook files for Mathematica 5.2, 6.0, 7.0. >> >> Can someone explain the >> >> 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? >> >> Ralf >> >>> math >> Mathematica 7.0 for Linux x86 (32-bit) >> Copyright 1988-2008 Wolfram Research, Inc. >> >> In[1]:= BeginPackage["A`"] >> >> Out[1]= A` >> >> In[2]:= {$ContextPath, $Context} >> >> Out[2]= {{A`, System`}, A`} >> >> In[3]:= `Array[c,3]=17 >> >> Array::shdw: Symbol Array appears in multiple contexts {A`, System`} >> ; definitions in context A` may shadow or be shadowed by other >> definitions. >> >> Out[3]= 17 >> >> In[4]:= Array[c,3] >> >> Out[4]= 17 >> >> In[5]:= `Array[c,3] >> >> General::dupsym: The symbol Array with context A` already exists. >> >> Out[5]= Removed[Array][c, 3] >> >> In[6]:= A`Array[c,3] >> >> Out[6]= 17 >> > >

0 |

3/26/2010 10:38:12 AM