Post Reply 
Help me with HP50g -DOSUBS !
03-21-2014, 12:05 PM (This post was last modified: 03-21-2014 12:05 PM by Dalil.)
Post: #2
RE: Help me with HP50g -DOSUBS !
Hello,


Code:
{ A B C D E }    @ list of element on which the command will be applied
« - »                  @ Command to apply
DOSUBS

What happens is: the command requires 2 arguments (number1 - number2), so for each iteration, the DOSUBS push 2 items onto the stack. What happens at the stack level is, step by step is:

Code:
1st iteration before operation:         |1st iteration after operation:
Stack level:item                        |Stack level:item
2:A                                     |2:
1:B                                     |1:A-B

2nd iteration before operation:         |2nd iteration after operation:
Stack level:item                        |Stack level:item
3:A-B                                   |3:
2:B                                     |2:A-B
1:C                                     |1:B-C


3rd iteration before operation:         |3rd iteration after operation:
Stack level:item                        |Stack level:item
4:A-B                                   |4:
3:B-C                                   |3:A-B
2:C                                     |2:B-C
1:D                                     |1:C-D


4th iteration before operation:         |4th iteration after operation:
Stack level:item                        |Stack level:item
5:A-B                                   |5:
4:B-C                                   |4:A-B
3:C-D                                   |3:B-C
2:D                                     |2:C-D
1:E                                     |1:D-E

at this point all items in the list have been used, the resulting list is constructed and output, i.e. the output is
Code:
{'A-B' 'B-C' 'C-D' 'D-E'}


Code:
Example 2:
{ A B C }          @ list of element on which the command will be applied  
2                  @ number of elements to push on the stack at each iterations
« DUP * * »        @ commands to perform at each iteration
DOSUBS

Something similar to the previous example happens at the stack level.



Code:
Example 3: Entering:
{ 1 2 3 4 5 }                 @ list of element on which the command will be applied 
« -> a b                      @ The function takes 2 arguments, so 2 items will be pushed onto the stack at each iteration
« CASE 'NSUB==1' THEN a END   @ similarly to the first example
'NSUB==ENDSUB' THEN b END     @ and this function will be executed
'a+b' EVAL END » »
DOSUBS
returns { 1 5 7 5 }
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Help me with HP50g -DOSUBS ! - carlovan - 03-21-2014, 09:21 AM
RE: Help me with HP50g -DOSUBS ! - Dalil - 03-21-2014 12:05 PM



User(s) browsing this thread: 1 Guest(s)