Version 55 of Peter Lewerin

Updated 2014-07-16 21:47:55 by PeterLewerin

A.K.A. PL. Used to be an avid Tcler in the early noughties, but later moved on to other pursuits. In 2010, he came back briefly to clean up some useless old pages he'd left behind. He thought that one would be his last editing visit, but in 2013 his youngest son chose (on PL's suggestion) to use Tcl/Tk for the GUI of an encrypting messaging application. PL decided then and there to brush up on his Tcling skills*.

Some pages he made during his first stay:

He certainly didn't create the Endekalogue but seems to have been the first one to use the term.

It took him over ten years to realize the significance of his wiki page number. Srsly. Still, Mark Zuckerberg may have 'I'm CEO, Bitch' on his business card, but he does not have page 1337 on the Tcler's Wiki. Too bad, Marky!

For electronic communication, this might be useful: join [list [join {peter lewerin} \x2e] [join {tele2 se} \x2e]]] \x40

As usual, clicking on this page's title brings up a list of pages that reference this page, i.e. where his full name is mentioned. Among those is the Tcl'ers list for obvious reasons, but apart from that it's usually either pages he started or made really significant contributions to, or in at least one case a page where he was mentioned by full name and didn't want to edit someone else's words. On pages where he makes a less important edit (maybe just a comment) he normally uses the PL alias, so they will be listed here .


One of his finest Tcl moments in the 2001-2005 era was when he used Tcl + Tcllib's csv module to save the largest (amateur, possibly overall) database of folk music in Sweden (>100k songs at that time). The collector was using an old database custom-written in Turbo Pascal. All sources and specifications were lost, and as the computers were beginning to go decrepit, he was about to lose years of work. Enter PL with the Tcl CD he used to always carry around. He wrote a probe to find out the database format as the collector was watching, then wrote a dumper to translate it into a CSV file, and then successfully imported it into Access. Programming is always fun; if you can save someone's bacon while programming it's even better.

He started his programming career in the 1980s at Volvo Komponenter (currently Volvo Powertrain) where he used AUTOLisp and Pascal, and later (pre-ANSI) C. He stayed with C and C++ for many years (eventually teaching those languages in secondary school) before a brief but passionate fling with various scripting languages, notably Perl. After working far too hard for too many years, the almost effortless nature of Tcl programming came as a great relief, but unfortunately he couldn't find a way to go professional with Tcl**, so it petered out. In 2013, he found himself working with data extraction/presentation and light systems development, mostly using IBM Cognos Report Studio and VBA for Excel/Access (he was unable to choose his tools at this workplace).


(2014-01-22:) One of his not at all finest Tcl (or, rather, Tk) moments was when he was trying to experiment with keypresses (it has to be noted that he was very tired and worn-out after work). He started with the code

console show ; bind . <KeyPress> { puts %s } ;# state field

This not being very informative, he tried adding more fields to the output. Being a spick-and-span kind of guy, he decided to format the output:

console show ; bind . <KeyPress> { puts [format "s=%s, k=%s" %s %k] } ;# state and keycode fields

(You're probably laughing already.) Well, what do you know, both fields show the same value! How about other fields, then?

console show ; bind . <KeyPress> { puts [format "s=%s, k=%s, A=%s, K=%s, N=%s" %s %k %A %K %N] }
# state, keycode, Unicode character, keysym-text, and keysym-decimal fields

Hey, they all show the exact same value, what gives? ...waaait...

console show ; bind . <KeyPress> { puts "s=%s, k=%k, A=%A, K=%K, N=%N" }
# state, keycode, Unicode character, keysym-text, and keysym-decimal fields

Yeah, that's more like it. Good thing nobody saw that... oops.


One simple but useful command is

proc man cmd {
    format http://www.tcl.tk/man/tcl/TclCmd/%s.htm $cmd
}

which, given the name of a documented Tcl command, generates an URL to the version-independent man page for that command.

If one were to use that to create formatted links on, say, the Tcler's wiki or Stack Overflow , one could use the following format definitions:

set linkformats [dict create \
    {tcler's wiki} [dict create \
        verbose  {%s} \
        brief    {[%s%%|%%%s%%|%%]}] \
    {stackoverflow} [dict create \
        verbose  {%s} \
        brief    {[%2$s](%1$s)} \
        html     {<a href="%1$s" title="%2$s">%2$s</a>}]]

set listformats [dict create {tcler's wiki} {   * } {stackoverflow} { * }]

Invocation could be like this:

set cmds {set puts format}
set site {tcler's wiki}
set style verbose
set fmt [dict get $linkformats $site $style]
set prefix [dict get $listformats $site]
foreach cmd $cmds {
    puts $prefix[format $fmt [man $cmd] $cmd]
}

Producing

   * http://www.tcl.tk/man/tcl/TclCmd/set.htm
   * http://www.tcl.tk/man/tcl/TclCmd/puts.htm
   * http://www.tcl.tk/man/tcl/TclCmd/format.htm

I.e.

Or

set cmds {set puts format}
set fmt [dict get $linkformats {tcler's wiki} brief]
puts [join [lmap cmd $cmds { format $fmt [man $cmd] $cmd }] {, }]

I.e.

set , puts , format

Less general:

proc socmddocs args {
    set cmds [lsort $args]
    set fn {cmd {format http://www.tcl.tk/man/tcl/TclCmd/%s.htm $cmd}}
    set fmt {[%2$s](%1$s)}
    puts -nonewline "Documentation: "
    puts [join [lmap cmd $cmds { format $fmt [apply $fn $cmd] $cmd }] {, }]
}

*) "Get a string for a file name consisting of a time stamp? Um, I think you need a command called... 'clock'. *does web search* Yeah, that's it."

**) And to be honest, he was being a bit lax with Tcl use. It shows in places if you look at his code on this wiki. He hopes to do better this time.