Neatware Company

An ISV for Mobile, Cloud, and Video Technologies and Software.

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.

The syntax 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.

  proc distance {x, y, {a 0} {b 0}} {
    set xa [expr x-a]
    set yb [expr y-b]
    return [expr sqrt(xa*xa + yb*yb)]
  }

to invoke the procedure

  set d [distance $a1 $b1 $a2 $b2]

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 media 2.0

To use a package a 'package require' command must be declared in a program. The syntax is 'package require 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.

  # in the application file
  package require media