Post Reply 
HP 50g - Storing local variables while branching???
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
Post Reply 


Messages In This Thread
RE: HP 50g - Storing local variables while branching??? - rprosperi - 03-05-2018 10:43 PM



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