(HP48) Local variable limit
10-30-2017, 03:37 AM
Post: #1
 Brad Barton Member Posts: 186 Joined: Jan 2014
(HP48) Local variable limit
Is there a limit to the number of local variables that can be declared in the 48? I'm working with some matrix operations, and I can't get it to recognize more than 9 local variables. If I put 10 numbers on the stack and try to assign them to 10 local variables, I get a "To few arguments" error. It's as if the 48 doesn't recognize the 10th value. I couldn't find an upper limit in the AUR.

10-30-2017, 03:58 AM
Post: #2
 Joe Horn Senior Member Posts: 1,282 Joined: Dec 2013
RE: (HP48) Local variable limit
Since the following errorlessly drops 17 objects from the stack, I don't think there's a limit to the number of local variables on the HP48.

<< -> A B C D E F G H I J K L M N O P Q << 2222 2 BEEP >> >>

Please post the pertinent section of your code. I suspect that some other issue is at play.

X<> c
-Joe-
11-02-2017, 03:26 AM (This post was last modified: 11-02-2017 03:39 PM by Brad Barton.)
Post: #3
 Brad Barton Member Posts: 186 Joined: Jan 2014
RE: (HP48) Local variable limit
Joe,

Thanks for taking a look. I was just trying something out and ran into this early in the process, so this is more of a code fragment than a program.

Code:
 \<< DUP IF DET 0 == THEN "NO INV" ELSE DUP DET SWAP OBJ\-> DROP \-> dt a b c d e f g h i END \<< 'dt' EVAL 'a' EVAL 'b' EVAL 'c' EVAL 'd' EVAL 'e' EVAL 'f' EVAL 'g' EVAL 'h' EVAL 'i' EVAL\>> END \>>

Obviously there was some mathy stuff in the middle of the program, but this is the debug version. If I put a 3 X 3 matrix on the stack and run this code, I get a "Too few arguments" error both in the calculator and emulator.

If I leave out the local variable 'i' the program runs, but 'h' evals as the 2nd to last element in the matrix. I'm not able to get it to recognize the last local variable. I tried changing it to 'j' and 'm' in case there was a conflict with the imaginary 'i', but it didn't seem to matter.

I'm using the following as a test matrix, but I don't think it matters as long as the determinant isn't zero.

[[ 1 2 3]
[0 8 5]
[7 5 9]]

I'm sure I've made a simple mistake, but I can't find it.

11-02-2017, 05:15 AM
Post: #4
 Joe Horn Senior Member Posts: 1,282 Joined: Dec 2013
RE: (HP48) Local variable limit
Trying to wrap my brain around your code. Is the END at the end of line 5 a typo? If not, there's your bug.

X<> c
-Joe-
11-02-2017, 02:27 PM
Post: #5
 DavidM Senior Member Posts: 621 Joined: Dec 2013
RE: (HP48) Local variable limit
(11-02-2017 05:15 AM)Joe Horn Wrote:  Is the END at the end of line 5 a typo? If not, there's your bug.

I noticed the same thing, and was quite surprised when the code actually compiled successfully (after changing all the "/" escapes to "\"). I suppose the "\->" somehow throws off the structure-matching mechanism in the built-in compiler.

Removing that first END (the one after the locals enumeration) results in what I believe is the output you're looking for, Brad.
11-02-2017, 03:20 PM (This post was last modified: 11-02-2017 03:26 PM by Brad Barton.)
Post: #6
 Brad Barton Member Posts: 186 Joined: Jan 2014
RE: (HP48) Local variable limit
(11-02-2017 05:15 AM)Joe Horn Wrote:  Trying to wrap my brain around your code.

Lol, always what you want to hear when asking someone to take a look. I totally deserve it though, it IS pretty ugly. It's not usually that bad, but I'd never label any of my programs as elegant.

Quote: Is the END at the end of line 5 a typo? If not, there's your bug.

Nope, not a typo. I think the compiler was as confused as I was. Not sure why it works out like it does, but here I am. Thanks for the help. Same to DavidM (sorry about using the wrong slash). Now on to clean up the mess.

Can you shed any light on why it acts the way it does? Why does the extra END keep it from recognizing the 10th local variable?

11-02-2017, 05:04 PM
Post: #7
 Gerald H Senior Member Posts: 1,360 Joined: May 2014
RE: (HP48) Local variable limit
Probably not a good idea to call a variable, neither local nor global, "END".
11-02-2017, 05:05 PM (This post was last modified: 11-02-2017 05:07 PM by DavidM.)
Post: #8
 DavidM Senior Member Posts: 621 Joined: Dec 2013
RE: (HP48) Local variable limit
Edit: Gerald beat me to the punch on this one. Here's a little more explanation...

(Note: I've deleted my previous post, because I've now seen what the problem actually is... it's not what I said in that last post.)

The internal parser should have seen your program as having a syntax error, but didn't (it should have thought that you were attempting to use a reserved word as a local variable name).

Instead, it is treating that first "END" as the name of a local variable. So it is actually looking for 11 arguments, not 10.

Case in point. On a 49-50g, use →S2 to decompile your program, and you'll see a reference to "LAM END", which is the SysRPL designation for a local ID with the name "END". Sorry about any confusion caused by my previous confusion.
11-02-2017, 05:42 PM (This post was last modified: 11-02-2017 05:54 PM by Gerald H.)
Post: #9
 Gerald H Senior Member Posts: 1,360 Joined: May 2014
RE: (HP48) Local variable limit
Great stuff.

For stack

4
3
2
1

guess what this programme returns:

Code:
« → IF THEN ELSE END   « IF THEN + ELSE + END +   » »
11-02-2017, 06:30 PM
Post: #10
 rprosperi Senior Member Posts: 2,796 Joined: Dec 2013
RE: (HP48) Local variable limit
(11-02-2017 05:42 PM)Gerald H Wrote:  Great stuff.

For stack

4
3
2
1

guess what this programme returns:

Code:
« → IF THEN ELSE END   « IF THEN + ELSE + END +   » »

10? (someone has to take the bait...)

Or maybe an error message?

--Bob Prosperi
11-02-2017, 07:00 PM
Post: #11
 Gerald H Senior Member Posts: 1,360 Joined: May 2014
RE: (HP48) Local variable limit
Well, for stack

4
3
2
1

this programme returns 4:

Code:
« → END IF THEN ELSE   « ELSE THEN + END + IF -   » »
11-02-2017, 07:05 PM
Post: #12
 Gerald H Senior Member Posts: 1,360 Joined: May 2014
RE: (HP48) Local variable limit
Mind you, this is also accepted as a valid programme & evaluates!

Code:
« → END IF THEN ELSE END   « ELSE THEN + END + IF -   » »
11-02-2017, 09:02 PM
Post: #13
 Joe Horn Senior Member Posts: 1,282 Joined: Dec 2013
RE: (HP48) Local variable limit
RPL's eagerness to create local variables with any name at all, including reserved words, can lead to truly hilarious code.

For example, the following program takes any whole number as its input, and returns the number of bits required to express it in binary. But just LOOK at that code!

Code:
<< 0 1 ROT FOR SWAP 1 + SWAP STEP >>

X<> c
-Joe-
11-02-2017, 10:29 PM
Post: #14
 rprosperi Senior Member Posts: 2,796 Joined: Dec 2013
RE: (HP48) Local variable limit
These are candidates for an obfuscated RPL program contest.

Which would be very interesting!

I still can't figure out Joe's contender... I have it running and confirm it works as stated, but I'll need to step through it to understand it exactly.

Thanks for sharing these guys.

--Bob Prosperi
11-03-2017, 06:43 AM
Post: #15
 Gerald H Senior Member Posts: 1,360 Joined: May 2014
RE: (HP48) Local variable limit
& this works as expected(?).

Code:
« 0 5   FOR NEXT     « NEXT     » EVAL 2 +   NEXT »
11-03-2017, 07:49 AM
Post: #16
 brickviking Member Posts: 259 Joined: Dec 2014
RE: (HP48) Local variable limit
(11-03-2017 06:43 AM)Gerald H Wrote:  & this works as expected(?).

Code:
« 0 5   FOR NEXT     « NEXT     » EVAL 2 +   NEXT »

I thought the manual expressly forbade creating variables (whether global or local) with the same names as internal functions? Doesn't the calculator throw a wobbly or something? Clearly not, or the previous two examples wouldn't have even got out of the starting gate.

(Post 127)

Regards, BrickViking
HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a)
 « Next Oldest | Next Newest »

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