HP Forums

Full Version: local variables
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

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

Hi,

I am pretty sure that this is case sensitive so you "A B" is not the same as "a b".

Hope that helps.

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.

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 .. :-(

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

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)

« -> 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.

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
»
»

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

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