home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / apl / 1393 < prev    next >
Encoding:
Text File  |  1993-01-28  |  3.1 KB  |  91 lines

  1. Newsgroups: comp.lang.apl
  2. 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
  3. From: emclean@sfsuvax1.sfsu.edu (Emmett McLean)
  4. Subject: Re: Selective assignment (was Re: J is NOT APL)
  5. Message-ID: <1993Jan27.094037.13820@csus.edu>
  6. Sender: news@csus.edu
  7. Organization: San Francisco State University
  8. References: <1993Jan23.113019.23895@fid.morgan.com> <C1EIJn.I3@quadsys.com> <1993Jan26.184600.24394@csi.jpl.nasa.gov>
  9. Date: Wed, 27 Jan 1993 09:40:37 GMT
  10. Lines: 79
  11.  
  12. NB. In article 1993Jan26.184600.24394@csi.jpl.nasa.gov sam@csi.jpl.nasa.gov (Sam Sirlin) writes:
  13. NB. .... Though I do think ammend is much more confusing
  14. NB. than the old standard, reliable, selective assignment, this descision
  15. NB. had nothing to do with the character set.
  16. NB. 
  17. NB.  I agree with this.
  18. NB. 
  19. NB. .... There's even lots
  20. NB. of new ideas and functionality. The only thing that I still find
  21. NB. missing is selective assignment...
  22. NB. 
  23. NB.    Not sure what Sam means by missing but here is a nice verb
  24. NB.    implementing selective assignment.  New Jer's might enjoy looking
  25. NB.    at it.  Perhaps this will also touch on the thread of how readable
  26. NB.    J can be. Apologies to bold APL enthusiasts tired of verbose
  27. NB.    postings -:)
  28.  
  29. NB.    (This verb only works on v6.1 & v6.2)
  30.  
  31. NB.    First some redefined  J primitives:
  32.    right =. ]
  33.    drop =. }.
  34.    open =. > 
  35.    shape =. $
  36.    scalar =. ''&shape 
  37.    take =. {.
  38.    base =. #.
  39.    left =. [
  40.    amend =. }
  41.    link =. ;
  42.    integers =. i.
  43.    largOrEql =. >:
  44.    orscan =. +./
  45.    agenda =. @.
  46.    laminate =. ,:
  47.    9!:3 (5) NB. nice for functional verb displays 
  48.   
  49. NB. and now for the construction :
  50.  
  51.    data =. scalar@:open@drop@right
  52.    positions =. shape@left base open@take@right
  53.    amendNoun =. left
  54.    selectiveAssign =. data`positions`amendNoun amend 
  55.  
  56. NB.    As is, "selectiveAssign" works perfectly  but in the instance
  57. NB.    where one is indexing into a postion which doesn't exist, it 
  58. NB.    sometimes it assigns when it shouldn't.  We can make
  59. NB.    "selectiveAssign" return an error in this case:
  60.  
  61.    assign =. data`positions`amendNoun amend  NB. old selectiveAssign
  62.    errorMessage =. 'index error (selectiveAssign)'"_
  63.    errorCondition =. scalar@orscan@(open@take@right largOrEql shape@left) 
  64.    selectiveAssign =. assign`errorMessage agenda errorCondition
  65.  
  66. NB. For the indigenous representation :
  67.    assign =. (data f.)`(positions f.)`(amendNoun f.) amend 
  68.    selectiveAssign=.(assign f.)`(errorMessage f.)(agenda f.)(errorCondition f.)
  69.  
  70. NB. lets check (I leave it to you to 0!:2 this file.)
  71.  
  72.    a =. integers 4 4
  73.    b =. 2 1 link 1000
  74.    c =. (2 2 shape 0 1 2 3) link 100 200
  75.    b link a selectiveAssign b
  76.    c link a selectiveAssign c
  77.    a3D =. integers 2 2 2
  78.    b3D =. (1 1 1) link 200
  79.    b3D link a3D selectiveAssign b3D
  80.    ae0 =. 2 5 link 1000
  81.    ae1 =. 5 5 link 1000
  82.    ae2 =. 4 4 link 1000
  83.    ae0 link a selectiveAssign (2 5 link 1000) 
  84.    ae1 link a selectiveAssign (2 5 link 1000) 
  85.    ae2 link a selectiveAssign (2 5 link 1000) 
  86.  
  87. NB. Of course all this may be making a big deal about something
  88. NB. which amend would handle nicely. 
  89. NB.    Emmett
  90.  
  91.