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