local variables



#2

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


#3

Hi,

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

Hope that helps.

#4

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.

#5

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


#6

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)

#7

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


#8

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

#9

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

#10

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


#11

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  HP: Dump the predefined variables! bluesun08 12 3,895 11-19-2013, 02:18 PM
Last Post: bluesun08
  HP Prime - local variables retain their initial type BruceH 4 1,914 11-10-2013, 12:42 PM
Last Post: Michael de Estrada
  Shutdown with the Apps key and more than 10 variables in a program. Davi Ribeiro de Oliveira 10 3,924 11-05-2013, 01:26 PM
Last Post: Han
  HP Prime: Number of external Variables Davi Ribeiro de Oliveira 0 1,033 11-01-2013, 08:10 PM
Last Post: Davi Ribeiro de Oliveira
  HP Prime variables Davi Ribeiro de Oliveira 3 1,718 10-31-2013, 02:24 AM
Last Post: cyrille de Brébisson
  HP Prime - deleting variables bluesun08 1 1,257 10-29-2013, 06:36 PM
Last Post: Joe Horn
  HP Prime: CAS Variables - -How to save? Helge Gabert 2 1,875 10-27-2013, 11:26 PM
Last Post: Helge Gabert
  HP Prime Programming Tutorial #1: LOCAL, RETURN Eddie W. Shore 6 3,066 10-26-2013, 08:42 PM
Last Post: Miguel Toro
  HP Prime Solver Variables Issue Anibal Morones Ruelas 8 3,135 10-19-2013, 09:45 AM
Last Post: Harold A Climer
  HP Prime Programming: LOCAL Alberto Candel 3 1,581 10-07-2013, 01:31 AM
Last Post: cyrille de Brébisson

Forum Jump: