6. Module
mCL may construct modules with procedure and package. A procedure defines a new command with the combination of existed commands. package loads an extension without concerning its location.
Procedure
The format of proc command is
proc name argument body
The first argument name of proc is the command name. argument is a list of arguments of the command. An element of the argument can be a string or a list pair. A string is the argument name without default value. A list pair consists of an arugment name and its default value. The body specifies the command sequence that implements the function of a procedure. All the variables except the global variables in the body have a local scope. The return value of the last command will be the return value of the procedure except exist a return command.
Package
package command provides a facility to group a set of commands. To setup a package each library must declare a package provide name version in its file. The 'name' is the package name. 'version' is the version number of the package with the format 'major.minor'. Same major number expresses the interfaces of the packages are compatible. Different minor number may have different implementation. Usually a package should keep backward compatibility. That is the package with bigger major number will work for the package with smaller major number. A package may be distributed on several files by specifing the identical package provide command. In the library file
package provide mcl 3.0
To use a package a package require command must be declared in a program. The syntax is
package require [-exact] name [version].
Without the version argument the hightest version of the package is loaded. If there is no suitable version of package available, 'package require' command will raise an error.
|