local variables - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: local variables (/thread-231476.html) local variables - brooky - 09-19-2012 hi I need some help with local variables. I want create local variables within a program for example; << -> A B << b a - 5 / 'c' ->tag b c + 'd' ->tag >> >> what i get on the stack after exacution is (a=5 b=6) 2: 0.2 1: '6+c' instead of 1: 6.2 Thanks Re: local variables - Neil Hamilton (Ottawa) - 09-19-2012 Hi, I am pretty sure that this is case sensitive so you "A B" is not the same as "a b". Hope that helps. Re: local variables - Marcus von Cube, Germany - 09-19-2012 I can't see a definition for the variable c. The ->tag command just labels entries on the stack. It does not store values or create variables. Re: local variables - Namir - 09-19-2012 Perhaps << -> A B << b a - 5 / 'c' ->tag b c + 'd' ->tag >> >> Should be: << 0 -> c A B << b a - 5 / 'c' STO 'c' ->tag b c + 'd' ->tag >> >> Yes? Namir My RPL is very rusty .. :-( Re: local variables - Gilles Carpentier - 09-19-2012 Hi, as Marcus wrote, the ->TAG function is just for labels data on the stack. There are several way for your calculation : ```<< -> a b '((b-a)/5)+b' >> << -> a b << b a - 5 / b + >> >> or just << DUP ROT - 5 / + >> ``` Not that, in all cases, if you name your program for example 'f', you can use it in RPN or Algrabraic : ```5 6 f 'f(5,6)' EVAL or just `f(5,6)` ``` The result will be 6.2 I recommand you to debug each program to see what happens PS : My RPL is for 49 and 50G. Edited: 19 Sept 2012, 1:40 p.m. after one or more responses were posted Re: local variables - Gilles Carpentier - 09-19-2012 Hi Namir ``` << 0 -> c A B << b a - 5 / 'c' STO 'c' ->tag b c + 'd' ->tag >> >> Yes?``` No ;) Could be : << 0 -> a b c << b a - 5 / 'c' STO b c + 'd' ->tag >> >> But this is unnecessarely complex (the c varaible has no interest here) Re: local variables - C.Ret - 09-19-2012 ```« -> a b '((b-a)/5)+b' » is pure User Function Format « -> a b « b a - 5 / b + » » is pure User Programm Format « DUP ROT - 5 / + » is pure User Reverse Polish Language ``` Again Gilles you make it right ! Translate into RPN this will give (may vary depending of exact calculator) `Lbl F - Lastx x:y 5 / + R/S` If as brooky you persist in using a third variable, you just have to embed the local variable structure : ```« -> a b « b a - 5 / -> c « c b + » » » ``` But, as Gilles already say it, it is unnecessarily complex since the intermediate c variable has no interest here. Edited: 19 Sept 2012, 10:20 a.m. Re: local variables - David Hayden - 09-20-2012 This does what you seem to want from your example, but why are you storing into the local variable 'd' when it disappears at the end of the program? ```« 0. 0. @ put two dummy values on the stack for locals c & d  A B c d « B A - 5 / 'c' STO B 'c' EVAL + @ locals need EVAL DUP 'd' STO » » ``` Re: local variables - brooky - 09-24-2012 The simple fromula was only example sorry for the confussion. Can you create local variables during a program or do they have to be stored as global ones. ie STO Re: local variables - David Hayden - 09-25-2012 You create local variables with the -> << >> construction. Once creat4ed you can store to them with STO just like with global variables. In other words 'XYZ' STO will store into the local variable XYZ if it exists, and otherwise it will store into the global variable. Does this help? Dave