(HP48) Local variable limit
|
10-30-2017, 03:37 AM
Post: #1
|
|||
|
|||
(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.
Brad |
|||
10-30-2017, 03:58 AM
Post: #2
|
|||
|
|||
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. <0|ɸ|0> -Joe- |
|||
11-02-2017, 03:26 AM
(This post was last modified: 11-02-2017 03:39 PM by Brad Barton.)
Post: #3
|
|||
|
|||
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 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. Brad |
|||
11-02-2017, 05:15 AM
Post: #4
|
|||
|
|||
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.
<0|ɸ|0> -Joe- |
|||
11-02-2017, 02:27 PM
Post: #5
|
|||
|
|||
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
|
|||
|
|||
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? Brad |
|||
11-02-2017, 05:04 PM
Post: #7
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
RE: (HP48) Local variable limit
Great stuff.
For stack 4 3 2 1 guess what this programme returns: Code: « → IF THEN ELSE |
|||
11-02-2017, 06:30 PM
Post: #10
|
|||
|
|||
RE: (HP48) Local variable limit
(11-02-2017 05:42 PM)Gerald H Wrote: Great stuff. 10? (someone has to take the bait...) Or maybe an error message? --Bob Prosperi |
|||
11-02-2017, 07:00 PM
Post: #11
|
|||
|
|||
RE: (HP48) Local variable limit
Well, for stack
4 3 2 1 this programme returns 4: Code: « → END IF THEN |
|||
11-02-2017, 07:05 PM
Post: #12
|
|||
|
|||
RE: (HP48) Local variable limit
Mind you, this is also accepted as a valid programme & evaluates!
Code: « → END IF THEN |
|||
11-02-2017, 09:02 PM
Post: #13
|
|||
|
|||
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 >> <0|ɸ|0> -Joe- |
|||
11-02-2017, 10:29 PM
Post: #14
|
|||
|
|||
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
|
|||
|
|||
RE: (HP48) Local variable limit
& this works as expected(?).
Code: « 0 5 |
|||
11-03-2017, 07:49 AM
Post: #16
|
|||
|
|||
RE: (HP48) Local variable limit
(11-03-2017 06:43 AM)Gerald H Wrote: & this works as expected(?). 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: 7 Guest(s)