As others have mentioned, this has been discussed before.  You can use the 
Forum searcher form to find the old threads:

Forum searching form:  
   http://www.jsoftware.com/forumsearch  

Threads mentioning 'accgen' or 'accumulator': 
   
http://www.jsoftware.com/cgi-bin/forumsearch.cgi?all=&exa=&one=accgen+accumulator&exc=&add=&sub=&fid=&tim=0&rng=0&dbgn=1&mbgn=1&ybgn=1998&dend=31&mend=12&yend=2006

My contribution to this effort is the 'lexical closure' script, which abuses 
JMF in an amusing manner:

    http://www.jsoftware.com/svn/DanBron/trunk/uncategorized/lexicalclosure.ijs

See the post at:

    http://www.jsoftware.com/pipermail/general/2005-February/020539.html

But, in short:
    
           accGen=. 4 : 'x. =. x. + y.'  lexicalClosureOnRHA
        
           acc0 =. 0 accGen 
           acc0 1
        1
           acc0 1
        2
        
           acc10 =. 10 accGen  NB.  Start with 10
           acc10 78.5
        88.5
           
           100 accGen"0 i. 10  NB.  Anonymous accumulator
        100 101 103 106 110 115 121 128 136 145


This is a FAQ, so I've written it up at 
http://www.jsoftware.com/jwiki/LexicalClosure and added it to 
http://www.jsoftware.com/jwiki/Doc/FAQ  .  I didn't do much more than quote 
myself, so I'd appreciate any copy editing or re-thinking you can do for that 
page.

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

Reply via email to