(HP48) Local variable limit - Printable Version +- HP Forums (http://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: (HP48) Local variable limit (/thread-9395.html) (HP48) Local variable limit - Brad Barton - 10-30-2017 03:37 AM 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 RE: (HP48) Local variable limit - Joe Horn - 10-30-2017 03:58 AM 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. RE: (HP48) Local variable limit - Brad Barton - 11-02-2017 03:26 AM 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. Brad RE: (HP48) Local variable limit - Joe Horn - 11-02-2017 05:15 AM 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. RE: (HP48) Local variable limit - DavidM - 11-02-2017 02:27 PM (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. RE: (HP48) Local variable limit - Brad Barton - 11-02-2017 03:20 PM (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 RE: (HP48) Local variable limit - Gerald H - 11-02-2017 05:04 PM Probably not a good idea to call a variable, neither local nor global, "END". RE: (HP48) Local variable limit - DavidM - 11-02-2017 05:05 PM 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. RE: (HP48) Local variable limit - Gerald H - 11-02-2017 05:42 PM Great stuff. For stack 4 3 2 1 guess what this programme returns: Code: ```« → IF THEN ELSE END   « IF THEN + ELSE + END +   » »``` RE: (HP48) Local variable limit - rprosperi - 11-02-2017 06:30 PM (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? RE: (HP48) Local variable limit - Gerald H - 11-02-2017 07:00 PM Well, for stack 4 3 2 1 this programme returns 4: Code: ```« → END IF THEN ELSE   « ELSE THEN + END + IF -   » »``` RE: (HP48) Local variable limit - Gerald H - 11-02-2017 07:05 PM Mind you, this is also accepted as a valid programme & evaluates! Code: ```« → END IF THEN ELSE END   « ELSE THEN + END + IF -   » »``` RE: (HP48) Local variable limit - Joe Horn - 11-02-2017 09:02 PM 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 >>` RE: (HP48) Local variable limit - rprosperi - 11-02-2017 10:29 PM 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. RE: (HP48) Local variable limit - Gerald H - 11-03-2017 06:43 AM & this works as expected(?). Code: ```« 0 5   FOR NEXT     « NEXT     » EVAL 2 +   NEXT »``` RE: (HP48) Local variable limit - brickviking - 11-03-2017 07:49 AM (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)