new tasks
This commit is contained in:
parent
2a4d27cea0
commit
80737d5a6a
1194 changed files with 15353 additions and 1 deletions
24
Task/Collections/Tcl/collections-2.tcl
Normal file
24
Task/Collections/Tcl/collections-2.tcl
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# create an empty array
|
||||
array set h {}
|
||||
# add some pair
|
||||
set h(one) 1
|
||||
set h(two) 2
|
||||
# add more data
|
||||
array set h {three 3 four 4 more {5 6 7 8}}
|
||||
# iterate over it in a couple of ways
|
||||
foreach key [array names h] {puts "$key -> $h($key)"}
|
||||
foreach {key value} [array get h] {puts "$key -> $value"}
|
||||
|
||||
# pass by name
|
||||
proc numkeys_byname {arrayName} {
|
||||
upvar 1 $arrayName arr
|
||||
puts "array $arrayName has [llength [array names arr]] keys"
|
||||
}
|
||||
numkeys_byname h
|
||||
|
||||
# pass serialized
|
||||
proc numkeys_bycopy {l} {
|
||||
array set arr $l
|
||||
puts "array has [llength [array names arr]] keys"
|
||||
}
|
||||
numkeys_bycopy [array get h]
|
||||
9
Task/Collections/Tcl/collections-3.tcl
Normal file
9
Task/Collections/Tcl/collections-3.tcl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# create an empty dictionary
|
||||
set d [dict create]
|
||||
dict set d one 1
|
||||
dict set d two 2
|
||||
# create another
|
||||
set e [dict create three 3 four 4]
|
||||
set f [dict merge $d $e]
|
||||
dict set f nested [dict create five 5 more [list 6 7 8]]
|
||||
puts [dict get $f nested more] ;# ==> 6 7 8
|
||||
12
Task/Collections/Tcl/collections.tcl
Normal file
12
Task/Collections/Tcl/collections.tcl
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
set c [list] ;# create an empty list
|
||||
# fill it
|
||||
lappend c 10 11 13
|
||||
set c [linsert $c 2 "twelve goes here"]
|
||||
# iterate over it
|
||||
foreach elem $c {puts $elem}
|
||||
|
||||
# pass to a proc
|
||||
proc show_size {l} {
|
||||
puts [llength $l]
|
||||
}
|
||||
show_size $c
|
||||
Loading…
Add table
Add a link
Reference in a new issue