home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / hp48 / 5872 < prev    next >
Encoding:
Internet Message Format  |  1992-11-21  |  1.8 KB

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