<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://www.tcl.tk/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Fri May 24 22:15:19 GMT 2013 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='371'>
<header><title>Improvements for the dict command</title><author address="mailto:tombert@gmx.at">Thomas Perschak</author><author address="mailto:twylite@crypt.co.za">Trevor Davel</author><status type='project' state='draft' tclversion="8.7" vote='prior'>$Revision: 1.3 $</status><history></history><created day='5' month='aug' year='2010' /></header>
<abstract>The <emph style="bold">dict</emph> command is limited by allowing manipulation of only the first level of key elements. Not only should the <emph style="bold">dict get</emph> accept a nested key list, but also the other commands like <emph style="bold">dict replace</emph>.</abstract>
<body><section title="Specification And Example">
<para>The following line:</para>
<verbatim><vline encoding='base64'>ZGljdCBnZXQgey1yYW5nZSB7LXZhbHVlcyB7YSBiIGN9IC1iYXNlIE19IC1uYW1lIG15bmFtZX0gXA==</vline><vline encoding='base64'>ICAgICAgICAtcmFuZ2UgLWJhc2U=</vline></verbatim>
<para>Results in:</para>
<verbatim><vline encoding='base64'>TQ==</vline></verbatim>
<para>But how to change the base? I suggest the following <emph style="bold">dict</emph> syntax extension:</para>
<verbatim><vline encoding='base64'>ZGljdCByZXBsYWNlIHstcmFuZ2Ugey12YWx1ZXMge2EgYiBjfSAtYmFzZSBNfSAtbmFtZSBteW5hbWV9IFw=</vline><vline encoding='base64'>ICAgICAgICB7LXJhbmdlIC1iYXNlfSBr</vline></verbatim>
<para>Results in:</para>
<verbatim><vline encoding='base64'>LXJhbmdlIHstdmFsdWVzIHthIGIgY30gLWJhc2Uga30gLW5hbWUgbXluYW1l</vline></verbatim>
<para>Allowing a nested key list would not break any previous code, but substantially improve the <emph style="bold">dict</emph> command.</para>
</section>
<section title="Rationale">
<para>The <emph style="bold">dict</emph> command is the basis for handling database like structures. By allowing nested keys this would give more freedom in organizing these structures like the example above.</para>
<rule/>
</section>
<section title="Comments">
<para>Twylite 2010/08/17: The specification states that &quot;Allowing a nested key list would not break any previous code&quot;. This is not correct, for example:</para>
<verbatim><vline encoding='base64'>ZGljdCByZXBsYWNlIHsiSmFuZSBTbWl0aCIgIjExIEZvbyBSb2FkIiAiSm9obiBEb2UiICJBZGRyZXNzIHVua25vd24ifSB7SmFuZSBTbWl0aH0gbmV3X2FkZHJlc3M=</vline><vline encoding='base64'>LT4ge0phbmUgU21pdGh9IG5ld19hZGRyZXNzIHtKb2huIERvZX0ge0FkZHJlc3MgdW5rbm93bn0=</vline></verbatim>
<para>Existing code that uses <emph style="bold">dict replace</emph> in conjunction with keys that are valid lists of 2 or more elements would break.</para>
<para>Also, drawing from experience, the nested key approach is a source of subtle bugs. It is natural to write code such as:</para>
<verbatim><vline encoding='base64'>ZGljdCByZXBsYWNlICRkaWN0ICRrZXkgJHZhbHVl</vline></verbatim>
<para>but that contains a bug that is often missed during testing. The correct approach would be:</para>
<verbatim><vline encoding='base64'>ZGljdCByZXBsYWNlICRkaWN0IFtsaXN0ICRrZXldICR2YWx1ZQ==</vline></verbatim>
<rule/>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>
