diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2010-01-20 13:42:17 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2010-01-20 13:42:17 (GMT) |
commit | 1549d82a2029add6f62dde489d26a70b466f4fd0 (patch) | |
tree | 6b453022eb94d1d13ccd73cb7e033e4859af45fd /doc/dict.n | |
parent | ee1c40272a0ee43da070323282205173df4a8816 (diff) | |
download | tcl-1549d82a2029add6f62dde489d26a70b466f4fd0.zip tcl-1549d82a2029add6f62dde489d26a70b466f4fd0.tar.gz tcl-1549d82a2029add6f62dde489d26a70b466f4fd0.tar.bz2 |
Use a consistent indentation of 4 for code examples.
Diffstat (limited to 'doc/dict.n')
-rw-r--r-- | doc/dict.n | 44 |
1 files changed, 22 insertions, 22 deletions
@@ -4,7 +4,7 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: dict.n,v 1.22 2010/01/19 09:48:58 dkf Exp $ +'\" RCS: @(#) $Id: dict.n,v 1.23 2010/01/20 13:42:17 dkf Exp $ '\" .so man.macros .TH dict n 8.5 Tcl "Tcl Built-In Commands" @@ -328,16 +328,16 @@ Constructing and using nested dictionaries: set i 0 puts "There are [\fBdict size\fR $employeeInfo] employees" \fBdict for\fR {id info} $employeeInfo { - puts "Employee #[incr i]: $id" - \fBdict with\fR info { - puts " Name: $forenames $surname" - puts " Address: $street, $city" - puts " Telephone: $phone" - } + puts "Employee #[incr i]: $id" + \fBdict with\fR info { + puts " Name: $forenames $surname" + puts " Address: $street, $city" + puts " Telephone: $phone" + } } # Another way to iterate and pick out names... foreach id [\fBdict keys\fR $employeeInfo] { - puts "Hello, [\fBdict get\fR $employeeInfo $id forenames]!" + puts "Hello, [\fBdict get\fR $employeeInfo $id forenames]!" } .CE .PP @@ -347,7 +347,7 @@ A localizable version of \fBstring toupper\fR: # Set up the basic C locale set capital [\fBdict create\fR C [\fBdict create\fR]] foreach c [split {abcdefghijklmnopqrstuvwxyz} ""] { - \fBdict set\fR capital C $c [string toupper $c] + \fBdict set\fR capital C $c [string toupper $c] } # English locales can luckily share the "C" locale @@ -366,22 +366,22 @@ Showing the detail of \fBdict with\fR: .PP .CS proc sumDictionary {varName} { - upvar 1 $varName vbl - foreach key [\fBdict keys\fR $vbl] { - # Manufacture an entry in the subdictionary - \fBdict set\fR vbl $key total 0 - # Add the values and remove the old - \fBdict with\fR vbl $key { - set total [expr {$x + $y + $z}] - unset x y z - } - } - puts "last total was $total, for key $key" + upvar 1 $varName vbl + foreach key [\fBdict keys\fR $vbl] { + # Manufacture an entry in the subdictionary + \fBdict set\fR vbl $key total 0 + # Add the values and remove the old + \fBdict with\fR vbl $key { + set total [expr {$x + $y + $z}] + unset x y z + } + } + puts "last total was $total, for key $key" } set myDict { - a {x 1 y 2 z 3} - b {x 6 y 5 z 4} + a {x 1 y 2 z 3} + b {x 6 y 5 z 4} } sumDictionary myDict |