<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Reverse Currying</title>
	<atom:link href="http://jacksondunstan.com/articles/371/feed" rel="self" type="application/rss+xml" />
	<link>http://jacksondunstan.com/articles/371</link>
	<description>Mastering AS3</description>
	<lastBuildDate>Tue, 07 Feb 2012 09:30:08 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: jackson</title>
		<link>http://jacksondunstan.com/articles/371/comment-page-1#comment-250</link>
		<dc:creator>jackson</dc:creator>
		<pubDate>Fri, 09 Oct 2009 17:13:47 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=371#comment-250</guid>
		<description>Optional parameters can go two ways. Consider this function:

&lt;pre lang=&quot;actionscript3&quot;&gt;
function foo(required:String, optional:String=&quot;n/a&quot;): void
{
        trace(required + &quot;, &quot; + optional);
}
&lt;/pre&gt;

If you use set &lt;tt&gt;numArgs&lt;/tt&gt; to 1, only one argument will be passed and &lt;tt&gt;optional&lt;/tt&gt; will be defaulted to &quot;n/a&quot;. If you set &lt;tt&gt;numArgs&lt;/tt&gt; to 2 but only pass one argument, &lt;tt&gt;optional&lt;/tt&gt; will not be defaulted but instead set to what you passed: undefined (although this will be converted to null as Strings cannot be undefined). If you set &lt;tt&gt;numArgs&lt;/tt&gt; to 2 and actually pass two arguments, it will be as though you simply called the function with those two arguments. If you set &lt;tt&gt;numArgs&lt;/tt&gt; higher than 2, you will get a runtime error (the same one as in the article) for passing too many parameters.

This last case is the subject of your second question and is answered in the comment for the &lt;tt&gt;reverse()&lt;/tt&gt; function:

&lt;pre lang=&quot;text&quot;&gt;
        *   @param numArgs Number of arguments to allow through to the function.
        *                 This can be used to increase the number of arguments
        *                 passed to the function, but all arguments beyond
        *                 those actually passed will be undefined. 
&lt;/pre&gt;

The reason for this is that there isn&#039;t a convenient way for &lt;tt&gt;reverse()&lt;/tt&gt; to protect against passing too many parameters since it does not know how many parameters the function takes. There may be some (very slow) way of finding this out, such as &lt;a href=&quot;http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/utils/package.html#describeType()&quot; rel=&quot;nofollow&quot;&gt;describeType()&lt;/a&gt;, but I&#039;d rather not add such tremendous overhead to the function.

Thanks for the comment. It&#039;s good to fully explore the details of using such a function. I hope you find it useful.</description>
		<content:encoded><![CDATA[<p>Optional parameters can go two ways. Consider this function:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #339966; font-weight: bold;">function</span> foo<span style="color: #000000;">&#40;</span>required<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> optional<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span>=<span style="color: #990000;">&quot;n/a&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
        <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>required <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;, &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> optional<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>If you use set <tt>numArgs</tt> to 1, only one argument will be passed and <tt>optional</tt> will be defaulted to &#8220;n/a&#8221;. If you set <tt>numArgs</tt> to 2 but only pass one argument, <tt>optional</tt> will not be defaulted but instead set to what you passed: undefined (although this will be converted to null as Strings cannot be undefined). If you set <tt>numArgs</tt> to 2 and actually pass two arguments, it will be as though you simply called the function with those two arguments. If you set <tt>numArgs</tt> higher than 2, you will get a runtime error (the same one as in the article) for passing too many parameters.</p>
<p>This last case is the subject of your second question and is answered in the comment for the <tt>reverse()</tt> function:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">        *   @param numArgs Number of arguments to allow through to the function.
        *                 This can be used to increase the number of arguments
        *                 passed to the function, but all arguments beyond
        *                 those actually passed will be undefined.</pre></div></div>

<p>The reason for this is that there isn&#8217;t a convenient way for <tt>reverse()</tt> to protect against passing too many parameters since it does not know how many parameters the function takes. There may be some (very slow) way of finding this out, such as <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/utils/package.html#describeType()" rel="nofollow">describeType()</a>, but I&#8217;d rather not add such tremendous overhead to the function.</p>
<p>Thanks for the comment. It&#8217;s good to fully explore the details of using such a function. I hope you find it useful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jonathan</title>
		<link>http://jacksondunstan.com/articles/371/comment-page-1#comment-249</link>
		<dc:creator>jonathan</dc:creator>
		<pubDate>Fri, 09 Oct 2009 10:16:42 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=371#comment-249</guid>
		<description>What about optional parameters ?

your (args.length = numArgs;) can be greater than the number of given parameters, is not a problem ?</description>
		<content:encoded><![CDATA[<p>What about optional parameters ?</p>
<p>your (args.length = numArgs;) can be greater than the number of given parameters, is not a problem ?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

