The Museum of HP Calculators

HP Forum Archive 21

[ Return to Index | Top of Index ]

HP39GII and local functions
Message #1 Posted by Gilles Carpentier on 23 July 2012, 8:03 a.m.

One interesting thing with the 39gII is that you can define local functions in a program.

An exemple is given in the User's guide (p.247) but it seems there is an error :

Local functions 39gII

As Tim wrote in the previous link,a local function must be define before to be used in another program.

This seems logic but the user's guide confuses me, and perhaps this message can avoid another users to lose time to understand

Edited: 23 July 2012, 8:04 a.m.

      
Re: HP39GII and local functions
Message #2 Posted by Namir on 23 July 2012, 8:30 a.m.,
in response to message #1 by Gilles Carpentier

Thanks Gilles for this valuable tip!! I am ashamed to admit that I was unaware of local functions for the HP39gII. I guess I did not look at the manual much.

Namir

            
Re: HP39GII and local functions
Message #3 Posted by C.Ret on 23 July 2012, 11:33 a.m.,
in response to message #2 by Namir

Hi !

I just start reading the documentation of the HP-39gII and I discover that programming is powerful.

Programs allow high level structured code, use of local variable as well as local functions, global variable share with the user and also specific variable from system-application...

In one hand access to the global variables (organized in real, complex, lists, matrix/vector) make it easy to share or bring results to the user. In the other hand, the local variables and functions allow easy development of complex application free of any worries about how to organize data and code.

In addition, it seems really easy to use pre-definite Application-Key, plots or data tables or to predefine Application-Views. Manly due to the fact that pre-define application variable are documented and accessible (read/write) from user-applications.

This make quite powerful, complete and capable advanced calculator!

Exploring all its capabilities, make me believe that the shifted EEX-key, the lack of no Reverse Polish Logic or Notation are only details of small effect and of no weight when considering the power, capabilities and easy programming.

Keep in mind that I have not tested all the sharing possibilities (since I only test it on the emulator). But, for sure the SEND, CLONE and other command will make easy to transmit, share data, results as well as functions or user-applications with other HP-39 owners.

Edited: 23 July 2012, 11:34 a.m.

                  
Re: HP39GII and local functions
Message #4 Posted by Tim Wessman on 23 July 2012, 11:42 a.m.,
in response to message #3 by C.Ret

Quote:
This make quite powerful, complete and capable advanced calculator!

Exploring all its capabilities, make me believe that the shifted EEX-key, the lack of no Reverse Polish Logic or Notation are only details of small effect and of no weight when considering the power, capabilities and easy programming.


Makes me happy to hear things like that. :-)

TW

                  
Re: HP39GII and local functions
Message #5 Posted by fhub on 23 July 2012, 1:15 p.m.,
in response to message #3 by C.Ret

Quote:
Programs allow high level structured code, use of local variable as well as local functions, ...
The TI-92 had all this already more than 15 years ago ... ;-)

Franz

                        
Re: HP39GII and local functions
Message #6 Posted by From Hong Kong on 23 July 2012, 11:57 p.m.,
in response to message #5 by fhub

Quote:

The TI-92 had all this already more than 15 years ago ... ;-)

Franz


But one of the selling points of HP-39gII is speed. With the calculator benchmark, we know that HP-39gII is approximately 96 times faster than TI-89 HW2 (no data is available for TI-92) considering that HP-39gII is an economical model on par with TI-85/86 in terms of functionality.

Edited: 24 July 2012, 12:01 a.m.

                  
Re: HP39GII and local functions
Message #7 Posted by Cristian Arezzini on 23 July 2012, 4:32 p.m.,
in response to message #3 by C.Ret

Quote:
Exploring all its capabilities, make me believe that the shifted EEX-key, the lack of no Reverse Polish Logic or Notation are only details of small effect and of no weight when considering the power, capabilities and easy programming.

I agree with everything you said except the lack of RPL. I could see myself using this machine for programming (it really does seem powerful though I only used the emulator) but I really can't get myself to use algebraic for basic, quick calculations. Which is something I do a lot at work. Would it be possible to add a RPL calculator as an app? Just a 50g-style unlimited stack and basic scientific operations...

Cristian

      
Re: HP39GII and local functions
Message #8 Posted by Tim Wessman on 23 July 2012, 11:41 a.m.,
in response to message #1 by Gilles Carpentier

Hello,

The revision 1 version of the manual was a bit light on the programming details. Revision 2 was greatly improved (but still needs more work for some of the more advanced stuff).

Which one are you looking at?

TW

Edited: 23 July 2012, 11:43 a.m.

            
Re: HP39GII and local functions
Message #9 Posted by Gilles Carpentier on 23 July 2012, 5:44 p.m.,
in response to message #8 by Tim Wessman

Hi TIm

I use the version 2 User's Guide - May 2012

Page 247, you can read :

************************
EXPORT ROLLMANY(n,sides)
 BEGIN
  LOCAL k,roll;
  // initialize list of frequencies
  MAKELIST(0,X,1,2*sides,1)=> L2;
  FOR k FROM 1 TO n DO
   ROLLDIE(sides)+ROLLDIE(sides)=> roll;
   L2(roll)+1=> L2(roll);
  END;
 END;

ROLLDIE(n) BEGIN RETURN 1+ FLOOR(RANDOM(N)); END; ******************************

This don't work because the ROLLDIE must be define before to be used(and a typo error with n and N in ROLLDIE). Must be :

******************************
ROLLDIE(n)
 BEGIN
  RETURN 1 + FLOOR(RANDOM(n));
 END;

EXPORT ROLLMANY(n,sides) BEGIN LOCAL k,roll; // initialize list of frequencies MAKELIST(0,X,1,2*sides,1)=> L2; FOR k FROM 1 TO n DO ROLLDIE(sides)+ROLLDIE(sides)=> roll; L2(roll)+1=> L2(roll); END; END; *******************************

Edited: 23 July 2012, 5:57 p.m. after one or more responses were posted

                  
Re: HP39GII and local functions
Message #10 Posted by Tim Wessman on 23 July 2012, 5:56 p.m.,
in response to message #9 by Gilles Carpentier

Thanks, appreciated!

TW

Edited: 23 July 2012, 5:58 p.m.

      
Re: HP39GII and local functions
Message #11 Posted by cyrille de brebisson on 24 July 2012, 1:11 a.m.,
in response to message #1 by Gilles Carpentier

Quote:
As Tim wrote in the previous link,a local function must be define before to be used in another program.

actually, you can do a forward declaration, just like in C... put the name of the function followed by a ';'

cyrille

            
Re: HP39GII and local functions
Message #12 Posted by Gilles Carpentier on 24 July 2012, 4:32 a.m.,
in response to message #11 by cyrille de brebisson

Hi Cyrille, Or like the FORWARD in PASCAL. Interesting and sometime essentiel (cross recursivity).

I have a question about local variables.

Are they local to each functions, or to the whole program ? In another words, can I do that in the same program :

MyLocalFunction
 BEGIN
  LOCAL a,b,c;
  ...
 END;

EXPORT MyGlobalFunction BEGIN LOCAL a,e,f; ... END;

And if I can, does that means that my 'a' in MyLocalFunction has nothing to do with my 'a' in MyGlobalFunction ?

PS : another question ... Local variable must be declared but without 'type'... Is there a way to know the type of a variable ? Like the VTYPE in the 50G ? Could be interesting to write functions wich works with multiple types (kind of polymorph function)

Edited: 24 July 2012, 5:10 a.m.

                  
Re: HP39GII and local functions
Message #13 Posted by Tim Wessman on 24 July 2012, 1:10 p.m.,
in response to message #12 by Gilles Carpentier

Code:

b:="B initial";

TEMP1() BEGIN LOCAL a; a:="A"; b:="b"; PRINT(a); PRINT(b); END;

EXPORT TEMP(c) BEGIN LOCAL a:=c; PRINT(a); PRINT(b); TEMP1(); PRINT(a); PRINT(b); END;

There are a few interesting things here.

On first run, the terminal would have:

B initial
<c input>
A
b
<c input>
b

The next time you run however, the first printed item will be "b". You can have variables that stay around by declaring them outside a program scope. Every function or routine in that program file will be able to use b as a variable. Other programs will not. I believe the content of b also stays around when you power cycle.

So the EXPORT keyword turns it into something recognized anywhere in the system, a non-exported variable outside of a scope will be available to anything in the program file (the file itself is the scope), and something inside of a function is limited to that specific function.

As for type...yeah, oops. We kind of forgot to include that. :-(

Nice thing is it only takes a short time to code it (probably an hour or so for something this simple) and it is fully integrated into the system. To define a system function/variable you provide: a name, getter/evaluator, setter (if a variable), min args, max args, algebraic priority, enabling of automatic input processing including list processing for specific agrumnts, whether it requires full qualification (C1 versus Statistics_2Var.C1 - eg. global or not), special printing if needed, Help, Menu id, and special printing for 2d mode (sigma or the like).

Then you have a new function that will work properly everywhere - including the help interface, placement in the appropriate menu location and even will handle special printing in 2d display mode!

Contrast that with adding a built in function to the 50g ROM. Might take anywhere from a week to much more depending on quite a few factors.

TW

Edited: 24 July 2012, 1:37 p.m.


[ Return to Index | Top of Index ]

Go back to the main exhibit hall