home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / hp48 / 6505 < prev    next >
Encoding:
Internet Message Format  |  1992-12-24  |  2.1 KB

  1. Path: sparky!uunet!wupost!spool.mu.edu!agate!dog.ee.lbl.gov!network.ucsd.edu!rutgers!modus!gear!cflav!flavio
  2. From: flavio@cflav.sublink.org (Flavio Casetta)
  3. Newsgroups: comp.sys.hp48
  4. Subject: Re: Utility: applylist
  5. Message-ID: <1L77VB1w164w@cflav.sublink.org>
  6. Date: 22 Dec 92 16:59:35 GMT
  7. Organization: Flavio Casetta, Reg'd HP ISV & OEM of handheld computers.
  8. Lines: 62
  9.  
  10. Excerpted from Klaus Kalb article...
  11.  
  12. > There is one thing I always missed from UserRPL: The possiblity to 
  13. > iterate a program over all entries in  a list.
  14. > Something like
  15. >   FOR obj IN list DO ... END
  16. > would sometimes be handy. So I wrote a utility the offers a workaround.
  17. > APPLYLIST takes to arguments:
  18. >  A list in level 2, lets assume it's L = { O1 O2 ... On }
  19. >  Anything in level 1, lets call this P
  20. >  and it does
  21. > - Bind L,P and the current depth to local vars (unnamed ones)
  22. > - Push O1 to the stack, execute P
  23. > - Push O2 to the stack, execute P
  24. >  ...
  25. > - Push On to the stack, execute P
  26. > - Make all new objects on the stack into a list
  27. >
  28. > Examples:
  29. > --- Double all numbers in a list
  30. > { 1 2 3 } 
  31. > \<< 2 * \>> 
  32. > APPLYLIST  --> { 2 4 6 }
  33. >
  34. > --- Double all numbers in a list, in a somewhat different sense
  35. > { 1 2 3 } 
  36. > \<< DUP \>> 
  37. > APPLYLIST  --> { 1 1 2 2 3 3 }
  38. >
  39. > --- Delete all zeros from a list
  40. > { 0 1 2 0 3 4 }
  41. > \<< IF DUP 0 SAME THEN DROP END \>> 
  42. > APPLYLIST  --> { 1 2 3 4 }
  43. > --- Add up all numbers in the list
  44. > 0
  45. > { 1 2 3 4 }
  46. > \<< + \>>
  47. > APPLYLIST   --> 10 { }
  48. >
  49. > --- Find the amount of mem used in port 0
  50. > 0 DUP PVARS DROP \<< RCL BYTES SWAP DROP + \>> APPLYLIST DROP 
  51. >
  52. > ---     Recall all vars to the stack and tag them with their name:
  53. > VARS \<< DUP RCL SWAP \->TAG \>> APPLYLIST DROP
  54. >
  55.  
  56.  
  57. The SmartROM contains this keyword, named LOP1, (and many variations on the 
  58. theme as well LOPN, METOP, RPT) since early 1991.
  59.  
  60.  
  61. Bye,
  62.  
  63. Flavio
  64. __
  65. * flavio@cflav.sublink.org (Flavio Casetta)
  66.  ---------------------------------------------------------------------
  67. | The usual disclaimer does not apply      |   +59 440404 (Vox populi) |
  68. | ForCALC's opinions are necessarily mine  |   +59 304490 (Fax dei)    |
  69.