Debian Codegraph @

doc/tclvars.n

raw
1 '\"
2 '\" Copyright (c) 1993 The Regents of the University of California.
3 '\" Copyright (c) 1994-1997 Sun Microsystems, Inc.
4 '\"
5 '\" See the file "license.terms" for information on usage and redistribution
6 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7 '\"
8 .TH tclvars n 8.0 Tcl "Tcl Built-In Commands"
9 .so man.macros
10 .BS
11 '\" Note: do not modify the .SH NAME line immediately below!
12 .SH NAME
13 argc, argv, argv0, auto_path, env, errorCode, errorInfo, tcl_interactive, tcl_library, tcl_patchLevel, tcl_pkgPath, tcl_platform, tcl_precision, tcl_rcFileName, tcl_traceCompile, tcl_traceExec, tcl_version \- Variables used by Tcl
14 .BE
15 .SH DESCRIPTION
16 .PP
17 The following global variables are created and managed automatically
18 by the Tcl library. Except where noted below, these variables should
19 normally be treated as read-only by application-specific code and by users.
20 .\" VARIABLE: auto_path
21 .TP
22 \fBauto_path\fR
23 .
24 If set, then it must contain a valid Tcl list giving directories to
25 search during auto-load operations (including for package index
26 files when using the default \fBpackage unknown\fR handler).
27 This variable is initialized during startup to contain, in order:
28 the directories listed in the \fBTCLLIBPATH\fR environment variable,
29 the directory named by the \fBtcl_library\fR global variable,
30 the parent directory of \fBtcl_library\fR,
31 \fB[file dirname [file dirname [info nameofexecutable]]]/lib\fR,
32 the directories listed in the \fBtcl_pkgPath\fR variable.
33 Additional locations to look for files and package indices should
34 normally be added to this variable using \fBlappend\fR.
35 .RS
36 .PP
37 Additional variables relating to package management exist. More
38 details are listed in the \fBVARIABLES\fR section of the \fBlibrary\fR
39 manual page.
40 .RE
41 .\" VARIABLE: env
42 .TP
43 \fBenv\fR
44 .
45 This variable is maintained by Tcl as an array
46 whose elements are the environment variables for the process.
47 Reading an element will return the value of the corresponding
48 environment variable.
49 Setting an element of the array will modify the corresponding
50 environment variable or create a new one if it does not already
51 exist.
52 Unsetting an element of \fBenv\fR will remove the corresponding
53 environment variable.
54 Changes to the \fBenv\fR array will affect the environment
55 passed to children by commands like \fBexec\fR.
56 If the entire \fBenv\fR array is unset then Tcl will stop
57 monitoring \fBenv\fR accesses and will not update environment
58 variables.
59 .RS
60 .PP
61 Under Windows, the environment variables PATH and COMSPEC in any
62 capitalization are converted automatically to upper case. For instance, the
63 PATH variable could be exported by the operating system as
64 .QW path ,
65 .QW Path ,
66 .QW PaTh ,
67 etc., causing otherwise simple Tcl code to have to
68 support many special cases. All other environment variables inherited by
69 Tcl are left unmodified. Setting an env array variable to blank is the
70 same as unsetting it as this is the behavior of the underlying Windows OS.
71 It should be noted that relying on an existing and empty environment variable
72 will not work on Windows and is discouraged for cross-platform usage.
73 .PP
74 The following elements of \fBenv\fR are special to Tcl:
75 .TP
76 \fBenv(HOME)\fR
77 .
78 This environment variable, if set, gives the location of the directory
79 considered to be the current user's home directory, and to which a
80 call of \fBcd\fR without arguments or with just
81 .QW ~
82 as an argument will change into. Most platforms set this correctly by
83 default; it does not normally need to be set by user code.
84 .TP
85 \fBenv(TCL_LIBRARY)\fR
86 .
87 If set, then it specifies the location of the directory containing
88 library scripts (the value of this variable will be
89 assigned to the \fBtcl_library\fR variable and therefore returned by
90 the command \fBinfo library\fR). If this variable is not set then
91 a default value is used.
92 .RS
93 .PP
94 Note that this environment variable should \fInot\fR normally be set.
95 .RE
96 .TP
97 \fBenv(TCLLIBPATH)\fR
98 .
99 If set, then it must contain a valid Tcl list giving directories to
100 search during auto-load operations. Directories must be specified in
101 Tcl format, using
102 .QW /
103 as the path separator, regardless of platform.
104 This variable is only used when initializing the \fBauto_path\fR variable.
105 .TP
106 \fBenv(TCL_TZ)\fR, \fBenv(TZ)\fR
107 .
108 These specify the default timezone used for parsing and formatting times and
109 dates in the \fBclock\fR command. On many platforms, the TZ environment
110 variable is set up by the operating system.
111 .TP
112 \fBenv(LC_ALL)\fR, \fBenv(LC_MESSAGES)\fR, \fBenv(LANG)\fR
113 .
114 These environment variables are used by the \fBmsgcat\fR package to
115 determine what locale to format messages using.
116 .TP
117 \fBenv(TCL_INTERP_DEBUG_FRAME)\fR
118 .
119 If existing, it has the same effect as running \fBinterp debug\fR
120 \fB{} -frame 1\fR
121 as the very first command of each new Tcl interpreter.
122 .RE
123 .\" VARIABLE: errorCode
124 .TP
125 \fBerrorCode\fR
126 .
127 This variable holds the value of the \fB\-errorcode\fR return option
128 set by the most recent error that occurred in this interpreter.
129 This list value represents additional information about the error
130 in a form that is easy to process with programs.
131 The first element of the list identifies a general class of
132 errors, and determines the format of the rest of the list.
133 The following formats for \fB\-errorcode\fR return options
134 are used by the Tcl core; individual applications may define
135 additional formats.
136 .RS
137 .TP
138 \fBARITH\fI code msg\fR
139 .
140 This format is used when an arithmetic error occurs (e.g. an attempt
141 to divide zero by zero in the \fBexpr\fR command).
142 \fICode\fR identifies the precise error and \fImsg\fR provides a
143 human-readable description of the error. \fICode\fR will be either
144 DIVZERO (for an attempt to divide by zero),
145 DOMAIN (if an argument is outside the domain of a function, such as acos(\-3)),
146 IOVERFLOW (for integer overflow),
147 OVERFLOW (for a floating-point overflow),
148 or UNKNOWN (if the cause of the error cannot be determined).
149 .RS
150 .PP
151 Detection of these errors depends in part on the underlying hardware
152 and system libraries.
153 .RE
154 .TP
155 \fBCHILDKILLED\fI pid sigName msg\fR
156 .
157 This format is used when a child process has been killed because of
158 a signal. The \fIpid\fR element will be the process's identifier (in decimal).
159 The \fIsigName\fR element will be the symbolic name of the signal that caused
160 the process to terminate; it will be one of the names from the
161 include file signal.h, such as \fBSIGPIPE\fR.
162 The \fImsg\fR element will be a short human-readable message
163 describing the signal, such as
164 .QW "write on pipe with no readers"
165 for \fBSIGPIPE\fR.
166 .TP
167 \fBCHILDSTATUS\fI pid code\fR
168 .
169 This format is used when a child process has exited with a non-zero
170 exit status. The \fIpid\fR element will be the
171 process's identifier (in decimal) and the \fIcode\fR element will be the exit
172 code returned by the process (also in decimal).
173 .TP
174 \fBCHILDSUSP\fI pid sigName msg\fR
175 .
176 This format is used when a child process has been suspended because
177 of a signal.
178 The \fIpid\fR element will be the process's identifier, in decimal.
179 The \fIsigName\fR element will be the symbolic name of the signal that caused
180 the process to suspend; this will be one of the names from the
181 include file signal.h, such as \fBSIGTTIN\fR.
182 The \fImsg\fR element will be a short human-readable message
183 describing the signal, such as
184 .QW "background tty read"
185 for \fBSIGTTIN\fR.
186 .TP
187 \fBNONE\fR
188 .
189 This format is used for errors where no additional information is
190 available for an error besides the message returned with the
191 error. In these cases the \fB\-errorcode\fR return option
192 will consist of a list containing a single element whose
193 contents are \fBNONE\fR.
194 .TP
195 \fBPOSIX \fIerrName msg\fR
196 .
197 If the first element is \fBPOSIX\fR, then
198 the error occurred during a POSIX kernel call.
199 The \fIerrName\fR element will contain the symbolic name
200 of the error that occurred, such as \fBENOENT\fR; this will
201 be one of the values defined in the include file errno.h.
202 The \fImsg\fR element will be a human-readable
203 message corresponding to \fIerrName\fR, such as
204 .QW "no such file or directory"
205 for the \fBENOENT\fR case.
206 .TP
207 \fBTCL\fR ...
208 .
209 Indicates some sort of problem generated in relation to Tcl itself, e.g. a
210 failure to look up a channel or variable.
211 .PP
212 To set the \fB\-errorcode\fR return option, applications should use library
213 procedures such as \fBTcl_SetObjErrorCode\fR, \fBTcl_SetReturnOptions\fR,
214 and \fBTcl_PosixError\fR, or they may invoke the \fB\-errorcode\fR
215 option of the \fBreturn\fR command.
216 If none of these methods for setting the error code has been used,
217 the Tcl interpreter will reset the variable to \fBNONE\fR after
218 the next error.
219 .RE
220 .\" VARIABLE: errorInfo
221 .TP
222 \fBerrorInfo\fR
223 .
224 This variable holds the value of the \fB\-errorinfo\fR return option
225 set by the most recent error that occurred in this interpreter.
226 This string value will contain one or more lines
227 identifying the Tcl commands and procedures that were being executed
228 when the most recent error occurred.
229 Its contents take the form of a stack trace showing the various
230 nested Tcl commands that had been invoked at the time of the error.
231 .\" VARIABLE: tcl_library
232 .TP
233 \fBtcl_library\fR
234 .
235 This variable holds the name of a directory containing the
236 system library of Tcl scripts, such as those used for auto-loading.
237 The value of this variable is returned by the \fBinfo library\fR command.
238 See the \fBlibrary\fR manual entry for details of the facilities
239 provided by the Tcl script library.
240 Normally each application or package will have its own application-specific
241 script library in addition to the Tcl script library;
242 each application should set a global variable with a name like
243 \fB$\fIapp\fB_library\fR (where \fIapp\fR is the application's name)
244 to hold the network file name for that application's library directory.
245 The initial value of \fBtcl_library\fR is set when an interpreter
246 is created by searching several different directories until one is
247 found that contains an appropriate Tcl startup script.
248 If the \fBTCL_LIBRARY\fR environment variable exists, then
249 the directory it names is checked first.
250 If \fBTCL_LIBRARY\fR is not set or doesn't refer to an appropriate
251 directory, then Tcl checks several other directories based on a
252 compiled-in default location, the location of the binary containing
253 the application, and the current working directory.
254 .\" VARIABLE: tcl_patchLevel
255 .TP
256 \fBtcl_patchLevel\fR
257 .
258 When an interpreter is created Tcl initializes this variable to
259 hold a string giving the current patch level for Tcl, such as
260 \fB8.4.16\fR for Tcl 8.4 with the first sixteen official patches, or
261 \fB8.5b3\fR for the third beta release of Tcl 8.5.
262 The value of this variable is returned by the \fBinfo patchlevel\fR
263 command.
264 .\" VARIABLE: tcl_pkgPath
265 .TP
266 \fBtcl_pkgPath\fR
267 .
268 This variable holds a list of directories indicating where packages are
269 normally installed. It is not used on Windows. It typically contains
270 either one or two entries; if it contains two entries, the first is
271 normally a directory for platform-dependent packages (e.g., shared library
272 binaries) and the second is normally a directory for platform-independent
273 packages (e.g., script files). Typically a package is installed as a
274 subdirectory of one of the entries in the \fBtcl_pkgPath\fR
275 variable. The directories in the \fBtcl_pkgPath\fR variable are
276 included by default in the \fBauto_path\fR
277 variable, so they and their immediate subdirectories are automatically
278 searched for packages during \fBpackage require\fR commands. Note:
279 \fBtcl_pkgPath\fR is not intended to be modified by the application. Its
280 value is added to \fBauto_path\fR at startup; changes to \fBtcl_pkgPath\fR
281 are not reflected in \fBauto_path\fR. If you want Tcl to search additional
282 directories for packages you should add the names of those directories to
283 \fBauto_path\fR, not \fBtcl_pkgPath\fR.
284 .\" VARIABLE: tcl_platform
285 .TP
286 \fBtcl_platform\fR
287 .
288 This is an associative array whose elements contain information about
289 the platform on which the application is running, such as the name of
290 the operating system, its current release number, and the machine's
291 instruction set. The elements listed below will always
292 be defined, but they may have empty strings as values if Tcl could not
293 retrieve any relevant information. In addition, extensions
294 and applications may add additional values to the array. The
295 predefined elements are:
296 .RS
297 .IP \fBbyteOrder\fR
298 The native byte order of this machine: either \fBlittleEndian\fR or
299 \fBbigEndian\fR.
300 .IP \fBdebug\fR
301 If this variable exists, then the interpreter was compiled with and linked
302 to a debug-enabled C run-time. This variable will only exist on Windows,
303 so extension writers can specify which package to load depending on the
304 C run-time library that is in use. This is not an indication that this core
305 contains symbols.
306 .IP \fBengine\fR
307 The name of the Tcl language implementation. When the interpreter is first
308 created, this is always set to the string \fBTcl\fR.
309 .IP \fBmachine\fR
310 The instruction set executed by this machine, such as
311 \fBintel\fR, \fBPPC\fR, \fB68k\fR, or \fBsun4m\fR. On UNIX machines, this
312 is the value returned by \fBuname -m\fR.
313 .IP \fBos\fR
314 The name of the operating system running on this machine,
315 such as \fBWindows NT\fR or \fBSunOS\fR.
316 On UNIX machines, this is the value returned by \fBuname -s\fR.
317 .IP \fBosVersion\fR
318 The version number for the operating system running on this machine.
319 On UNIX machines, this is the value returned by \fBuname -r\fR.
320 .IP \fBpathSeparator\fR
321 .VS 8.6
322 '\" Defined by TIP #315
323 The character that should be used to \fBsplit\fR PATH-like environment
324 variables into their corresponding list of directory names.
325 .VE 8.6
326 .IP \fBplatform\fR
327 Either \fBwindows\fR, or \fBunix\fR. This identifies the
328 general operating environment of the machine.
329 .IP \fBpointerSize\fR
330 This gives the size of the native-machine pointer in bytes (strictly, it
331 is same as the result of evaluating \fIsizeof(void*)\fR in C.)
332 .IP \fBthreaded\fR
333 If this variable exists, then the interpreter
334 was compiled with threads enabled.
335 .IP \fBuser\fR
336 This identifies the
337 current user based on the login information available on the platform.
338 This value comes from the getuid() and getpwuid() system calls on Unix,
339 and the value from the GetUserName() system call on Windows.
340 .IP \fBwordSize\fR
341 This gives the size of the native-machine word in bytes (strictly, it
342 is same as the result of evaluating \fIsizeof(long)\fR in C.)
343 .RE
344 .\" VARIABLE: tcl_precision
345 .TP
346 \fBtcl_precision\fR
347 .
348 This variable controls the number of digits to generate
349 when converting floating-point values to strings. It defaults
350 to 0. \fIApplications should not change this value;\fR it is
351 provided for compatibility with legacy code.
352 .PP
353 .RS
354 The default value of 0 is special, meaning that Tcl should
355 convert numbers using as few digits as possible while still
356 distinguishing any floating point number from its nearest
357 neighbours. It differs from using an arbitrarily high value
358 for \fItcl_precision\fR in that an inexact number like \fI1.4\fR
359 will convert as \fI1.4\fR rather than \fI1.3999999999999999\fR
360 even though the latter is nearer to the exact value of the
361 binary number.
362 .RE
363 .PP
364 .RS
365 If \fBtcl_precision\fR is not zero, then when Tcl converts a floating
366 point number, it creates a decimal representation of at most
367 \fBtcl_precision\fR significant digits; the result may be shorter if
368 the shorter result represents the original number exactly. If no
369 result of at most \fBtcl_precision\fR digits is an exact representation
370 of the original number, the one that is closest to the original
371 number is chosen.
372 If the original number lies precisely between two equally accurate
373 decimal representations, then the one with an even value for the least
374 significant digit is chosen; for instance, if \fBtcl_precision\fR is 3, then
375 0.3125 will convert to 0.312, not 0.313, while 0.6875 will convert to
376 0.688, not 0.687. Any string of trailing zeroes that remains is trimmed.
377 .RE
378 .PP
379 .RS
380 a \fBtcl_precision\fR value of 17 digits is
381 .QW perfect
382 for IEEE floating-point in that it allows
383 double-precision values to be converted to strings and back to
384 binary with no loss of information. For this reason, you will often
385 see it as a value in legacy code that must run on Tcl versions before
386 8.5. It is no longer recommended; as noted above, a zero value is the
387 preferred method.
388 .RE
389 .PP
390 .RS
391 All interpreters in a thread share a single \fBtcl_precision\fR value:
392 changing it in one interpreter will affect all other interpreters as
393 well. Safe interpreters are not allowed to modify the
394 variable.
395 .RE
396 .PP
397 .RS
398 Valid values for \fBtcl_precision\fR range from 0 to 17.
399 .RE
400 .TP
401 \fBtcl_rcFileName\fR
402 .
403 This variable is used during initialization to indicate the name of a
404 user-specific startup file. If it is set by application-specific
405 initialization, then the Tcl startup code will check for the existence
406 of this file and \fBsource\fR it if it exists. For example, for \fBwish\fR
407 the variable is set to \fB~/.wishrc\fR for Unix and \fB~/wishrc.tcl\fR
408 for Windows.
409 .\" VARIABLE: tcl_traceCompile
410 .TP
411 \fBtcl_traceCompile\fR
412 .
413 The value of this variable can be set to control
414 how much tracing information
415 is displayed during bytecode compilation.
416 By default, \fBtcl_traceCompile\fR is zero and no information is displayed.
417 Setting \fBtcl_traceCompile\fR to 1 generates a one-line summary in \fBstdout\fR
418 whenever a procedure or top-level command is compiled.
419 Setting it to 2 generates a detailed listing in \fBstdout\fR of the
420 bytecode instructions emitted during every compilation.
421 This variable is useful in
422 tracking down suspected problems with the Tcl compiler.
423 .PP
424 .RS
425 This variable and functionality only exist if
426 \fBTCL_COMPILE_DEBUG\fR was defined during Tcl's compilation.
427 .RE
428 .\" VARIABLE: tcl_traceExec
429 .TP
430 \fBtcl_traceExec\fR
431 .
432 The value of this variable can be set to control
433 how much tracing information
434 is displayed during bytecode execution.
435 By default, \fBtcl_traceExec\fR is zero and no information is displayed.
436 Setting \fBtcl_traceExec\fR to 1 generates a one-line trace in \fBstdout\fR
437 on each call to a Tcl procedure.
438 Setting it to 2 generates a line of output
439 whenever any Tcl command is invoked
440 that contains the name of the command and its arguments.
441 Setting it to 3 produces a detailed trace showing the result of
442 executing each bytecode instruction.
443 Note that when \fBtcl_traceExec\fR is 2 or 3,
444 commands such as \fBset\fR and \fBincr\fR
445 that have been entirely replaced by a sequence
446 of bytecode instructions are not shown.
447 Setting this variable is useful in
448 tracking down suspected problems with the bytecode compiler
449 and interpreter.
450 .PP
451 .RS
452 This variable and functionality only exist if
453 \fBTCL_COMPILE_DEBUG\fR was defined during Tcl's compilation.
454 .RE
455 .\" VARIABLE: tcl_version
456 .TP
457 \fBtcl_version\fR
458 .
459 When an interpreter is created Tcl initializes this variable to
460 hold the version number for this version of Tcl in the form \fIx.y\fR.
461 Changes to \fIx\fR represent major changes with probable
462 incompatibilities and changes to \fIy\fR represent small enhancements and
463 bug fixes that retain backward compatibility.
464 The value of this variable is returned by the \fBinfo tclversion\fR
465 command.
466 .SH "OTHER GLOBAL VARIABLES"
467 .PP
468 The following variables are only guaranteed to exist in \fBtclsh\fR
469 and \fBwish\fR executables; the Tcl library does not define them
470 itself but many Tcl environments do.
471 .\" VARIABLE: argc
472 .TP 6
473 \fBargc\fR
474 .
475 The number of arguments to \fBtclsh\fR or \fBwish\fR.
476 .\" VARIABLE: argv
477 .TP 6
478 \fBargv\fR
479 .
480 Tcl list of arguments to \fBtclsh\fR or \fBwish\fR.
481 .\" VARIABLE: argv0
482 .TP 6
483 \fBargv0\fR
484 .
485 The script that \fBtclsh\fR or \fBwish\fR started executing (if it was
486 specified) or otherwise the name by which \fBtclsh\fR or \fBwish\fR
487 was invoked.
488 .\" VARIABLE: tcl_interactive
489 .TP 6
490 \fBtcl_interactive\fR
491 .
492 Contains 1 if \fBtclsh\fR or \fBwish\fR is running interactively (no
493 script was specified and standard input is a terminal-like device), 0
494 otherwise.
495 .SH EXAMPLES
496 .PP
497 To add a directory to the collection of locations searched by
498 \fBpackage require\fR, e.g., because of some application-specific
499 packages that are used, the \fBauto_path\fR variable needs to be
500 updated:
501 .PP
502 .CS
503 lappend ::\fBauto_path\fR [file join [pwd] "theLibDir"]
504 .CE
505 .PP
506 A simple though not very robust way to handle command line arguments
507 of the form
508 .QW "\-foo 1 \-bar 2"
509 is to load them into an array having first loaded in the default settings:
510 .CS
511 array set arguments {-foo 0 -bar 0 -grill 0}
512 array set arguments $::\fBargv\fR
513 puts "foo is $arguments(-foo)"
514 puts "bar is $arguments(-bar)"
515 puts "grill is $arguments(-grill)"
516 .CE
517 .PP
518 The \fBargv0\fR global variable can be used (in conjunction with the
519 \fBinfo script\fR command) to determine whether the current script is
520 being executed as the main script or loaded as a library. This is
521 useful because it allows a single script to be used as both a library
522 and a demonstration of that library:
523 .PP
524 .CS
525 if {$::\fBargv0\fR eq [info script]} {
526 # running as: tclsh example.tcl
527 } else {
528 package provide Example 1.0
529 }
530 .CE
531 .SH "SEE ALSO"
532 eval(n), library(n), tclsh(1), tkvars(n), wish(1)
533 .SH KEYWORDS
534 arithmetic, bytecode, compiler, error, environment, POSIX, precision,
535 subprocess, user, variables
536 '\" Local Variables:
537 '\" mode: nroff
538 '\" End: