diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2012-10-16 13:14:28 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2012-10-16 13:14:28 (GMT) |
commit | 6c99b4f5451a3804f546cfe6a2164835603f67e6 (patch) | |
tree | b39ac82a9bce6a5b82d8c2ec8cae14c64e4ffc86 /doc/dict.n | |
parent | 37f4435517b352b24b20260f00401120be11547b (diff) | |
parent | 7e90ca9d199a4a36d05b93ef6912cccf5da60e6b (diff) | |
download | tcl-6c99b4f5451a3804f546cfe6a2164835603f67e6.zip tcl-6c99b4f5451a3804f546cfe6a2164835603f67e6.tar.gz tcl-6c99b4f5451a3804f546cfe6a2164835603f67e6.tar.bz2 |
Implementation of TIP #405.
Diffstat (limited to 'doc/dict.n')
-rw-r--r-- | doc/dict.n | 29 |
1 files changed, 27 insertions, 2 deletions
@@ -147,6 +147,31 @@ keys are treated as if they map to an empty list, and it is legal for there to be no items to append to the list. It is an error for the value that the key maps to to not be representable as a list. .TP +\fBdict map \fR{\fIkeyVar valueVar\fR} \fIdictionaryValue body\fR +. +This command applies a transformation to each element of a dictionary, +returning a new dictionary. It takes three arguments: the first is a +two-element list of variable names (for the key and value respectively of each +mapping in the dictionary), the second the dictionary value to iterate across, +and the third a script to be evaluated for each mapping with the key and value +variables set appropriately (in the manner of \fBlmap\fR). In an iteration +where the evaluated script completes normally (\fBTCL_OK\fR, as opposed to an +\fBerror\fR, etc.) the result of the script is put into an accumulator +dictionary using the key that is the current contents of the \fIkeyVar\fR +variable at that point. The result of the \fBdict map\fB command is the +accumulator dictionary after all keys have been iterated over. +.RS +.PP +If the evaluation of the body for any particular step generates a \fBbreak\fR, +no further pairs from the dictionary will be iterated over and the \fBdict +map\fR command will terminate successfully immediately. If the evaluation of +the body for a particular step generates a \fBcontinue\fR result, the current +iteration is aborted and the accumulator dictionary is not modified. The order +of iteration is the natural order of the dictionary (typically the order in +which the keys were added to the dictionary; the order is the same as that +used in \fBdict for\fR). +.RE +.TP \fBdict merge \fR?\fIdictionaryValue ...\fR? . Return a dictionary that contains the contents of each of the @@ -408,9 +433,9 @@ puts $foo # prints: \fIa b foo {a b} bar 2 baz 3\fR .CE .SH "SEE ALSO" -append(n), array(n), foreach(n), incr(n), list(n), lappend(n), set(n) +append(n), array(n), foreach(n), mapeach(n), incr(n), list(n), lappend(n), set(n) .SH KEYWORDS -dictionary, create, update, lookup, iterate, filter +dictionary, create, update, lookup, iterate, filter, map '\" Local Variables: '\" mode: nroff '\" End: |