Re: HP50g - soft menu & local procedures problem (406 Views)
Reply
Frequent Advisor
Posts: 53
Registered: ‎03-10-2013
Message 1 of 3 (432 Views)
Accepted Solution

HP50g - soft menu & local procedures problem

Pls help! 

Below is a simple program to illustrate the problem with a soft menu & compiled local procedures

(->   and  <- stand for right and left arrows)

Program is working fine under debugger! (correctly displays SALDO and TRANS in response to pressing soft keys)

But started alone gives  error messages: "undefined  local Name".

According to the manual compiled local variables (here <-S and <-T ) should be visible in the whole program module, or do I not unerstand something?

Of course program is working fine when global procedures are used instead of the local ones.

Thanks in advance for your advise

 

<< 

     << "SALDO" >>

     << "TRANS" >>

      ->    <-S   <-T

       <<

           {

              { "SALDO"  <<   <-S   EVAL >> }

              { "TRANS"  <<   <-T   EVAL >> }

           }  MENU

      >>

>>

 

Trusted Contributor
Posts: 78
Registered: ‎11-18-2004
Message 2 of 3 (406 Views)

Re: HP50g - soft menu & local procedures problem

Hello,

 

A local variable has 1 main characteristic: a Scope.

 

This Scope means that the variable ONLY exists within that Scope...

A Scope has a 'physical' and Time extend (note the quotes around Physical, this is because it's not real physics, but virtual physics).

 

The 'physical' extend is the length/area of the program where the local variable exists. This extend start from the local variable definition all the way to the closure of the is the innermost Program block where the local variable is defined.

 

The Time extend is the runtime duration of the execution of this program block.

 

 

There is a secondary characteristic: It's name and it's recognition by the system.

In RPL, as in most languages, the basic program gramar rules allows a local variable to have any name. This makes it, at first glance undistinguishable from a global variable. The compiler then uses it's knowledge of Scope to know, when you type a name, if it should create a local or global variable.

 

Up to there, there is no problems in the definitions...

 

Now, let us look at your program (in essence)

 

<< 1 2 -> V1 V2

  <<

    { { "V1" V1 } { "V2" V2} } MENU

  >>

>>

 

When the program executes, it creates 2 MENU items and then EXITS!

At the time when your innermost program exits, the local variables are destroyed (normal, follow the rules)...

HOWEVER, you left a temporary structure available to the user (the menu) which contains references to these variables (which do not exists anymore).. When you press on one of these menu keys.. KaBoom....

 

 

But what about that <- syntax stuff?????

Remember the 'physical' Extend of the scope... This is all good and everything... BUT it has some issues.

Namely, you can not split your program in smaller chuncks, stored in various global variables, to make programming easier.

In most languages, and following the rules set above, you could not create a sub-program, using local variables that you plan to have exist in a 'Time extend' that covers the execution of this sub-program. This is true of most programming languages. The reason why you could not create such sub-program is because the compiler would not know/notice that these variables are 'in scope' when compiling the program (*see trick below).

The <- syntax allows you do do this. It allows you to force a variable to be compiled as a local even outside of the physical extend of the scope. But at the TIME of this call to the local variable, the variable MUST be defined, else... KaBoom!

 

This is the core of your mis-understanding....

 

 

To do what you want, you have 2 options:

- Use global varaibles

- Put a HALT after the MENU instruction (you should use TMENU BTW) and a CONT at the end of the execution of each menu items.

 

 

Hope that this helps!

 

Cyrille

 

*trick below*

The HP 50 has a very neat integrated run/programming environment which allows you do to the following to avoid having to type these pesky back arrows.

Create your top program with your local variable definitions (no arrows nessecary). Just after local variable definition, put a HALT instruction. Run the program.

Now, you can create your SUB program! When you press ENTER and the system compiles your program, these local variable EXIST (you are in their TIME scope!) and your program will contain local variable calls instead of global ones!

 

However, this will not solve your problem.

Frequent Advisor
Posts: 53
Registered: ‎03-10-2013
Message 3 of 3 (398 Views)

Re: HP50g - soft menu & local procedures problem

Thank you Cyrille very much, all is clear now

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.