Creating an Array: Difference between revisions

→‎{{header|Tcl}}: migrate from Array Initialization
m (→‎{{header|AWK}}: merging from array init)
(→‎{{header|Tcl}}: migrate from Array Initialization)
Line 883:
=={{header|Tcl}}==
 
Tcl uses the <tt>list</tt> for what many other languages call "array". A list is an ordered, numerically indexable (zero based) collection of values in a single variable. Each list entry itself can be a list.
 
<lang tcl>set a [list 5 hello {} [expr 3*5]]</lang>
 
this creates a list with the name <tt>a</tt> and four elements - the number 5, the word "hello", an empty list, and the result of the expression "3*5".
 
The <tt>lrepeat</tt> command builds a list by repeating elements
<lang tcl>set a [lrepeat 5 foo] ;# {foo foo foo foo foo}</lang>
 
lrepeat can be used to create multidimensional lists
<lang tcl>set a [lrepeat 4 [lrepeat 2 0]] ;# {{0 0} {0 0} {0 0} {0 0}}
 
Tcl does have an "<tt>array</tt>", though, which is really an "associative array":
Anonymous user