These programs are for those who uses the HP-48S/SX models and still wan't
to use programs made for HP-48G/GX. Programs are presented in the order
which I first created them. Surely there are a lot new commands in the G-series
which are not included here, but these are special list commands and of
my particular interest. You can submit your improved versions and/or new
programs to the editor Timo Talonpoika.
Veli-Pekka Nousiainen (008)
-------------------------------------------------------------------
Command Reference Page
-------------------------------------------------------------------
SEQ 3-302
STREAM 3-333
REVLIST 3-274
SORT 3-315
(PI)LIST 3-171
(SIGMA)LIST 3-170
DOSUBS 3-92
(DELTA)LIST 3-170
DOLIST 3-91
-------------------------------------------------------------------
SEQ, Sequential Calculation Command:
Returns a list of results generated by repeatedly executing obj_exec using index over the range x_start to x_end, in increments of x_incr.
Level 5 Level 4 Level 3 Level 2 Level 1 -> Level 1
____________________________________________________________
obj_exec index x_start x_end x_incr -> { list }
'SEQ' BYTES # 1909d 237.5
<< -> o x s d c | obj_exec index x_start x_end x_incr
<< DEPTH -> l | preserve DEPTH of stack to 'l'
<< s d o DTAG | (I used (lambda) instead of'l')
WHILE DUP | put into stack: start end
TYPE DUP 6 == SWAP | WHILE object is of type Global/Local
7 == OR | RCL and REPEAT
REPEAT RCL | * NOTE * MATCH needs an existing
END DUP TYPE | local 'l' here, but a FOR variable
9 | overrides it without problems *
IF == | check if it is albegraic
THEN x 'l' 2 | THEN change every index to local 'l'
->LIST |MATCH DROP -> | using (UP-ARROW)MATCH and save to
a | algebraic
<< FOR l a | take start end from stack FOR l
EVAL c | * NOTE * new 'l' is created *
STEP | EVALuate and increment STEP
>> |
ELSE DROP | ELSE
FOR j j o | take start end from stack FOR j
EVAL c | EVALuate and increment STEP
STEP |
END DEPTH l - | increased DEPTH is combined
->LIST | into a list
>> |
>> |
>> |
-------------------------------------------------------------------
STREAM, Stream Execution Command:
Moves the first two elements from the list onto the stack, and executes obj.
Then moves the next element (if any) onto the stack, and executes obj again using the previous result and the new element. Repeats this until the list is exhausted, and returns the final result
Level 2 Level 1 -> Level 1
______________________________
{ list } obj -> result
'STREAM' BYTES # 64225d 74.5
<< -> o | obj
<< DUP SIZE 1 | IF list SIZE is bigger than 1
IF > |
THEN LIST-> 2 | THEN put list onto stack
SWAP | SWAP 2 and the list size
START o EVAL | START obj EVALuating over the
NEXT | list objects on stack
END |
>> |
>> |
-------------------------------------------------------------------
REVLIST, Reverse List Command:
Reverses the order of the elements in a list.
Level 1 -> Level 1
____________________________________________
{ obj_n ... obj_1 } -> { obj_1 ... obj_n }
'REVLIST' BYTES # 22754d 89
<< DUP SIZE 1 | IF list SIZE is bigger than 1
IF > | THEN put list elements onto the
THEN LIST-> -> n | stack and save size to n
<< 2 n | loop from 2 to size
FOR j j ROLL | ROLL list to reverse it
NEXT n ->LIST | NEXT combine stack into a list
>> |
END |
>> |
-------------------------------------------------------------------
SORT, Ascending Order Sort Command:
Sorts the elements in a list in ascending order.
Level 1 -> Level 1
__________________________
{ list }_1 -> { list }_2
'SORT' BYTES # 31614d 218
<< -> g | save list to 'g' to make a local
<< g | variable. Put g onto the stack.
<< DUP SIZE 1 | Put this program onto the stack.
IF > | IF SIZE is greater than 2 THEN
THEN LIST-> | list onto stack and ROLL middle
DUP 2 / 1 + ROLL | of the list to the top of the
NEWOB -> x | stack as a NEWOBject and save x
<< { } { } 2 | empty left and right lists
4 ROLL | 2 to list size START
START ROT |
DUP x |
IF < | IF x is smaller
THEN | THEN add to the left list
ROT + SWAP |
ELSE + | ELSE add to the right list
END |
NEXT g | NEXT recursively EVALuate both
EVAL SWAP g EVAL x | lists with this program
+ SWAP + | combine result list
>> | * NOTE * this solution ensures
END | that you can rename 'SORT' *
>> -> l g | save list and program onto l g
<< l g EVAL | EVALuate g with l on the stack
>> | * NOTE * at the beginning 'g'
>> | originally held the list for
>> | a moment just to create a local *
-------------------------------------------------------------------
(PI)LIST, List Product Command:
Returns the product of the elements in a list.
Level 1 -> Level 1
_____________________
{ list } -> product
'#LIST' BYTES # 20568d 57
<< DUP SIZE 1 | IF list SIZE is greater than 1
IF > | THEN put list elements onto the
THEN LIST-> 2 SWAP | stack. SWAP 2 and SIZE.
START * | START multiplying the elements.
NEXT |
END |
>> |
-------------------------------------------------------------------
(SIGMA)LIST, List Sum Command:
Returns the sum of the elements in a list.
Level 1 -> Level 1
_____________________
{ list } -> sum
'ELIST' BYTES # 30744d 57
<< DUP SIZE 1 | IF list SIZE is greater than 1
IF > | THEN put list elements onto the
THEN LIST-> 2 SWAP | stack. SWAP 2 and SIZE.
START + | START adding the elements.
NEXT |
END |
>> |
-------------------------------------------------------------------
DOSUBS, Do to Sublist Command:
Applies a program or command to groups of elements in a list.
Level 3 Level 2 Level 1 -> Level 1
__________________________________________________
{ list }_1 n << program >> -> { list }_2
{ list }_1 n command -> { list }_2
{ list }_1 n name -> { list }_2
'DSUBS' BYTES # 1549d 198.5
<< -> l n o | list n obj (program/command/name)
<< DEPTH -> d | save DEPTH
<< 1 l SIZE n - | list SIZE minus n plus 1 saved
1 + DUP 'ENDSUB' | to 'ENDSUB' which is the number
STO | of groups of elements
FOR j l j DUP | FOR each j save j to 'NSUB'
'NSUB' STO DUP 1 - | take SUBlist and put it onto
n + SUB LIST-> DROP | the stack for program EVALuation
o EVAL |
NEXT DEPTH d | NEXT DEPTH difference is the new
- ->LIST | length of result list
>> { ENDSUB NSUB | PURGE globals
} PURGE | * NOTE * you can use locals also:
>> | 'SEQ' uses (UP-ARROW)MATCH
>> | What would you do here ??? *
-------------------------------------------------------------------
(DELTA)LIST, List Differences Command:
Returns the first differences of the elements in a list.
Level 1 -> Level 1
_____________________________
{ list } -> { differences }
'DLIST' BYTES # 20568d 57
<< LIST-> -> n | put list elements onto the stack
<< 2 n | save size to n. from 2 to n
START n ROLL n | START to ROLL PICK and
PICK SWAP - | calculate the differences
NEXT n 1 - | NEXT combine result list with
->LIST SWAP DROP | one less elemenent than the
>> | original list and DROP the
>> | remaining element
-------------------------------------------------------------------
DOLIST, Do to List Command:
Applies commands, programs or user-defined functions to lists.
Level n...Level 3 Level 2 Level 1 -> Level 1
______________________________________________________________
{ list }_1...{ list }_n n << program >> -> { results }
{ list }_1...{ list }_n n command -> { results }
{ list }_1...{ list }_n n name -> { results }
'DOLIST' BYTES # 15025d 338
<< -> o | save obj (program/command/name)
<< OVER SIZE -> n l | n and SIZE of the first list (l)
<< n 1 | are saved
IF > | IF n is greater then 1 then
THEN DEPTH 0 | save stack DEPTH to d and
-> d D | 0 to D ( I used (delta) )
<< 1 l DUP2 | 1 l into the stack
IF > | IF 1 > l
THEN | THEN DROP 1 and l
DROP2 n DROPN 1 n | and DROPN lists also
START o |
EVAL | START EVALuating the program
NEXT |
ELSE | ELSE
FOR j 1 | FOR each j
n | n times
START | START PICKing lists and GETting
n PICK j GET | j'th element from each list
NEXT |
o EVAL D | NEXT EVALuate program
IF |
NOT | IF (delta) is 0 (first time here)
THEN | THEN compute it from the current
DEPTH d - 1 SWAP | stack DEPTH and STOre
DUP n + 'D' STO | * NOTE * (delta) is used save
ELSE | result list size after first EVAL
1 D DUP2 | ELSE
IF >= | IF 1 >= (delta)
THEN DROP2 | THEN DROP both
ELSE n - | ELSE subtract n
END | END
END | END of (delta) is 0 -test
START | START
D ROLLD | ROLLDown of results
NEXT | NEXT
NEXT | NEXT (PICKing...)
END n | END of 1 > l -test
DROPN DEPTH d - n + | DROPN lists
->LIST | compute new DEPTH for result size
>> | and combine into a list
END | END of n > 1 -test
>> | * NOTE * There is something funny
>> | in this program. Can you find it?
>> | Any improvements?