| Home News Product Order Forum Feedback Partner Profile | © Neatware 2000 |
| Neatware | Snaml |
|
Module |
|
|
Last Update: Wed Apr 12 20:04:25 2000 |
|
Snaml Basic
Introduction Syntax Control Types Modules Status Snaml HTML HTML Structure Link Objects Text Font Snaml CSS CSS Script Snaml CGI CGI Variables Output Form Application Snaml XML XML Document EBNF |
The syntax of proc command is
proc name argument body
The first argument 'name' of proc is the procedure name. 'argument' is a list of arguments of the defined command. An element of the 'argument' can be a string or a list of pairs. A string is the argument name without default value. A 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 of the global variables in the body have a local scope. The return value of the last command is the return value of the proc. Typically, a 'return' command in a proc can return a value directly.
Global scope is the top level scope. In the global scope a variable is a global variable as default. A 'global v1 v2 ...' command declares variables as global variables in a proc. Namespace prefix :: of a variable also makes a variable access as a global variable.
upvar command passes the name of a variable into a proc. It refers a local variable to a variable outer one level of the scope. Its syntas is
upvar var1 localvar1 [var2 localvar2] ...
.
To pass an array name into a proc, upvar command may refer to the array with a local variable. For example.
# namespace declaration
namespace eval name {
variable var value ...
namespace export proc1 proc2 ...
}
# procedure declaration
proc name::proc1 {args} {
variable var
commands ...
}
...
# procedure declaration
proc name::procn {args} {
commands ...
}
'namespace eval name' specifies the name of a namespace. In the namespace specification, keyword 'variable' declares the variable 'var' and its initial value 'value'. The 'namespace export' command declares the procedure names that will be available for invocation. Outside the 'namespace eval' declaration the proc specifies a procedure of the namespace. The procedure name consists a namespace prefix name linked by :: with a procedure name and its arguments. Local namespace variable must be declared by variable command.
It is possible to define a namespace with the full qualified name rather than relative qualified name. Global prefix :: must be added to the namespace name. We suggest namespace name and proc name starts with the capital letter, variable name starts in the lowercase letter. These naming convenition will make code readable.
'source filename' command will evaluate the commands in the filname. Its return value is the value of the last command in the filename. filename is the location of the file. It may be a relative or absolute path. Source command is limited to load a text file and the file location is dependent on the platforms.
'load filename' command will load an binary code into the program and calls an initialization procedure in the extension. The filename varies from platforms such as .so in Sun and .dll in Windows. The extension must obey Tcl extension rules in order to add them as new commands.
Package command provides a facility to group a set of commands. To setup a package each library must declare a 'package provide pkgname pkgver' in its file. The 'pkgname' is the package name. 'pkgver' 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.
To use a package a 'package require' command must be declared in a program. The syntax is 'package require pkgname [pkgver]'. Without the pkgver 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.
To create a package, you need to do manually package installation.
|
|
|
|
Last Update: Wed Apr 12 20:04:25 2000 |
|
Module |
| Neatware | Snaml |
| Home News Product Order Forum Feedback Partner Profile | © Neatware 2000 |