HP Forums
Help me with HP50g -DOSUBS ! - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: General Forum (/forum-4.html)
+--- Thread: Help me with HP50g -DOSUBS ! (/thread-948.html)



Help me with HP50g -DOSUBS ! - carlovan - 03-21-2014 09:21 AM

I started programming in RPN with the HP33E (1974) and continued up to the HP41C.
When I bought the new HP50G I encountered a lot of problems to understand the UserRPN: manuals are not exhaustive !
But the worst came with the command DOSUBS: I really cannot understand how it works: Is there any gentle soul who can write a @comment after every line of the “explanatory example” programs of the RPN Programming manual (!) ?


Example 1:
{ A B C D E }
« - »
DOSUBS
returns { 'A-B' 'B-C' 'C-D' 'D-E' }.

Example 2:
{ A B C }
2
« DUP * * »
DOSUBS
returns { 'A*(B*B)' 'B*(C*C)' }.

Example 3: Entering:
{ 1 2 3 4 5 }
« → a b
« CASE 'NSUB==1' THEN a END
'NSUB==ENDSUB' THEN b END
'a+b' EVAL END » »
DOSUBS
returns { 1 5 7 5 }


RE: Help me with HP50g -DOSUBS ! - Dalil - 03-21-2014 12:05 PM

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 }



RE: Help me with HP50g -DOSUBS ! - carlovan - 03-21-2014 05:21 PM

nowhere is written that DOSUBS puts the arguments it needs on the stack !
Now I can go on !
Grazie mille (Thanks a lot !)

Carlo


RE: Help me with HP50g -DOSUBS ! - Gerson W. Barbosa - 03-21-2014 06:32 PM

(03-21-2014 05:21 PM)carlovan Wrote:  nowhere is written that DOSUBS puts the arguments it needs on the stack !

You should get yourself an HP-48G/GX manual instead:

http://h10032.www1.hp.com/ctg/Manual/c00442262.pdf

(See page 17-5)

Gerson.


RE: Help me with HP50g -DOSUBS ! - carlovan - 03-23-2014 10:19 AM

Your help has been useful!

Those who write the HP manuals must be convinced that people who read them is becoming more and more clever, so progressively are shrinking the explanations !

In the next manual, the explanation of the DOSUBS command will be: "guess how it works" !