up previous next
3.9.8 Package Initialization
|
Packages are often stored in files and read into a CoCoA session
using the
Source
command. When a package is loaded, any function
whose name is
Initialize will automatically be executed. For
example, this feature may be used to print a message or initialized
global variables when the package is read into a session.
(Note: following this rule, if the first time you access package
PKG is to make an explicit call to the function PKG.Initialize() then
the function will be called twice!)
Package $example
Define Initialize()
Print "CALLED INITIALIZE";
MEMORY.MyVar := 17;
EndDefine;
EndPackage;
CALLED INITIALIZE
-------------------------------
MEMORY.MyVar;
17
-------------------------------
|