![]() |
![]() |
![]() |
||||||||||
|
||||||||||||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
||||
![]() |
  | |||||||||||
Programming in User RPL - Local variablesLet's see another simple program that does nothing more than calculate the hypotenuse of a triangle when the two catets are given: << SQ SWAP SQ + In the above case, each of the two inputs is used only once, so stack-manipulation is not a real case. But in some cases, the inputs are used more than once, so keeping the stack organised is quite difficult and to get a specific value is a real problem. So, instead of using lots of commands just the get the value you need, why not store each of the values somewhere, and then recall them and if necessary change the value? It's a lot easier. But where would you store the values. You could use variables, sure, but that's a
problem. What if the user already has a variable with the name you want to use? And
you must erase the variables used in the end of the program. But if the program
terminates unexpectedly, because of an error, for example? The user's Because of this, the HP has a nice feature called local variables. They work
like normal variables, but they don't appear on the The local variables are created with the Let's clarify this: suppose you have 1, 2 and 3 on the stack, on this order. If you
use OK, but how do I use this in a program? Very simple: add the Clarifying: the above hypotenuse program can be written also as: << -> a b ' or<< -> a b << a SQ b SQ + But, in this case, the first on is the most effient. But in more complicated cases,
local variables are much more efficient. At least, they make the programs easier to
understand, because you can see the fourmulas, and not crypt stack manipulation
commands like |
||||||||||||
![]() |
![]() |
This page was created by Eduardo M Kalinowski