Re-usable Procedures
[Context: HL Kit … Basic Concepts and Terminology … Scripting Language]
Procedures provide the means to define script logic in a single location and re-use that logic within multiple scripts by calling the procedure from each of those scripts. Procedures are an extremely convenient tool and are used regularly for a variety of purposes.
There are a number of important considerations that come in to play when using procedures. Some are fundamental to the nature of procedures, while others are selectable, allowing you to choose between various capabilities to better tailor the procedure to your needs.
The topics below summarize each of these considerations.
No Parameters
1. Procedures have no parameters, so you cannot pass parameters to procedures in the way that traditional programming languages do so.
Inherit Caller's Context
inherit the context of the caller
Inherit Caller's Local Variables
2. Procedures inherit all local variables of the calling script. You do still need to declare these local variables within the procedure so that the compiler knows how you intend to use them, but their values will be inherited when the procedure is called. Using local variables, you can pass information between the calling script and the procedure. Changes made to variables within the procedure will remain in effect upon return to the calling script, so you can use this technique to pass information in either direction between the script and procedure.
Script Type Vs. Context
script type vs. context - controls access to special symbols
3. All procedures must be assigned a classification (or context). Scripts can only call procedures that are assigned a compatible classification. For example, you cannot call a procedure with "container" context from within an Eval Script, since that script has a "pick" context. 5. If a procedure is designated as having a specific script type, then you can access the exact same special symbols from within the procedure that can be accessed by that script type. These special symbols inherit they meaning from the calling script, just like variables.
Using Pick and Container Context
pick and container procedures for re-use with preserved context
Generic Procedures
generic allows use with any script
6. Procedures can also be declared as generic, in which case no access to special symbols is possible from within the procedure. The advantage of a generic procedure is that it can be called from scripts of different types, but it comes with this critical limitation. If you need to access a special symbol from within a generic procedures, the calling script must declare a local variable and copy the special symbol value into it prior to calling the procedure.
Calling Other Procedures
4. Procedures are allowed to call other procedures at this time.