Re: RandomReal gets stuck
- To: mathgroup at smc.vnet.net
- Subject: [mg100428] Re: RandomReal gets stuck
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Wed, 3 Jun 2009 01:11:57 -0400 (EDT)
On 6/2/09 at 6:44 AM, bastraat at ucalgary.ca (Bas Straatman) wrote: >By the way, Bill, there is nothing wrong with the use of square >brackets to index a variable. Check out the array function: >In[1]:= Array[y, 3] >Out[1]= {y[1], y[2], y[3]} >In[2]:= Do[y[i] = 3 - i, {i, 3}] >In[3]:= ?y >Global`y >y[1]=2 >y[2]=1 >y[3]=0 >In[4]:= Head[y] >Out[4]= Symbol >In[5]:= Head[y[1]] >Out[5]= Integer My comments about y[1] were not that this is invalid syntax or that it cannot be used in *some* cases like an indexed array or subscripted variable. The point is it cannot be used as an indexed array or subscripted variable in *all* cases. The syntax y[1] is for a function named y evaluated at 1. The is not the same as an indexed array nor the same as a subscripted variable. In fact, the it does not even behave like an ordinary variable in all ways. Specifically, for a ordinary symbol assignments cause that symbol to have an OwnValue not a DownValue. Assignments to a function cause the function to have a DownValue not an OwnValue. These are different and the difference as consequences in some evaluations. If you have a clear understanding of the differences between DownValues and OwnValues and know what you are doing, you undoubtedly will get the result you want when treating y[1] as a subscripted variable. On the other hand, if you lack a clear understanding of the differences sooner or later you will encounter unexpected issues (not bugs) when using y[1] as a subscripted variable.