summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--doc/dict.n28
2 files changed, 29 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 0010208..7053a12 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
2009-01-07 Donal K. Fellows <dkf@users.sf.net>
+ * doc/dict.n: Added more examples. [Tk Bug 2491235]
+
* tests/oo.test (oo-22.1): Adjusted test to be less dependent on the
specifics of how [info frame] reports general frame information, and
instead to focus on what methods add to it; that's really what the
diff --git a/doc/dict.n b/doc/dict.n
index 4bbfedc..2dc4db3 100644
--- a/doc/dict.n
+++ b/doc/dict.n
@@ -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.20 2008/12/10 11:15:05 dkf Exp $
+'\" RCS: @(#) $Id: dict.n,v 1.21 2009/01/07 13:50:03 dkf Exp $
'\"
.so man.macros
.TH dict n 8.5 Tcl "Tcl Built-In Commands"
@@ -256,6 +256,32 @@ and
are equivalent dictionaries (with different string representations).
.SH EXAMPLES
.PP
+Basic dictionary usage:
+.PP
+.CS
+# Make a dictionary to map extensions to descriptions
+set filetypes [\fBdict create\fR .txt "Text File" .tcl "Tcl File"]
+
+# Add/update the dictionary
+\fBdict set\fR filetypes .tcl "Tcl Script"
+\fBdict set\fR filetypes .tm "Tcl Module"
+\fBdict set\fR filetypes .gif "GIF Image"
+\fBdict set\fR filetypes .png "PNG Image"
+
+# Simple read from the dictionary
+set ext ".tcl"
+set desc [\fBdict get\fR $filetypes $ext]
+puts "$ext is for a $desc"
+
+# Somewhat more complex, with existence test
+foreach filename [glob *] {
+ set ext [file extension $filename]
+ if {[\fBdict exists\fR $filetypes $ext]} {
+ puts "$filename is a [\fBdict get\fR $filetypes $ext]"
+ }
+}
+.CE
+.PP
Constructing and using nested dictionaries:
.PP
.CS