Special variables: Difference between revisions

From Rosetta Code
Content added Content deleted
(initial import from markhobley.yi.org)
 
(→‎Tcl: Added description)
Line 1: Line 1:
{{draft task}}
{{draft task}}[[Category:Special variables]]
Special variables have a predefined meaning within the programming language. The task is to list the special variables used within the language.
Special variables have a predefined meaning within the programming language. The task is to list the special variables used within the language.


Line 24: Line 24:
* SUBSEP - A control variable that specifies the subscript separator for multidimensional arrays
* SUBSEP - A control variable that specifies the subscript separator for multidimensional arrays


=={{header|Tcl}}==
[[Category:Special variables]]
There are three major categories of special variables in Tcl: global variables special to the Tcl language, global variables set by Tcl-based interpreters, and local variables with special interpretations.
===Language Globals===
These variables are defined by the standard implementation of Tcl, and are present in all Tcl interpreters by default.
;env
:This global array is Tcl's interface to the process's environment variables.
;errorCode
:This global scalar holds a machine-readable description of the last error to occur. (Note that prior to Tcl 8.6, internally-generated exceptions often used <tt>NONE</tt> for this value.)
;errorInfo
:This global scalar holds a stack trace from the last error to occur.
;tcl_library
:This global scalar holds the location of Tcl's own internal library.
;tcl_version, tcl_patchLevel
:This global scalar holds the version of Tcl in use. From Tcl 8.5 onwards, these hold the same (detailed) value.
;tcl_pkgPath
:This global scalar holds a Tcl list of directories where Tcl looks for packages by default. This is used to initialize the '''auto_path''' global variable.
;auto_path
:This global scalar holds a Tcl list of directories where Tcl looks for packages (and auto-loaded scripts, though this facility is deprecated).
;tcl_platform
:This global array holds a description of the platform on which Tcl is executing.
;tcl_precision
:This global scalar holds the number of significant figures to use when converting a floating-point value to a string by default. From Tcl 8.5 onwards it should not be changed. (If you are thinking of using this, consider using the <code>format</code> command instead.)
;tcl_rcFileName
:This global scalar holds the name of a file to <code>source</code> when the interpreter starts in interactive mode.
;tcl_rcRsrcName
:This global scalar is only used on classic Mac OS (now deprecated); consult the documentation for more information.
;tcl_traceCompile
:If enabled at library configuration time, this global scalar allows tracing of the compilation of bytecode in the interpreter.
;tcl_traceExec
:If enabled at library configuration time, this global scalar allows tracing of the execution of bytecode in the interpreter.
;tcl_wordchars, tcl_nonwordchars
:These global scalars hold regular expression fragments that describe the current platform's interpretation of what is and isn't a word.
===Interpreter Globals===
These global variables are only features of the most common Tcl-based shells, [[tclsh]] and [[wish]].
;argc
:This global scalar holds the number of arguments (after the script) passed to the Tcl interpreter.
;argv
:This global scalar holds a Tcl list of the arguments (after the script) passed to the Tcl interpreter.
;argv0
:This global scalar holds the name of the main script to execute that was passed to the Tcl interpreter, or the name of the interpreter itself in interactive mode.
;tcl_interactive
:This global scalar holds whether this interpreter is working in interactive mode (i.e., needs to print command prompts, run a REPL, etc.)
;tcl_prompt1, tcl_prompt2
:These global scalars allow customization of the prompt strings in interactive mode.
;geometry
This global scalar holds the user-supplied preferred dimensions of the initial window. Only used by interpreters that load the [[Tk]] library.
===Local Special Variables===
This is a language feature of procedures.
;args
:This local variable holds the Tcl list of arguments supplied to the current procedure after all the other formal arguments have been satisfied. Note that it needs to be explicitly listed in the formal arguments ''and'' be last in the list of formal arguments to have this behavior.

Revision as of 10:21, 3 June 2011

Special variables is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Special variables have a predefined meaning within the programming language. The task is to list the special variables used within the language.

AWK

There are two types of special variables within AWK: Control variables and Informative variables.

  • dollarint variables - The dollarint special variables represent fields within a record
  • ARGC - An informative variable that provides command line parameter information
  • ARGV - An informative array that provides command line parameter information
  • CONVFMT - A control variable that specifies the conversion format of numerical strings
  • ENVIRON - An informative array that contains the environment strings
  • FILENAME - An informative variable that provides the current input [filename]
  • FNR - An informative variable that provides the record number within the current file
  • FS - A control variable that specifies the input field separator
  • NF - An informative variable that provides the number of fields within the current record
  • NR - An informative variable that provides the total number of records processed
  • OFMT - A control variable that specifies the output format of numerical values
  • OFS - A control variable that specifies the output field separator
  • ORS - A control variable that specifies the output record separator
  • RLENGTH - An informative variable that provides the length of the currently matched substring
  • RS - A control variable that specifies the input record separator
  • RSTART - An informative variable that provides the start index of the currently matched substring
  • SUBSEP - A control variable that specifies the subscript separator for multidimensional arrays

Tcl

There are three major categories of special variables in Tcl: global variables special to the Tcl language, global variables set by Tcl-based interpreters, and local variables with special interpretations.

Language Globals

These variables are defined by the standard implementation of Tcl, and are present in all Tcl interpreters by default.

env
This global array is Tcl's interface to the process's environment variables.
errorCode
This global scalar holds a machine-readable description of the last error to occur. (Note that prior to Tcl 8.6, internally-generated exceptions often used NONE for this value.)
errorInfo
This global scalar holds a stack trace from the last error to occur.
tcl_library
This global scalar holds the location of Tcl's own internal library.
tcl_version, tcl_patchLevel
This global scalar holds the version of Tcl in use. From Tcl 8.5 onwards, these hold the same (detailed) value.
tcl_pkgPath
This global scalar holds a Tcl list of directories where Tcl looks for packages by default. This is used to initialize the auto_path global variable.
auto_path
This global scalar holds a Tcl list of directories where Tcl looks for packages (and auto-loaded scripts, though this facility is deprecated).
tcl_platform
This global array holds a description of the platform on which Tcl is executing.
tcl_precision
This global scalar holds the number of significant figures to use when converting a floating-point value to a string by default. From Tcl 8.5 onwards it should not be changed. (If you are thinking of using this, consider using the format command instead.)
tcl_rcFileName
This global scalar holds the name of a file to source when the interpreter starts in interactive mode.
tcl_rcRsrcName
This global scalar is only used on classic Mac OS (now deprecated); consult the documentation for more information.
tcl_traceCompile
If enabled at library configuration time, this global scalar allows tracing of the compilation of bytecode in the interpreter.
tcl_traceExec
If enabled at library configuration time, this global scalar allows tracing of the execution of bytecode in the interpreter.
tcl_wordchars, tcl_nonwordchars
These global scalars hold regular expression fragments that describe the current platform's interpretation of what is and isn't a word.

Interpreter Globals

These global variables are only features of the most common Tcl-based shells, tclsh and wish.

argc
This global scalar holds the number of arguments (after the script) passed to the Tcl interpreter.
argv
This global scalar holds a Tcl list of the arguments (after the script) passed to the Tcl interpreter.
argv0
This global scalar holds the name of the main script to execute that was passed to the Tcl interpreter, or the name of the interpreter itself in interactive mode.
tcl_interactive
This global scalar holds whether this interpreter is working in interactive mode (i.e., needs to print command prompts, run a REPL, etc.)
tcl_prompt1, tcl_prompt2
These global scalars allow customization of the prompt strings in interactive mode.
geometry

This global scalar holds the user-supplied preferred dimensions of the initial window. Only used by interpreters that load the Tk library.

Local Special Variables

This is a language feature of procedures.

args
This local variable holds the Tcl list of arguments supplied to the current procedure after all the other formal arguments have been satisfied. Note that it needs to be explicitly listed in the formal arguments and be last in the list of formal arguments to have this behavior.