Version 0 of Things British

Updated 2001-02-14 22:55:58

Richard Suchenwirth - This is not another OO game, just some Tcl notes for peculiarities of the United Kingdom. Tcl/Tk code to draw the Union Jack on a canvas can be had at Describing and rendering flags in Tcl.

Non-decimal money: Kevin Kenny (2 November 2000) At least we seldom have to deal with mixed radix currencies any more; dealing with pounds-shillings-pence was quite an �sd trip.

 �2 16s 2 3/4d

was read as "two pounds, sixteen shillings tuppence ha'penny farthing").


RS: Except for fractions of old pence, the following converts decimal GBP amounts to L-s-d, and Unicoded:

 proc dec2trad {amount {slash " "}} {
        set L [expr int($amount)]
        set s [expr int(($amount-$L)*20)]
        set d [expr int(($amount-$L-$s/20.)*240+0.5)]
        set res ""
        if {$slash==" "} {
                if $L {append res "\u20A4$L"}
                if $s {append res " ${s}s"}
                if $d {append res " ${d}d"}
        } else {
                if $L {append res "\u20A4$L/"}
                if $s {append res $s} else {append res -}
                if $d {append res /$d} else {append res /-}
        }
        set res
 }
 dec2trad 10.01 /
 �10/-/2
 dec2trad .10 /
 2/-

UK phone-book sorting order: Donal Fellows wrote in comp.lang.tcl: Indeed, even for strings there are many different ordering relations. Tcl supports two directly in [lsort]: ASCII and Dictionary. There are others though; dictionary ordering should be dependent on locale, and there are also other orderings like phone-book ordering (in the UK, MacDonald should come between McArthur and McEwan in phone number listings, and all should precede Mabbs.)

 proc sort.uk.phone {x y} {
        foreach i {x y} {
            regsub {Ma?c ?([A-Z])} [set  $i] {M_\1} $i
        } 
        string compare $x $y
 }
 lsort -command sort.uk.phone {MacDonald McArthur McEwan Lyttle Mabbs Jones}
 Jones Lyttle McArthur MacDonald McEwan Mabbs

KBK (14 February 2001) -- [lsort -command] is a pig from the performance standpoint. Much faster, although treble the memory consumption, is:

 proc sort.uk.phone2 { list } {
    foreach name $list {
        regsub {Ma?c ?([A-Z])} $name {M_\1} key
        lappend list2 [list $key $name]
    }
    foreach pair [lsort -index 0 -ascii $list2] {
        lappend list3 [lindex $pair 1]
    }
    return $list3
 }

 sort.uk.phone2 {MacDonald McArthur McEwan Lyttle Mabbs Jones}

For virtually all applications, this technique of ``sort a list of pairs'' should be preferred to [lsort -command].

There's a benchmark of the two versions of the command over on the lsort page.


Arts and crafts of Tcl-Tk programming