As mentioned above, packages are usually saved in files and then read
into a CoCoA session using the command 'Source' (or '<<').
I. Full path name, ordinary file sourcing.
package name: $mypackage
file name: this/is/my/stuff.pkg
Suppose the name of your package is '$mypackage' and is kept in the
file with full pathname 'this/is/my/stuff.pkg'. Then the package can
be loaded into the session as usual with either of the commands:
Source('this/is/my/stuff.pkg');
<<'this/is/my/stuff.pkg';
Functions can then be called from the package using the package name,
$mypackage, as a prefix (or using aliases).
II. The standard package path, $-shortcut.
package name: $mypackage
file name: lib/mypackages/stuff.pkg (relative to cocoa directory)
A package is in the 'standard package path' if its file is kept in the
'lib' directory inside the cocoa directory. Suppose your package has
name '$mypackage' and is kept in the file with pathname (relative to
the cocoa directory) 'lib/mypackages/stuff.pkg'. Then the package can
be read by passing this pathname to 'Source', as above, but there are
the following shortcuts:
Source('$mypackages/stuff');
<<'$mypackages/stuff';
<<$mypackages/stuff -- quotes are optional in this case
In other words, the prefix '$' is taking the place of 'lib/' and the
suffix '.pkg' is (and must be) left off. Functions can then be called
as in the previous case.
III. Autoloading.
package name: $mypackages/stuff
file name: lib/mypackages/stuff.pkg (relative to cocoa directory)
Now suppose that the package is in the standard package path, as
above, in the file with pathname (relative to the cocoa directory)
'lib/mypackages/stuff.pkg'. However, now assume that the name of the
package is '$mypackages/stuff', i.e., that it matches the name of its
file (without 'lib/' and '.pkg'). Then, if any function from the
package is called, say '$mypackages/stuff.MyFunction', the package
will automatically be loaded. Of course, one may also source the
package using either method I or II, from above.
* Initialize *
NOTE: As explained in the section entitled "Package Intitialization,"
below, no matter which method is used to source a package, any
function in the package named 'Initialize' will automatically be
executed when the package is loaded.
|