<?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: AS3 Inconsistency &#8211; Unable To Use &#8230;(rest) Keyword in Setter</title>
	<atom:link href="http://www.techper.net/2008/07/22/as3-inconsistency-unable-to-use-rest-keyword-in-setter/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.techper.net/2008/07/22/as3-inconsistency-unable-to-use-rest-keyword-in-setter/</link>
	<description>About Technology in My Life</description>
	<lastBuildDate>Thu, 11 Mar 2010 05:52:37 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: polesen</title>
		<link>http://www.techper.net/2008/07/22/as3-inconsistency-unable-to-use-rest-keyword-in-setter/comment-page-1/#comment-1518</link>
		<dc:creator>polesen</dc:creator>
		<pubDate>Thu, 24 Jul 2008 07:20:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=78#comment-1518</guid>
		<description>@Darren: I seems you are right. I just had an understanding of the set/get properties as just being syntactic sugar, that made the compiler generate actual methods for set and getters, and then convert calls like

&lt;code&gt;
  task.tags = foo
&lt;/code&gt;

into 

&lt;code&gt;
  task.setter_tags(foo)
&lt;/code&gt;

But hey, I guess they are more special than that then.</description>
		<content:encoded><![CDATA[<p>@Darren: I seems you are right. I just had an understanding of the set/get properties as just being syntactic sugar, that made the compiler generate actual methods for set and getters, and then convert calls like</p>
<p><code><br />
  task.tags = foo<br />
</code></p>
<p>into </p>
<p><code><br />
  task.setter_tags(foo)<br />
</code></p>
<p>But hey, I guess they are more special than that then.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darren</title>
		<link>http://www.techper.net/2008/07/22/as3-inconsistency-unable-to-use-rest-keyword-in-setter/comment-page-1/#comment-1507</link>
		<dc:creator>Darren</dc:creator>
		<pubDate>Wed, 23 Jul 2008 23:45:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=78#comment-1507</guid>
		<description>I think the Flex compiler is right here. It&#039;s not necessary for the Flex compiler to put in a special check to see that &quot;...rest&quot; is not used as a parameter in a setter because the default behaviour is just to treat it as a normal array - without the normal &quot;...rest&quot; qualities because of the unique nature of setter functions - and catch your error if you try to present it with something else. You seem to be complaining because in this particular case, the compiler won&#039;t do an automatic type conversion for you but it shouldn&#039;t because setters don&#039;t do this - just as it shouldn&#039;t if you had written &quot;var arr:Array = &quot;some_string&quot;. Is it really that surprising that a setter function handles a special type of parameter - which you shouldn&#039;t have given it in the first place because it makes no sense in this context - in a way that you didn&#039;t expect? For your use case, the setTags method is the appropriate solution, not a setter function. In an ideal world, the compiler would issue a warning when you use the &quot;...rest&quot; parameter in a setter but I&#039;m personally comfortable that it&#039;s not slowed down looking for particular use cases like this when an error will be thrown if you use it incorrectly anyway.</description>
		<content:encoded><![CDATA[<p>I think the Flex compiler is right here. It&#8217;s not necessary for the Flex compiler to put in a special check to see that &#8220;&#8230;rest&#8221; is not used as a parameter in a setter because the default behaviour is just to treat it as a normal array &#8211; without the normal &#8220;&#8230;rest&#8221; qualities because of the unique nature of setter functions &#8211; and catch your error if you try to present it with something else. You seem to be complaining because in this particular case, the compiler won&#8217;t do an automatic type conversion for you but it shouldn&#8217;t because setters don&#8217;t do this &#8211; just as it shouldn&#8217;t if you had written &#8220;var arr:Array = &#8220;some_string&#8221;. Is it really that surprising that a setter function handles a special type of parameter &#8211; which you shouldn&#8217;t have given it in the first place because it makes no sense in this context &#8211; in a way that you didn&#8217;t expect? For your use case, the setTags method is the appropriate solution, not a setter function. In an ideal world, the compiler would issue a warning when you use the &#8220;&#8230;rest&#8221; parameter in a setter but I&#8217;m personally comfortable that it&#8217;s not slowed down looking for particular use cases like this when an error will be thrown if you use it incorrectly anyway.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: polesen</title>
		<link>http://www.techper.net/2008/07/22/as3-inconsistency-unable-to-use-rest-keyword-in-setter/comment-page-1/#comment-1485</link>
		<dc:creator>polesen</dc:creator>
		<pubDate>Wed, 23 Jul 2008 07:15:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=78#comment-1485</guid>
		<description>Thanks for all the comments.

@Alex: The &quot;dude, car&quot; string is &lt;em&gt;not&lt;/em&gt; a try from me, to pass to strings into the setter. This is just the example here. And no, I would not expect &lt;tt&gt;task.tags = &quot;foo&quot;, 1, [&quot;foo&quot;,&quot;bar&quot;]&lt;/tt&gt; to work. I would expect it to convert my single string var into a one element array.

@Ash: At times, I am not sure myself, what I want to achive :)

@Senocular:

&lt;blockquote&gt;
However, where you can pass any number of arguments to a function call, you can only use one value in an assignment. There’s no way to do something like

target.tags = value, value1, valueN;
&lt;/blockquote&gt;

If there is no way to pass any number of arguments to a setter, why does the setter with ...rest then compile?

I would not expect &lt;tt&gt;target.tags = value, value1, valueN;&lt;/tt&gt; to work, but, given that the setter compiles, I would at least expect &lt;tt&gt;target.tags = value;&lt;/tt&gt; to work.

@Jake: EXACTLY! :-)</description>
		<content:encoded><![CDATA[<p>Thanks for all the comments.</p>
<p>@Alex: The &#8220;dude, car&#8221; string is <em>not</em> a try from me, to pass to strings into the setter. This is just the example here. And no, I would not expect <tt>task.tags = "foo", 1, ["foo","bar"]</tt> to work. I would expect it to convert my single string var into a one element array.</p>
<p>@Ash: At times, I am not sure myself, what I want to achive <img src='http://www.techper.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>@Senocular:</p>
<blockquote><p>
However, where you can pass any number of arguments to a function call, you can only use one value in an assignment. There’s no way to do something like</p>
<p>target.tags = value, value1, valueN;
</p></blockquote>
<p>If there is no way to pass any number of arguments to a setter, why does the setter with &#8230;rest then compile?</p>
<p>I would not expect <tt>target.tags = value, value1, valueN;</tt> to work, but, given that the setter compiles, I would at least expect <tt>target.tags = value;</tt> to work.</p>
<p>@Jake: EXACTLY! <img src='http://www.techper.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jake</title>
		<link>http://www.techper.net/2008/07/22/as3-inconsistency-unable-to-use-rest-keyword-in-setter/comment-page-1/#comment-1483</link>
		<dc:creator>Jake</dc:creator>
		<pubDate>Wed, 23 Jul 2008 03:06:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=78#comment-1483</guid>
		<description>I think the inconsistency lies in the fact that the compiler allows using &#039;...&#039; in a set method. varargs don&#039;t make much sense in the context of properties (a property is singular by nature).</description>
		<content:encoded><![CDATA[<p>I think the inconsistency lies in the fact that the compiler allows using &#8216;&#8230;&#8217; in a set method. varargs don&#8217;t make much sense in the context of properties (a property is singular by nature).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: zwetan</title>
		<link>http://www.techper.net/2008/07/22/as3-inconsistency-unable-to-use-rest-keyword-in-setter/comment-page-1/#comment-1481</link>
		<dc:creator>zwetan</dc:creator>
		<pubDate>Wed, 23 Jul 2008 00:29:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=78#comment-1481</guid>
		<description>nope it&#039;s not an AS3 inconsistency and it&#039;s certainly not a bug

you try to do something that make no sens

the rest parametter allow you to pass multi arguments to a function

function foobar( ...args )

foobar( 0, 1, 2, 3 ); // args = [0,1,2,3]

put this make no sens for a setter

function set foobar( ...args )

obj.foobar = &quot;you can pass only one argument here&quot;;

wen you try to do that
---
var myTags : String = &quot;dude, car&quot;;  
var task : Task = new Task();  
task.tags = myTags; //here your arg is not magically put into an array
---

so when you try to do that
for each (var tag : Object in tags)

you trying to do that on a String, not an Array
hence the implicit coercion error


I guess what you want is

public function set tags(tags:Array) : void

and

var myTags : String = &quot;dude,car&quot;;  
var task : Task = new Task();  
task.tags = myTags.split(&quot;,&quot;);

or

var myTags : Array = [&quot;dude&quot;,&quot;car&quot;];  
var task : Task = new Task();  
task.tags = myTags;</description>
		<content:encoded><![CDATA[<p>nope it&#8217;s not an AS3 inconsistency and it&#8217;s certainly not a bug</p>
<p>you try to do something that make no sens</p>
<p>the rest parametter allow you to pass multi arguments to a function</p>
<p>function foobar( &#8230;args )</p>
<p>foobar( 0, 1, 2, 3 ); // args = [0,1,2,3]</p>
<p>put this make no sens for a setter</p>
<p>function set foobar( &#8230;args )</p>
<p>obj.foobar = &#8220;you can pass only one argument here&#8221;;</p>
<p>wen you try to do that<br />
&#8212;<br />
var myTags : String = &#8220;dude, car&#8221;;<br />
var task : Task = new Task();<br />
task.tags = myTags; //here your arg is not magically put into an array<br />
&#8212;</p>
<p>so when you try to do that<br />
for each (var tag : Object in tags)</p>
<p>you trying to do that on a String, not an Array<br />
hence the implicit coercion error</p>
<p>I guess what you want is</p>
<p>public function set tags(tags:Array) : void</p>
<p>and</p>
<p>var myTags : String = &#8220;dude,car&#8221;;<br />
var task : Task = new Task();<br />
task.tags = myTags.split(&#8221;,&#8221;);</p>
<p>or</p>
<p>var myTags : Array = ["dude","car"];<br />
var task : Task = new Task();<br />
task.tags = myTags;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex Bustin</title>
		<link>http://www.techper.net/2008/07/22/as3-inconsistency-unable-to-use-rest-keyword-in-setter/comment-page-1/#comment-1480</link>
		<dc:creator>Alex Bustin</dc:creator>
		<pubDate>Wed, 23 Jul 2008 00:22:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=78#comment-1480</guid>
		<description>Can&#039;t you just do this... ?????

public function set tags(value:String) : void { 
      var tags:Array = value.split(&quot;,&quot;);
      .......
}

 …(rest) is of the Array type, so ActionScript is right to assume that you want to set an Array.  

Getters and setters have to be matching in type.  If you&#039;re passing in a String to the setter, the getter would return a String. I know you haven&#039;t implemented a matching getter and thats OK, but if you had, it would of had to of returned an Array to match the setter.

Your second block of code works because you&#039;re using 
 …(rest) correctly.  But your implementation is buggy, your myTags string will never be automatically split at the comma in ActionScript. So in the  setTags method, your newtags Array will always contain only one String element.  Passing the newtags Array to this.tags works because this.tags is expecting an Array. Before you were trying to pass a String.

To use setTags correctly, you would say ...

setTags(&quot;foo&quot;, &quot;bar&quot;, &quot;bob&quot;);</description>
		<content:encoded><![CDATA[<p>Can&#8217;t you just do this&#8230; ?????</p>
<p>public function set tags(value:String) : void {<br />
      var tags:Array = value.split(&#8221;,&#8221;);<br />
      &#8230;&#8230;.<br />
}</p>
<p> …(rest) is of the Array type, so ActionScript is right to assume that you want to set an Array.  </p>
<p>Getters and setters have to be matching in type.  If you&#8217;re passing in a String to the setter, the getter would return a String. I know you haven&#8217;t implemented a matching getter and thats OK, but if you had, it would of had to of returned an Array to match the setter.</p>
<p>Your second block of code works because you&#8217;re using<br />
 …(rest) correctly.  But your implementation is buggy, your myTags string will never be automatically split at the comma in ActionScript. So in the  setTags method, your newtags Array will always contain only one String element.  Passing the newtags Array to this.tags works because this.tags is expecting an Array. Before you were trying to pass a String.</p>
<p>To use setTags correctly, you would say &#8230;</p>
<p>setTags(&#8221;foo&#8221;, &#8220;bar&#8221;, &#8220;bob&#8221;);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: senocular</title>
		<link>http://www.techper.net/2008/07/22/as3-inconsistency-unable-to-use-rest-keyword-in-setter/comment-page-1/#comment-1479</link>
		<dc:creator>senocular</dc:creator>
		<pubDate>Tue, 22 Jul 2008 23:47:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=78#comment-1479</guid>
		<description>This is as designed.  You can&#039;t use = to assign more than one value to any given target.  Setters are defined in a way that let you create variables that convert = into a method call.  So what may have been:

target.setTags(value);

can instead be

target.tags = value;

However, where you can pass any number of arguments to a function call, you can only use one value in an assignment.  There&#039;s no way to do something like

target.tags = value, value1, valueN;

The closest thing you have to that is assigning an array at which point you&#039;re then back to dealing with one object (where the setter would be defined with one parameter of the type Array).</description>
		<content:encoded><![CDATA[<p>This is as designed.  You can&#8217;t use = to assign more than one value to any given target.  Setters are defined in a way that let you create variables that convert = into a method call.  So what may have been:</p>
<p>target.setTags(value);</p>
<p>can instead be</p>
<p>target.tags = value;</p>
<p>However, where you can pass any number of arguments to a function call, you can only use one value in an assignment.  There&#8217;s no way to do something like</p>
<p>target.tags = value, value1, valueN;</p>
<p>The closest thing you have to that is assigning an array at which point you&#8217;re then back to dealing with one object (where the setter would be defined with one parameter of the type Array).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ash</title>
		<link>http://www.techper.net/2008/07/22/as3-inconsistency-unable-to-use-rest-keyword-in-setter/comment-page-1/#comment-1478</link>
		<dc:creator>Ash</dc:creator>
		<pubDate>Tue, 22 Jul 2008 23:38:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=78#comment-1478</guid>
		<description>I&#039;m not sure what you&#039;re trying to achieve here.. A setter takes one argument by definition, rather than a list of arguments. How would you intend to pass a list of arguments to your setter?
myProperty = 1, 2, 3?

In that case you would just pass an array:
myProperty = [1, 2, 3];

and the argument for your setter would be of type Array.

Otherwise you would just use a regular method, as in your last example :)</description>
		<content:encoded><![CDATA[<p>I&#8217;m not sure what you&#8217;re trying to achieve here.. A setter takes one argument by definition, rather than a list of arguments. How would you intend to pass a list of arguments to your setter?<br />
myProperty = 1, 2, 3?</p>
<p>In that case you would just pass an array:<br />
myProperty = [1, 2, 3];</p>
<p>and the argument for your setter would be of type Array.</p>
<p>Otherwise you would just use a regular method, as in your last example <img src='http://www.techper.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.techper.net/2008/07/22/as3-inconsistency-unable-to-use-rest-keyword-in-setter/comment-page-1/#comment-1477</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Tue, 22 Jul 2008 22:54:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=78#comment-1477</guid>
		<description>when using ...rest on a method call you wouldn&#039;t put &quot;&quot; around the parameters. In the examples above I see &quot;&quot;, which suggest just one argument. Would you expected a syntax like this to work?

task.tags = &quot;foo&quot;, 1, [&quot;foo&quot;,&quot;bar&quot;];</description>
		<content:encoded><![CDATA[<p>when using &#8230;rest on a method call you wouldn&#8217;t put &#8220;&#8221; around the parameters. In the examples above I see &#8220;&#8221;, which suggest just one argument. Would you expected a syntax like this to work?</p>
<p>task.tags = &#8220;foo&#8221;, 1, ["foo","bar"];</p>
]]></content:encoded>
	</item>
</channel>
</rss>
