thanks
dly
[EMAIL PROTECTED]


On 3-Jan-07, at 2:59 AM, Dan Bron wrote:

The whole concept of local and global variables is to deal
with assigning the same name both locally and globally.

Not within a single definition. If you did that, you'd only be able to access the value of one "flavor" (in J, the local name).
For example:

           NB.  Run this in J5 ('cause J6 will
           NB.  produce errors, which is the
           NB.  topic of this thread)

           9!:14''
        j504/2005-03-30/13:35
        
           useful =: verb define
        
                a       =. ''         NB.  Local
        
                for_i. i.-#y.  do.
                        a =. a , i{y.   NB.  Local
                end.
        
                a
        
           )
        
           useless =: verb define
        
                a       =. ''         NB.  Local
        
                for_i. i.-#y.  do.
                        a =: a , i{y.   NB.  Global
                end.
        
                a
           )
        
        
           useful  ;:'reverse me, please'
        +------+-+--+-------+
        |please|,|me|reverse|
        +------+-+--+-------+

           useless ;:'not what I expected'
        
        
           a
        +---+
        |not|
        +---+
                
Does this clarify? If not, then maybe an argument in English: local and global variables serve different purposes. Global names are for state persistance and information sharing, whereas the local names are for code clarity (and efficency, sometimes). Assigning both flavors of a name in the same definition is most likely an oversight.

If you're still not convinced, then maybe I misunderstood you. If so, can you provide an example where you need to assign the
same name both locally and globally within a single definition?

-Dan

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to