From: Uwe Klein on 20 Apr 2010 12:41 Donald G Porter wrote: > Uwe Klein wrote: > >> I am too dumb to compare strings. >> But I can sort them: > > > Why not use [lsort -dictionary] if the aim is sorting? duh! uwe
From: Glenn Jackman on 20 Apr 2010 15:17 At 2010-04-20 12:20PM, "Donald G Porter" wrote: > Uwe Klein wrote: > > I am too dumb to compare strings. > > But I can sort them: > > Why not use [lsort -dictionary] if the aim is sorting? > > The [lsort -dictionary] command could also be the core of > a pairwise comparison function, but I'll leave it to other > to test whether the performance of such a thing is acceptable > and/or better than other alternatives. Here's an implementation proc string_comp_dictionary {s1 s2} { if {$s1 eq $s2} { return 0 } else { set l [list $s1 $s2] if {$l == [lsort -dictionary $l]} { return -1 } else { return 1 } } } Is that the best way to examine list equality? I also considered examining them as strings: {"$s1 $s2" eq [join [lsort -dictionary [list $s1 $s2]]]} -- Glenn Jackman Write a wise saying and your name will live forever. -- Anonymous
From: Donald G Porter on 20 Apr 2010 17:13 >> The [lsort -dictionary] command could also be the core of >> a pairwise comparison function, but I'll leave it to other >> to test whether the performance of such a thing is acceptable >> and/or better than other alternatives. Georgios Petasis wrote: > In my opinion this shows that string compare is missing an option. Isn't > it? I think a good case could be made that the comparison function embedded in [lsort -dictionary] ought to be exposed to scripts as an independent command. I do not think it would be a good idea to do so by adding an option to [string compare]. As a matter of taste, I don't much like options. If a command doesn't do what you want, create a new one that does, rather than add an option to transform an existing command into a different one. What about "-nocase" you ask? I lost. DGP
From: Rohit M on 21 Apr 2010 00:19 On Apr 20, 9:07 pm, Donald G Porter <d...(a)nist.gov> wrote: > Rohit M wrote: > > if { [expr {$numeralVal1} ] > [expr {$numeralVal2}] } { > > Please find whoever taught you that and tell them never to teach > Tcl again. > > DGP I have not one to blame DGP, self taught. But I know the code is wrong, written hurriedly, dont think there is need to do expr as we already have pure numbers.
From: Rohit M on 21 Apr 2010 00:20 On Apr 21, 12:17 am, Glenn Jackman <gle...(a)ncf.ca> wrote: > At 2010-04-20 12:20PM, "Donald G Porter" wrote: > > > Uwe Klein wrote: > > > I am too dumb to compare strings. > > > But I can sort them: > > > Why not use [lsort -dictionary] if the aim is sorting? > > > The [lsort -dictionary] command could also be the core of > > a pairwise comparison function, but I'll leave it to other > > to test whether the performance of such a thing is acceptable > > and/or better than other alternatives. > > Here's an implementation > > proc string_comp_dictionary {s1 s2} { > if {$s1 eq $s2} { > return 0 > } else { > set l [list $s1 $s2] > if {$l == [lsort -dictionary $l]} { > return -1 > } else { > return 1 > } > } > } > > Is that the best way to examine list equality? I also considered > examining them as strings: > > {"$s1 $s2" eq [join [lsort -dictionary [list $s1 $s2]]]} > > -- > Glenn Jackman > Write a wise saying and your name will live forever. -- Anonymous Thanks Glenn, I think this would be faster that what I have.
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: using libusb from TCL Next: TclOO: Renaming "new" and "create" methods? |