HP Prime - local variables retain their initial type



#2

Local variables retain the type that is first assigned. For example:

EXPORT t2()
BEGIN
LOCAL aa;
aa := [1,2,3];
print(aa);
aa := 3;
print(aa);
END;
returns
[1,2,3]
[[3]]
which is bound to catch people out.

#3

Hi Bruce,

In page (512 foot print) 518 / 616 of user guide says:

"Although the system will allow you to store different types in the same local variable, this is poor programming practice and should
be avoided."

Of course, thanks for your findings and it let us to remember to avoid as user guide indicates.

Best regards!!

joseph


#4

But it isn't storing a different type. It's converting the different type into the original type. I think the text is misleading. It should say that local variables maintain their type and if you try to store a different type into them, then the expression is converted into the local's type.

Dave


#5

Indeed. As a side note, it works fine for me here....

TW

#6

Yes, that's exactly what is happening and it's consistent with practice in other programming languages. I used to do a lot of programming in FORTRAN, where you could explicitly declare the type of a variable. You could declare A to be Real and B to be Integer, such that if you stored 3 in A it became 3.00 and if you stored 3.14 in B it became 3. I agree that this practice in PPL is correct.


Possibly Related Threads…
Thread Author Replies Views Last Post
  HP: Dump the predefined variables! bluesun08 12 3,896 11-19-2013, 02:18 PM
Last Post: bluesun08
  Shutdown with the Apps key and more than 10 variables in a program. Davi Ribeiro de Oliveira 10 3,926 11-05-2013, 01:26 PM
Last Post: Han
  HP Prime: Number of external Variables Davi Ribeiro de Oliveira 0 1,034 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,073 10-26-2013, 08:42 PM
Last Post: Miguel Toro
  HP Prime Solver Variables Issue Anibal Morones Ruelas 8 3,136 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
  Prime RPN storing variables kris223 3 1,766 09-19-2013, 03:49 PM
Last Post: kris223

Forum Jump: