Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!cs.utexas.edu!sun-barr!ames!haven.umd.edu!darwin.sura.net!spool.mu.edu!caen!uakari.primate.wisc.edu!usenet.coe.montana.edu!oususalg
From: oususalg@cs.montana.edu (Glassy)
Subject: Beginner J questions: local variables
Message-ID: <1992Sep10.164511.11493@coe.montana.edu>
Sender: usenet@coe.montana.edu (USENET News System)
Organization: Montana State University, Bozeman Montana USA
Date: Thu, 10 Sep 1992 16:45:11 GMT
Lines: 26

Hi J-folk:

Per subj: line, I have some questions on local variables in J.

Here's a verb to find the arithmetic mean of a rank-1 vector:
   
bar =. '(+/ y.) % (# y.)' : ''

ok.  Now I'd like to write a verb to calculate the variance 
of a vector.  The following does the trick:

var =. 'bar *: y. - bar y.' : ''

what i'd like to do, is encapsulate bar y. in a noun local
to the var verb.  var is correct and straightforward, but it
irks me that it recalculates bar y. repeatedly when it doesn't have
to.  can local variables be embedded in verb definitions?  
if so, how?

(i don't *know* that var recalculates bar y.  just a guess.)

thanks in advance...

lou.
-- 
Lou Glassy (oususalg@cs.montana.edu)                  C Delenda Est
