HP (Hewlett-Packard) NW280AAABA Calculator User Manual


 
Programming in HP PPL 515
L2(roll)+1 L2(roll);
END;
END;
By omitting the EXPORT command when a function is
declared, its visibility can be restricted to the program
within which it is defined. For example, you could define the
ROLLDIE function inside the ROLLMANY program like this:
ROLLDIE();
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+RANDINT(n-1);
END;
In the second version of the ROLLMANY program, there is
no ROLLDIE function exported from another program.
Instead, ROLLDIE is visible only to ROLLMANY. The
ROLLDIE function must be declared before it is called.
The first line of the program above contains the
declaration of the ROLLDIE function. The definition of the
ROLLDIE function is located at the end of the program.
Finally, the list of results could be returned as the result of
calling ROLLMANY instead of being stored directly in the
global list variable, L2. This way, if the user wanted to
store the results elsewhere, it could be done easily.
ROLLDIE();
EXPORT ROLLMANY(n,sides)
BEGIN
LOCAL k,roll,results;
// initialize list of frequencies
MAKELIST(0,X,1,2*sides,1) results;