Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!cs.utexas.edu!sdd.hp.com!swrinde!elroy.jpl.nasa.gov!jato!csi!sam
From: sam@csi.jpl.nasa.gov (Sam Sirlin)
Subject: Re: Selective assignment "It ain't so..."
Message-ID: <1993Feb4.003201.1361@csi.jpl.nasa.gov>
Originator: sam@kalessin
Sender: usenet@csi.jpl.nasa.gov (Network Noise Transfer Service)
Nntp-Posting-Host: kalessin
Organization: Jet Propulsion Laboratory, Pasadena, CA
References: <1993Jan27.094037.13820@csus.edu> <1993Jan27.221845.11152@csi.jpl.nasa.gov> <1535@kepler1.rentec.com> <1993Feb3.034055.12287@csus.edu>
Date: Thu, 4 Feb 1993 00:32:01 GMT
Lines: 70


In article <1993Feb3.034055.12287@csus.edu>, emclean@sfsuvax1.sfsu.edu (Emmett McLean) writes:
|>   "It ain't so..." Or rather, if it is so, could someone explain it 
|>   to me, I think I demonstrate it is not (so) in the next few lines 
|>   from an interactive session.
|> 
|>    NB. load selectiveAssign
|>    0!:3 <'A.js'
|>    NB. spaced needed to create a table with 100 rows and
|>    NB. 100 columns with each entry equal to 1000 is :
|>    7!:2 'a =. 100 100 $ 1000'
|> 40408
|>    NB. space used to use Emmett's selectiveAssign on a is :
|>    7!:2 'a =. a selectiveAssign (2 1 ; 1000)'
|> 81848
|>    NB. space used to used to do Sam's selective assignment is:
|>    7!:2 'a =. 1000 (21) } a'
|> 41048

Not so fast! On a sun sparc I get:
   7!:2 'a =. 100 100 $ 1000'
40408
   7!:2 'a =. a selectiveAssign (2 1 ; 1000)'
81848
   index  NB. my function
$@] #. [
   7!:2 'a=. 1000 (2 1&index@]) } a'  NB. my normal use of it 
81112
   7!:2 'a=. 1000 (2 1&index a) } a'  NB. another version !?
41612
   7!:2 'a=. 1000 (201)} a'  
41040

So my index function isn't much better than selectiveAssign when used
the way I'd like to use it! I looks like only "raw" ammend works
space-effiently.

|>  So when Sam writes :
|> >
|> >>Good idea. What I meant is that there is no way to change a part of an
|> >>existing structure, though you can make an ammended copy. I've heard
|> >>functional justifications for the restriction, but still miss
|> >>reassignment. I use it all the time in APL, for setting up arrays
|> >>with a given simple pattern and then changing parts for special cases.
|> >
|>   I think he means there is no way to change part of an existing
|>   structure using a verb whose syntax is like selectiveAssign
|>   (or like his wish verb thing) and not make a copy of the structure. 

Well sort of. What I ment was there's no way in J to specify that the
ith element of an existing array should be changed. For example in the
above example:

   a=. 1000 (201)} a

means take a, build a copy with the 201'st element set to 1000, then
assign this copy to a. Apparently the interpreter is able to recognize
(in some situations) that it doesn't need the copy and saves space
(which I didn't know).

|>   Suddenly I'm not so crazy about my verb selectiveAssign -:)

It does look like you pay a penalty for the functionality you want. It
looks like you could build it into an index function, but that ammend
has to be left "outside" to get the interpreter smarts.

-- 
Sam Sirlin
Jet Propulsion Laboratory         sam@kalessin.jpl.nasa.gov

