home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.apl
- Path: sparky!uunet!munnari.oz.au!sgiblab!spool.mu.edu!howland.reston.ans.net!usc!elroy.jpl.nasa.gov!decwrl!csus.edu!sfsuvax1.sfsu.edu!emclean
- From: emclean@sfsuvax1.sfsu.edu (Emmett McLean)
- Subject: Re: Selective assignment (was Re: J is NOT APL)
- Message-ID: <1993Jan27.094037.13820@csus.edu>
- Sender: news@csus.edu
- Organization: San Francisco State University
- References: <1993Jan23.113019.23895@fid.morgan.com> <C1EIJn.I3@quadsys.com> <1993Jan26.184600.24394@csi.jpl.nasa.gov>
- Date: Wed, 27 Jan 1993 09:40:37 GMT
- Lines: 79
-
- NB. In article 1993Jan26.184600.24394@csi.jpl.nasa.gov sam@csi.jpl.nasa.gov (Sam Sirlin) writes:
- NB. .... Though I do think ammend is much more confusing
- NB. than the old standard, reliable, selective assignment, this descision
- NB. had nothing to do with the character set.
- NB.
- NB. I agree with this.
- NB.
- NB. .... There's even lots
- NB. of new ideas and functionality. The only thing that I still find
- NB. missing is selective assignment...
- NB.
- NB. Not sure what Sam means by missing but here is a nice verb
- NB. implementing selective assignment. New Jer's might enjoy looking
- NB. at it. Perhaps this will also touch on the thread of how readable
- NB. J can be. Apologies to bold APL enthusiasts tired of verbose
- NB. postings -:)
-
- NB. (This verb only works on v6.1 & v6.2)
-
- NB. First some redefined J primitives:
- right =. ]
- drop =. }.
- open =. >
- shape =. $
- scalar =. ''&shape
- take =. {.
- base =. #.
- left =. [
- amend =. }
- link =. ;
- integers =. i.
- largOrEql =. >:
- orscan =. +./
- agenda =. @.
- laminate =. ,:
- 9!:3 (5) NB. nice for functional verb displays
-
- NB. and now for the construction :
-
- data =. scalar@:open@drop@right
- positions =. shape@left base open@take@right
- amendNoun =. left
- selectiveAssign =. data`positions`amendNoun amend
-
- NB. As is, "selectiveAssign" works perfectly but in the instance
- NB. where one is indexing into a postion which doesn't exist, it
- NB. sometimes it assigns when it shouldn't. We can make
- NB. "selectiveAssign" return an error in this case:
-
- assign =. data`positions`amendNoun amend NB. old selectiveAssign
- errorMessage =. 'index error (selectiveAssign)'"_
- errorCondition =. scalar@orscan@(open@take@right largOrEql shape@left)
- selectiveAssign =. assign`errorMessage agenda errorCondition
-
- NB. For the indigenous representation :
- assign =. (data f.)`(positions f.)`(amendNoun f.) amend
- selectiveAssign=.(assign f.)`(errorMessage f.)(agenda f.)(errorCondition f.)
-
- NB. lets check (I leave it to you to 0!:2 this file.)
-
- a =. integers 4 4
- b =. 2 1 link 1000
- c =. (2 2 shape 0 1 2 3) link 100 200
- b link a selectiveAssign b
- c link a selectiveAssign c
- a3D =. integers 2 2 2
- b3D =. (1 1 1) link 200
- b3D link a3D selectiveAssign b3D
- ae0 =. 2 5 link 1000
- ae1 =. 5 5 link 1000
- ae2 =. 4 4 link 1000
- ae0 link a selectiveAssign (2 5 link 1000)
- ae1 link a selectiveAssign (2 5 link 1000)
- ae2 link a selectiveAssign (2 5 link 1000)
-
- NB. Of course all this may be making a big deal about something
- NB. which amend would handle nicely.
- NB. Emmett
-
-