Errata for 3rd Edition

Practical Programming in Tcl and Tk
ISBN: 0-13-022028-0

This page reflects errors that were found in the the 3rd edition of the book. If you found an error that is not listed here, please send me a note at welch@acm.org and mention that you did not see it here.

Book Home Page

Last update Tue Apr 15 11:28:42 PDT 2003


Chapter 1

p11Font error on the second use of "return command" in the second to last paragraph.
p16lose is misspelled as loose right after the Hot Tip icon.
p23The cross reference to join should be to p. 67 (not 65), and the reference to lappend should be to p. 62 (not 61).

Chapter 4

p46Font error on string map table entry (charMap, string)
p51In-line examples of string map have incorrect argument order: the string "food" should be the last argument

Chapter 5

p61Example 5-1 uses backslashes to quote braces unnecessarily. The backslashes are not needed because the braces are inside a group formed with double quotes; the braces have no special meaning in this context. The overall point of the example is still valid - use the list command to construct lists instead of quoting by hand. But, the last set command in the example can be written like this and still have $x substituted:
set l2 "{$x} {a b} $y"

Chapter 7

p83The first paragraph of the Scope section references Chapter 7 for namespaces, when it should reference Chapter 14.

Chapter 10

p131Example 10-5 should gets from $in not $file

Chapter 11

p133Hindu, which is the religion, should be Hindi, which is the language.
p140The example that uses [:space:] should be written [[:space:]] because this syntax is only valid inside a bracketed expression.
p150Example 11-3 lists the match variables incorrectly. The command should be:
regexp {([^:]+)://([^:/]+)(:([0-9]+))?(/.*)} $url \ 
   match protocol server x port path
p151Example 11-4 mixes greedy and non-greedy matches, which Tcl makes all into non-greedy because it sees that first :-(. You have to force the last greedy match to go all the way to the end of the string with the $ anchor:
regexp {(.+?)://(.+?)(?::([0-9]+))?(/.*)$} $url \ 
   match protocol server port path
p151 Table 11-7, the fourth pattern should be non-greedy to work the same as the third pattern. It should be:
{^\S+?:}
p154Example 11-5 program listing for proc Url_Decode has a missing open square bracket. Line 3 should contain:
[[:xdigit:]]
p155The example title for 11-6 is incorrect, should name the Cgi_List and Cgi_Query procedures.

Chapter 12

p164Cross reference to Chapter 37 should be to Chapter 44.

Chapter 13

p175The %W clock format has a range of 00-52, not 01-52
p184Example 13-8 should use uplevel when creating its traces:
uplevel 1 [list trace variable $varName wu ReadOnlyTrace]

Chapter 15

p210"fewer" than 128 should probably be "less" than 128 in the discussion about UTF-8 and character codes.

Chapter 17

p227Example 17-1. This procedure leaves the fileevent active. After the vwait you ought to disable the file event:
    fileevent $sock w {set connected ok}
    vwait connected
    fileevent $sock w {}
p230Example 17-5 has the second + sign out of place in the regular expression. The regexp command should be
regexp -nocase {^(http://)?([^:/]+)(:([0-9]+))?(/.*)} \ 
   $url x protocol server y port path
p231Example 17-6 has the same bug as Example 17-5

Chapter 18

p246Replace /request with /page at the end of the first paragraph.
p250Example 18-4 should call Httpd_ReturnData with $contents instead of $data
p258Example 18-14 has a stray trailing double-quote on addr2"

Chapter 27

p404Example 27-14. It is better to use the menu's "invoke" operation than using the command directly. This correctly handles updating the checkbutton or ratiobutton variable. Oliver Bienert contributed this version that has this fix, checks the state of the menu, and takes an explicit accelerator string:
    proc Menu_Bind { what sequence accText menuName label } {
	variable menu
	set m [MenuGet $menuName]
	if [catch {$m index $label} index] {
	    error "$label not in menu $menuName"
	}
	set state [$m entrycget $index -state]
	if [string equal $state normal] {
	    set command [list $m invoke $index]
	} else {
	    set command {}
	}
	bind $what $sequence $command
	$m entryconfigure $index -accelerator $accText
    }

Chapter 31

p436Example 31-1. The graphic doesn't have "Address1" and "Address2" labels, which is what would be produced by the foreach loop in the example. You could get the display either with an if test for the field name, or by having two loop variables: one for the array index and one for the label.

Chapter 33

p453Bottom of the page. The => comparison operator should be >=
p456Last sentence. Delete "is" from "The example is uses the font naming system..."

Chapter 34

p495Table 34-11 is missing the overlapping spec for the find and addtag canvas operations. It takes x1 y1 x2 y2 that specify a bounding box, and returns the item IDs of those objects that overlap that box.

Chapter 41

p573The double-quotes around the wm command argument do not account for $argv0 values with spaces. A better solution is
wm command . [linsert $argv 0 $argv0]

Chapter 44

p610The in-line example that summarizes the Tcl_CreateCommand calling sequence is wrong. It should be:
Tcl_CreateCommand(interp, "cmd", CmdProc, data, DeleteProc);
p617There is no Tcl_GetListFromObj function. Replace all occurrences with:
Tcl_ListObjGetElements(interp, objv[1], &objc, &listv);
There is also the use of Tcl_GetInFromObj in the paragraph text that should be Tcl_GetIntFromObj.
p620The explanation of Tcl_Alloc vs. ckalloc is not right. If you are writing code for the core of Tcl and Tk, you should always use ckalloc and ckfree. If you are writing extensions, you can also use ckalloc and ckfree, and then control their effect with the TCL_MEM_DEBUG compile time flag. If you never use TCL_MEM_DEBUG, then you can stick with Tcl_Alloc and Tcl_Free.

Chapter 46

p665Example 46-8. Just before the end of the for (error) loop there needs to be a break; statement so the loop terminates correctly without error.

Chapter 47

p680Under Evaluating Tcl Commands, there should be a reference to "Tcl_RecordAndEval or Tcl_RecordAndEvalObj".

Chapter 55

p729The reference to binhex should be to macintosh/binhex
p730It should be port 8015, not part 8015.