home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!wupost!spool.mu.edu!agate!dog.ee.lbl.gov!network.ucsd.edu!rutgers!modus!gear!cflav!flavio
- From: flavio@cflav.sublink.org (Flavio Casetta)
- Newsgroups: comp.sys.hp48
- Subject: Re: Utility: applylist
- Message-ID: <1L77VB1w164w@cflav.sublink.org>
- Date: 22 Dec 92 16:59:35 GMT
- Organization: Flavio Casetta, Reg'd HP ISV & OEM of handheld computers.
- Lines: 62
-
- Excerpted from Klaus Kalb article...
-
- > There is one thing I always missed from UserRPL: The possiblity to
- > iterate a program over all entries in a list.
- > Something like
- > FOR obj IN list DO ... END
- > would sometimes be handy. So I wrote a utility the offers a workaround.
- >
- > APPLYLIST takes to arguments:
- > A list in level 2, lets assume it's L = { O1 O2 ... On }
- > Anything in level 1, lets call this P
- > and it does
- > - Bind L,P and the current depth to local vars (unnamed ones)
- > - Push O1 to the stack, execute P
- > - Push O2 to the stack, execute P
- > ...
- > - Push On to the stack, execute P
- > - Make all new objects on the stack into a list
- >
- > Examples:
- >
- > --- Double all numbers in a list
- > { 1 2 3 }
- > \<< 2 * \>>
- > APPLYLIST --> { 2 4 6 }
- >
- > --- Double all numbers in a list, in a somewhat different sense
- > { 1 2 3 }
- > \<< DUP \>>
- > APPLYLIST --> { 1 1 2 2 3 3 }
- >
- > --- Delete all zeros from a list
- > { 0 1 2 0 3 4 }
- > \<< IF DUP 0 SAME THEN DROP END \>>
- > APPLYLIST --> { 1 2 3 4 }
- >
- > --- Add up all numbers in the list
- > 0
- > { 1 2 3 4 }
- > \<< + \>>
- > APPLYLIST --> 10 { }
- >
- > --- Find the amount of mem used in port 0
- > 0 DUP PVARS DROP \<< RCL BYTES SWAP DROP + \>> APPLYLIST DROP
- >
- > --- Recall all vars to the stack and tag them with their name:
- > VARS \<< DUP RCL SWAP \->TAG \>> APPLYLIST DROP
- >
-
-
- The SmartROM contains this keyword, named LOP1, (and many variations on the
- theme as well LOPN, METOP, RPT) since early 1991.
-
-
- Bye,
-
- Flavio
- __
- * flavio@cflav.sublink.org (Flavio Casetta)
- ---------------------------------------------------------------------
- | The usual disclaimer does not apply | +59 440404 (Vox populi) |
- | ForCALC's opinions are necessarily mine | +59 304490 (Fax dei) |
-