home *** CD-ROM | disk | FTP | other *** search
- From: akcs.joehorn@hpcvbbs.cv.hp.com (Joseph K. Horn)
- Date: Sun, 22 Nov 1992 07:40:02 GMT
- Subject: Re: Inserting an object in a list
- Message-ID: <2b0f36c6.2217.2comp.sys.hp48.1@hpcvbbs.cv.hp.com>
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!hp-cv!hp-pcd!hpcvra!rnews!hpcvbbs!akcs.joehorn
- Newsgroups: comp.sys.hp48
- References: <TIM.92Nov18161944@nijinsky.ipac.caltech.edu> <MHEISKAN.92Nov201113
- Lines: 40
-
- tim@nijinsky.ipac.caltech.edu [Tim Conrow] writes:
-
- > How does one insert an object into a given place in a list?
- > I.e. Insert object ob after the i`th element of
- > {}:
- >
- > {} %i ob -> {}'
- >
- > Exploding the list onto the stack and inserting the new element then
- > reassembling the list is ... complicated.
-
- Well, not too complicated:
-
- %%HP: T(3)A(D)F(.);
- @ INSERT by Joe Horn; same syntax as PUT
- \<< ROT OBJ\-> 1 + DUP 1 + ROLL OVER DUP 3 + ROLL - 2 + ROLLD \->LIST
- \>>
-
- This is even faster (!) than HP's "INSERT{}N" System RPL word
- (described by Mika Heiskanen) for very large lists, because theirs
- uses local variables, whereas my program uses only the stack.
-
- Here is the same program but rewritten in System RPL:
-
- %%HP: T(3)A(D)F(.);
- ":: ROT INNERCOMP #1+DUP #1+ROLL OVERDUP
- #3+ ROLL COERCE #- #2+UNROLL {}N ;"
-
- Even though it's much shorter, I don't recommend it, because it's only
- a tad faster, and fraught with the dangers of System RPL. (Fewer than
- 3 items on the stack, or wrong object types on the three stack levels,
- or a "pointer" on level two that's out of range, all could make your
- 48 hurl). Stick with the User RPL routine until Joe Hacker rewrites
- it in ML.
-
- BTW, I also tried using Jim Donnelly's ROTATE function in his Tool
- Library. Forget it. It winds up being even slower than the
- alternatives, if the pointer is near the middle of a large list.
-
- -Joe Horn-
-
-