tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
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