Path: republic.btigate.com!atl-news-feed1.bbnplanet.com!cpk-news-hub1.bbnplanet.com!news.bbnplanet.com!newsfeed.internetmci.com!128.174.5.49!vixen.cso.uiuc.edu!newsrelay.iastate.edu!news.iastate.edu!vax1.miu.edu!JHMEYERS
From: jhmeyers@miu.edu (John H Meyers)
Newsgroups: comp.sys.hp48
Subject: STREAM, REVLIST, etc. for S/SX
Date: 22 Jan 1998 10:13:19 GMT
Organization: MIU Computer Services,  Fairfield, IA 52557.  Not Approved.
Lines: 88
Message-ID: <6a763v$nna$1@news.iastate.edu>
References: <6a5u20$gmc$1@news.iastate.edu>
Reply-To: jhmeyers@miu.edu
NNTP-Posting-Host: vax1.mum.edu
Xref: republic.btigate.com comp.sys.hp48:5928

%%HP: T(3); @ More HP48S/SX list functions (just like those in G/GX).

@ *NOT* for G/GX !

@ Some of these functions depend in turn upon DOSUBS,
@ which was posted on 1997/01/21.

\<< @ Run this program to store several new programs below
    @ into the current directory (HOME is recommended).

  \<< \-> ?p \<< { } SWAP 1
    \<< NSUB 1 > { ?p #6F8Eh SYSEVAL } @ Internal EVAL
      { ENDSUB 2 < { 1281 DOERR } IFT } IFTE \>>
    DOSUBS \>> DUP SIZE { + } IFT OBJ\-> DROP \>> 'STREAM' STO

  \<< LIST\-> \-> n \<< 0 n FOR i i ROLL NEXT n \->LIST \>> \>>
    'REVLIST' STO

  \<<  2 \<< SWAP - \>> DOSUBS \>> '\GDLIST' STO @ DeltaList

  \<< { + } OBJ\-> DROP STREAM \>> '\GSLIST' STO @ SumList

  \<< { * } OBJ\-> DROP STREAM \>> '\PILIST' STO @ PiList

  \<< { { 514 DOERR } 2 { 1 1 SUB } 5 { 1 GET } }
      DUP2 SWAP TYPE POS 1 + GET EVAL \>> 'HEAD' STO

  \<< 2 OVER SIZE SUB \>> 'TAIL' STO

\>> @ Discard this program after installing the above programs.

---------------------------------------------------------------

HEAD is the first element of a list, or first character of a string.

TAIL is the remainder of a list or string
(which may be empty, but never errors, except in buggy rev M).

SumList sums a list (of numbers, strings, etc.)

PiList multiplies together all the elements of a list.

DeltaList makes a list of "first differences" between adjacent
elements, e.g.  { 0 1 4 9 16 25 36 }  ==>  { 1 3 5 7 9 11 }

REVLIST reverses the order of the elements in any list; for
moderate-sized lists, our program is faster than the G/GX command!

STREAM is what makes SumList and PiList work:

  { list } \<< program \>> ==> result

  The first two elements of the list are put on the stack,
  then the program is executed, producing some result;
  this is repeated, introducing one more new list element onto
  the stack, following the initial result(s), executing the
  program again, and so forth until all elements from the list
  have been processed.  The final result(s) are *not* combined
  into a list; usuallly there is exactly one result, but it is
  possible to produce more results, or none.

  Other examples:  { 4 3 2 }  \<< ^ \>>  STREAM  ==>  4096

                   { 1 2 3 }  0  STREAM  ==>  1 0 2 0 3 0

  The G/GX refuses to do STREAM (and thus also refuses to do
  SumList or PiList) unless there are at least two elements
  in the list; a rationale for so doing could be that if an
  invalid object is in the list, it will not be detected,
  since the given operation will not be attempted even once.

  At any rate, we have duplicated this "feature" above, but
  you can allow all 1-element lists to always be accepted
  by removing "1281 DOERR" (or even more of the logic),
  at the price of non-compatibility with the G/GX.

At this point, the only explicit G/GX list-processing commands
for which we don't have close User-RPL equivalents for the S/SX
are SORT and SEQ.

There was rumor of the existence of some library
of possibly more efficient commands somewhere,
but I haven't come across it.

"Forge aHEAD -- but don't TAILgate!"

-----------------------------------------------------------
With best wishes from:   John H Meyers   <jhmeyers@mum.edu>