<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://www.tcl.tk/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Thu May 17 04:16:53 GMT 2012 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='323'>
<header><title>Do Nothing Gracefully</title><author address="mailto:colin@chinix.com">Colin McCormack</author><author address="mailto:dgp@users.sf.net">Don Porter</author><author address="mailto:kennykb@acm.org">Kevin B. Kenny</author><status type='project' state='final' tclversion="8.6" vote='after'>$Revision: 1.6 $</status><history></history><created day='6' month='aug' year='2008' /></header>
<abstract>A number of Tcl&apos;s built-in commands currently raise errors when given arguments that would cause them to do nothing. This proposal asks that they instead simply do nothing gracefully.</abstract>
<body><section title="Rationale">
<para>With the introduction of {*} syntax in Tcl 8.5 and its ability to convert one original word into zero words when an empty list is expanded, scripts using the syntax are forced to check for the empty list when passing expanded arguments to a command taking variable numbers of arguments, but arbitrarily rejecting zero arguments. For example,</para>
<verbatim><vline encoding='base64'>IHZhcmlhYmxlIHsqfSRkaWN0</vline></verbatim>
<para>will currently fail if $dict has no entries. Letting no-ops simply be no-ops rather than errors greatly lightens the programming burden on callers. There may be some marginal performance benefits as well.</para>
<para>Furthermore, there is no sound reason to constrain the argument count of these commands to be positive when an argument count of zero has a natural interpretation as a no-op. There is an elegance in permitting a function to range coherently over the complete domain.</para>
</section>
<section title="Proposal">
<para>The syntax of the following commands shall be revised as described:</para>
<enumerate><item.e index='1'><para><emph style="bold">file delete</emph> - accept zero pathnames.</para></item.e><item.e index='2'><para><emph style="bold">file mkdir</emph> - accept zero directories.</para></item.e><item.e index='3'><para><emph style="bold">global</emph> - accept zero variable names.</para></item.e><item.e index='4'><para><emph style="bold">glob</emph> - accept zero patterns, returning list of zero matching files (with <emph style="bold">-nocomplain</emph>) or &quot;no matches&quot; error.</para></item.e><item.e index='5'><para><emph style="bold">lassign</emph> - accept zero variable names. [<url ref="https://sourceforge.net/support/tracker.php?aid=1671880"/>]</para></item.e><item.e index='6'><para><emph style="bold">linsert</emph> - accept zero elements. [<url ref="https://sourceforge.net/support/tracker.php?aid=1672056"/>]</para></item.e><item.e index='7'><para><emph style="bold">lrepeat</emph> - accept both <emph style="italic">number</emph> = 0 and zero elements. [<url ref="https://sourceforge.net/support/tracker.php?aid=1671951"/>]</para></item.e><item.e index='8'><para><emph style="bold">my variable</emph> - accept zero variable names.</para></item.e><item.e index='9'><para><emph style="bold">namespace upvar</emph> - accept zero variable names.</para></item.e><item.e index='10'><para><emph style="bold">tcl::tm::path add</emph> - accept zero paths.</para></item.e><item.e index='11'><para><emph style="bold">tcl::tm::path remove</emph> - accept zero paths.</para></item.e><item.e index='12'><para><emph style="bold">variable</emph> - accept zero variable names. [<url ref="https://sourceforge.net/support/tracker.php?aid=1881284"/>]</para></item.e></enumerate>
</section>
<section title="Compatibilty">
<para>The proposed changes convert errors into no-ops. There should be no compatibility concerns with those. </para>
</section>
<section title="Implementation">
<para>When an implementation patch is completed, it will be logged in the SF Tracker and noted here.</para>
</section>
<section title="Exclusions">
<para>Some other candidates for this treatment are intentionally left out of this proposal where for various reasons their conversion is complicated in some way, or the benefits of conversion are not as clear cut. These other commands might still be revised in a similar way, but are left for other TIPs to accomplish it so that this TIP can focus only on the low-hanging fruit.</para>
<enumerate><item.e index='1'><para><emph style="bold">after idle</emph></para></item.e><item.e index='2'><para><emph style="bold">dict exists</emph></para></item.e><item.e index='3'><para><emph style="bold">dict set d</emph> <emph style="italic">val</emph> (no <emph style="italic">key</emph> argument)</para></item.e><item.e index='4'><para><emph style="bold">dict unset d</emph> <emph style="italic">val</emph> (no <emph style="italic">key</emph> argument)</para></item.e><item.e index='5'><para><emph style="bold">dict update d</emph> <emph style="italic">script</emph> (no <emph style="italic">key varName</emph> arguments)</para></item.e><item.e index='6'><para><emph style="bold">eval</emph></para></item.e><item.e index='7'><para><emph style="bold">expr</emph></para></item.e><item.e index='8'><para><emph style="bold">file join</emph></para></item.e><item.e index='9'><para><emph style="bold">interp eval</emph></para></item.e><item.e index='10'><para><emph style="bold">namespace eval</emph></para></item.e><item.e index='11'><para><emph style="bold">parray</emph> [<url ref="https://sourceforge.net/support/tracker.php?aid=1739221"/>] This feature request is more about tolerating errors than about expanding acceptance over a complete input domain. Not in the spirit of this TIP.</para></item.e><item.e index='12'><para><emph style="bold">uplevel</emph></para></item.e><item.e index='13'><para><emph style="bold">upvar</emph> - presence of the optional <emph style="italic">level</emph> argument makes this one messy.</para></item.e></enumerate>
</section>
<section title="Epilogue">
<para>Proposed changes to <emph style="bold">string first</emph>, <emph style="bold">string last</emph>, and <emph style="bold">string replace</emph> in earlier revisions of the TIP that were approved by the vote have been rescinded after testing during the implementation phase revealed greater than expected issues with the incompatibilities those changes introduced.</para>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>

