From: Jean-Christian I. <jc....@gm...> - 2015-04-23 00:39:42
|
I'm new to Tcl and trying to port some legacy Tcl 8.0 (I know!) code to 8.5. The legacy behaviour of lsort -command is different in 8.0 than 8.5 and I would like some help in figuring out how to port a line of legacy code to 8.5. Basically 8.0 would allow passing in more than two arguments to the sort command using braces and 8.0 would do substitution of any variables inside the braces. 8.5 does not interpolate the variables in the braces. Unfortunately I am too new to Tcl and don't quite have a handle on interpolation and how to get the same behaviour in 8.5 How can I pass in extra arguments to a custom sorting command? == Old 8.0 behaviour == % set fileId FILENAME FILENAME % set attrNames [list att1 att2] att1 att2 % set arg1 { {1} {stuff} } {1} {stuff} % set arg2 { {2} {more stuff} } {2} {more stuff} % lappend records $arg1 { {1} {stuff} } % lappend records $arg2 { {1} {stuff} } { {2} {more stuff} } % proc custom_sort {a1 a2 toSort1 toSort2} { puts "a1: $a1" puts "a2: $a2" puts "toSort1; $toSort1" puts "toSort2: $toSort2" return 1 } % lsort -command {custom_sort $fileId $attrNames} $records a1: FILENAME a2: att1 att2 toSort1; {1} {stuff} toSort2: {2} {more stuff} { {2} {more stuff} } { {1} {stuff} } % == 8.5 Behaviour == [only showing output] % lsort -command {custom_sort $fileId $attrNames} $records a1: $fileId a2: $attrNames toSort1; {1} {stuff} toSort2: {2} {more stuff} { {2} {more stuff} } { {1} {stuff} } Thank you! |