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

<TIP number='372'>
<header><title>Multi-argument Yield for Coroutines</title><author address="mailto:colin@chinix.com">Colin McCormack</author><status type='project' state='draft' tclversion="8.6" vote='after'>$Revision: 1.3 $</status><history></history><created day='11' month='aug' year='2010' /><discussions url='http://wiki.tcl.tk/26006'/><keyword>coroutine yield</keyword><obsoleted tip='396'/></header>
<abstract>This TIP proposes a command that allows a coroutine to accept multiple arguments being passed in on return from yield.</abstract>
<body><section title="Rationale">
<para>The coroutine mechanism of <tipref type="text" tip="328"/> has given Tcl 8.6 a new primitive which permits light-weight mulitasking. The mechanism as specified by <tipref type="text" tip="328"/> lacks the ability to emulate general-purpose procedural invocation through the arbitrary limitation of coroutine calls to a single argument (except on the initial call).</para>
<para>The ability of coroutines to emulate general-purpose procedural invocation is of great utility, the lack of which leads to stilted verbiage, and diverges unnecessarily from Tcl&apos;s other functionals.</para>
<para>The <emph style="bold">yieldm</emph> command, as currently implemented by <emph style="bold">::tcl::unsupported::yieldm</emph>, extends coroutines to permit general emulation, and it is the proposal of this TIP that yieldm be moved to the global namespace, or such other namespaces as may be used for coroutine functionality in the future.</para>
</section>
<section title="Syntax and Semantics of yieldm">
<quote><emph style="bold">yieldm</emph> ?<emph style="italic">value</emph>?</quote>
<para>This is just like <emph style="bold">yield</emph>, except that it causes the coroutine command to accept arbitrarily many arguments and will return the list of those arguments (i.e., an empty list if there are no arguments, a single-element list if there is one, a pair for two, etc.)</para>
</section>
<section title="Detailed Rationale">

<subsection title="Utility">
<para>Restatement-in-summary of the arguments in <url ref="http://wiki.tcl.tk/26006:"/></para>
<enumerate><item.e index='1'><para>Coroutines should be able to simulate any command, not just any single-arg&apos;d command. [Argument: generality]</para></item.e><item.e index='2'><para>To implement single-arg&apos;s coroutines in multi-arg&apos;d coroutines is trivial - nothing needs to be done. The converse (implementing multi-arg&apos;d coroutines under coroutine is inefficient and difficult. [Argument: increased expressive power]</para></item.e><item.e index='3'><para>There is no sound reason that the invocation of a coroutine should not resemble that of any other command. [Argument: principle of minimal surprise]</para></item.e><item.e index='4'><para>It is impossible to construct forms like <emph style="bold">interp alias</emph> to address a coroutine in the common case that the caller is expecting to pass more than one argument.</para></item.e></enumerate>
</subsection>
<subsection title="Consistency">
<para>Restatement-in-summary of the arguments in <url ref="http://wiki.tcl.tk/26056:"/></para>
<para>The following commands create new commands: <emph style="bold">proc</emph>, <emph style="bold">coroutine</emph>, <emph style="bold">namespace ensemble</emph>, <emph style="bold">class create</emph>, <emph style="italic">$cls</emph> <emph style="bold">create</emph>, <emph style="bold">interp alias</emph>, <emph style="bold">interp create</emph>, <emph style="bold">::thread::create</emph>, <emph style="bold">apply</emph>.</para>
<para>In each case except <emph style="bold">coroutine</emph>, the created command permits multiple arguments (arguably this being a key feature of Tcl in practice). There is no sound reason for this disparity, and for consistency the disparity should be removed, which the proposed <emph style="bold">yieldm</emph> does.</para>
</subsection>
</section>
<section title="Implementation">
<para>Simply rename the <emph style="bold">::tcl::unsupported::yieldm</emph> into the global namespace, and extend the coroutine documentation to refer to the new command.</para>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>
