Post Reply 
HP 50g - Storing local variables while branching???
03-05-2018, 09:52 PM (This post was last modified: 03-05-2018 09:52 PM by Carsen.)
Post: #1
HP 50g - Storing local variables while branching???
Hello all:

While working on a 50g UserRPL program that allows me to calculate days between two dates based on either a 365 day basis or 30/360 day basis, I stumbled across a problem. I cannot store local variables in my IF...THEN...ELSE...END branching. You can see that this issue happened when I tried to store mm1, dd1, yy1, mm2, dd2, & yy2. Here's the incomplete program...

<< -> DT1 DT2 << "Day-Count Convention" { { "Actual Day Basis" 1 } { "30/360 Day Basis" 0 } } 1 CHOOSE NOT IF THEN DT1 DT2 ELSE IF THEN DT1 DT2 DDAYS ELSE DT1 DUP IP SWAP FP 100 * DUP IP SWAP FP 10000 * DT2 DUP IP SWAP FP 100 * DUP IP SWAP FP 10000 * IF -42 FC? THEN -> mm1 dd1 yy1 mm2 dd2 yy2 ELSE -> dd1 mm1 yy1 dd2 mm2 yy2 END END END >> >> ***The bold area is my problem right now***

The 50g will highlight one of the program containers at the end of the program (i.e the [ >> ]) and reply with "INVALID SYNTAX". Of course, when I remove the [ -> ] that's before the mm1 dd1 yy1...etc. The syntax error goes away.

May anyone help me out here a little bit. I've been resolving this issue to the point of sheer frustration. Plus I would like to understand why this isn't working. With my understanding, it should work but it doesn't. Thank you

-Carsen
Find all posts by this user
Quote this message in a reply
03-05-2018, 10:43 PM
Post: #2
RE: HP 50g - Storing local variables while branching???
(03-05-2018 09:52 PM)Carsen Wrote:  Hello all:

While working on a 50g UserRPL program that allows me to calculate days between two dates based on either a 365 day basis or 30/360 day basis, I stumbled across a problem. I cannot store local variables in my IF...THEN...ELSE...END branching. You can see that this issue happened when I tried to store mm1, dd1, yy1, mm2, dd2, & yy2. Here's the incomplete program...

<< -> DT1 DT2 << "Day-Count Convention" { { "Actual Day Basis" 1 } { "30/360 Day Basis" 0 } } 1 CHOOSE NOT IF THEN DT1 DT2 ELSE IF THEN DT1 DT2 DDAYS ELSE DT1 DUP IP SWAP FP 100 * DUP IP SWAP FP 10000 * DT2 DUP IP SWAP FP 100 * DUP IP SWAP FP 10000 * IF -42 FC? THEN -> mm1 dd1 yy1 mm2 dd2 yy2 ELSE -> dd1 mm1 yy1 dd2 mm2 yy2 END END END >> >> ***The bold area is my problem right now***

The 50g will highlight one of the program containers at the end of the program (i.e the [ >> ]) and reply with "INVALID SYNTAX". Of course, when I remove the [ -> ] that's before the mm1 dd1 yy1...etc. The syntax error goes away.

May anyone help me out here a little bit. I've been resolving this issue to the point of sheer frustration. Plus I would like to understand why this isn't working. With my understanding, it should work but it doesn't. Thank you

-Carsen

When you allocate local variables, they are only accessible in the program object (i.e. stuff between << and >>) that immediately follows the variable declaration. In your example, there is no program object following their allocation. It looks like you are trying to return values on the stack to the mm1, dd1, etc. variables, but the "->" variables are only local (accessible in the next block, which in your exampled doesn't exist); you can't store into named object storage this way.

RPL experts will hopefully explain this using more exact language, but that's the basic problem. Bottom line: local storage is temporary and you cannot allocate permanent storage this way.

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
03-05-2018, 11:27 PM (This post was last modified: 03-05-2018 11:28 PM by Carsen.)
Post: #3
RE: HP 50g - Storing local variables while branching???
Thanks rprosperi. Your information was enough for me to solve the problem. And I found this in the Advance User's Reference Guide. So that means it can be program containers or an algebraic object.


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
03-06-2018, 07:01 AM
Post: #4
RE: HP 50g - Storing local variables while branching???
Yes exactly that. So every time you use -> then you need to open a program, but then the variables there declared may not be seen by the outer program.

Suggestion: declare all the variables that you need before, then use them. (Don't worry to think about them early, just write the program first and then copy the name in the declaration section)

An example of what I mean is here http://www.hpmuseum.org/forum/thread-795...l#pid82455

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
Post Reply 




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