Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!uunet.ca!geac!itcyyz!yrloc!hui
From: hui@yrloc.ipsa.reuter.COM (Roger Hui)
Subject: Re: Beginner J questions: local variables
Message-ID: <1992Sep12.055706.3856@yrloc.ipsa.reuter.COM>
Organization: Iverson Software Inc.
References: <1992Sep10.164511.11493@coe.montana.edu>
Date: Sat, 12 Sep 92 05:57:06 GMT
Lines: 21

Lou Glassy writes:
 
> bar =. '(+/ y.) % (# y.)' : ''
> 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.)
 
var calculates bar y. just once.  In any case, names can be assigned
within explicit verbs as without, using =. or =: .  For example:
 
s2 =. '((n*+/*:y.)-*:+/y.)%*:n=.#y.' : ''

------------------------------------
Roger Hui, Iverson Software Inc., 33 Major Street, Toronto, Ontario  M5S 2K9
Phone: (416) 925 6096;  Fax: (416) 488 7559
