constTcl 9.1 only
Sets a variable and makes it a constant.
const VAR VALUE
Description
Sets the variable VAR to VALUE and makes it a constant. A later write to VAR is the error can't set "VAR": variable is a constant, and unset VAR is an error too. unset -nocomplain VAR gives no error and keeps the constant. A const of a variable that is a constant changes no value and gives no error, so const can run in a loop.
VAR is a scalar variable: an array and an element of an array give an error. The write runs the write traces of VAR. When a trace fails, VAR is no constant. A constant that is a local variable ends with its proc, and a constant of a namespace ends with the namespace.
info constant VAR gives 1 for a constant, and info consts gives the names of the constants.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| VAR | variable name | required | The variable that becomes a constant. |
| VALUE | string | required | The value of the constant. |
Returns
An empty string.
Examples
% const pi 3.14159
> catch {set pi 3} msg
> list $pi $msg
3.14159 {can't set "pi": variable is a constant}
% const a 1
> const a 2
> list $a [info constant a] [info consts a]
1 1 a
Errors
% const
wrong # args: should be "const varName value"
-errorcode TCL WRONGARGS
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 only.
- Since
- ztcl 1.0.0-beta.2