Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Optional-parameters/Tcl/optional-parameters-1.tcl
Normal file
15
Task/Optional-parameters/Tcl/optional-parameters-1.tcl
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
proc tablesort {table {ordering ""} {column 0} {reverse 0}} {
|
||||
set direction [expr {$reverse ? "-decreasing" : "-increasing"}]
|
||||
if {$ordering ne ""} {
|
||||
lsort -command $ordering $direction -index $column $table
|
||||
} else {
|
||||
lsort $direction -index $column $table
|
||||
}
|
||||
}
|
||||
|
||||
puts [tablesort $data]
|
||||
puts [tablesort $data "" 1]
|
||||
puts [tablesort $data "" 0 1]
|
||||
puts [tablesort $data {
|
||||
apply {{a b} {expr {[string length $a]-[string length $b]}}}
|
||||
}]
|
||||
18
Task/Optional-parameters/Tcl/optional-parameters-2.tcl
Normal file
18
Task/Optional-parameters/Tcl/optional-parameters-2.tcl
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package require Tcl 8.5; # Only for the list expansion syntax
|
||||
|
||||
proc tablesort {table args} {
|
||||
array set opt {ordering "" column 0 reverse 0}
|
||||
array set opt $args
|
||||
set pars [list -index $opt(column)]
|
||||
if {$opt(reverse)} {lappend pars -decreasing}
|
||||
if {$opt(ordering) ne ""} {lappend pars -command $opt(ordering)}
|
||||
lsort {*}$pars $table
|
||||
}
|
||||
|
||||
puts [tablesort $data]
|
||||
puts [tablesort $data column 1]
|
||||
puts [tablesort $data column 0]
|
||||
puts [tablesort $data column 0 reverse 1]
|
||||
puts [tablesort $data ordering {
|
||||
apply {{a b} {expr {[string length $b]-[string length $a]}}}
|
||||
}]
|
||||
Loading…
Add table
Add a link
Reference in a new issue