<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Day 16: We call it &#8216;the old switcheroo&#8217;</title>
	<atom:link href="http://perl6advent.wordpress.com/2009/12/16/day-16-we-call-it-the-old-switcheroo/feed/" rel="self" type="application/rss+xml" />
	<link>http://perl6advent.wordpress.com/2009/12/16/day-16-we-call-it-the-old-switcheroo/</link>
	<description>Something cool about Perl 6 every day</description>
	<lastBuildDate>Sun, 03 Feb 2013 05:15:50 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: carl</title>
		<link>http://perl6advent.wordpress.com/2009/12/16/day-16-we-call-it-the-old-switcheroo/#comment-237</link>
		<dc:creator><![CDATA[carl]]></dc:creator>
		<pubDate>Thu, 31 Dec 2009 13:12:52 +0000</pubDate>
		<guid isPermaLink="false">http://perl6advent.wordpress.com/?p=272#comment-237</guid>
		<description><![CDATA[You&#039;re right, that isn&#039;t all it is. But the &lt;code&gt;fib()&lt;/code&gt; example is not optimal to show the difference, so allow me to choose two other, clearer ones.

You want to add forty-two to every number in @numbers. So you use a &lt;code&gt;map&lt;/code&gt;, naturally. With &lt;code&gt;$_&lt;/code&gt;, it looks like this: &lt;code&gt;map { $_ + 42 }, @numbers&lt;/code&gt;; with &lt;code&gt;*&lt;/code&gt;, it looks like this: &lt;code&gt;map * + 42, @numbers&lt;/code&gt;.

From the first example, we see that &lt;code&gt;*&lt;/code&gt; is short not only for &lt;code&gt;$_&lt;/code&gt;, but also for the surrounding &lt;code&gt;{}&lt;/code&gt; block.

Now, think about what &lt;code&gt;@numbers[$_ - 5]&lt;/code&gt; means. It means &quot;the element in &lt;code&gt;@numbers&lt;/code&gt; five places before what&#039;s in &lt;code&gt;$_&lt;/code&gt;&quot;. (For the example, it doesn&#039;t much matter what &lt;code&gt;$_&lt;/code&gt; itself contains.)

Conversely, what does &lt;code&gt;@numbers[* - 5]&lt;/code&gt; mean? It means &quot;the elemens in &lt;code&gt;@numbers&lt;/code&gt; five places before *mumble-mumble*&quot;. Or, in code, &lt;code&gt;@numbers[ { $_ - 5 } ]&lt;/code&gt;. The mumbling comes from the fact that the &lt;code&gt;$_&lt;/code&gt; won&#039;t be evaluated until the block is run, and a &lt;code&gt;$_&lt;/code&gt; value is sent in as a parameter. Now, it so happens that array indexings evaluate blocks by sending in their number of elements (their &quot;length&quot;) as a parameter to the block, so the code actually comes to mean &lt;code&gt;@numbers[ @numbers - 5 ]&lt;/code&gt;, or &quot;the fifth last element in &lt;code&gt;@numbers&lt;/code&gt;&quot;.

Summing up, &lt;code&gt;*&lt;/code&gt; means not just &lt;code&gt;$_&lt;/code&gt;, but &lt;code&gt;$_&lt;/code&gt; in a code block which is possibly run at a later time, when it&#039;s more convenient, with a value of &lt;code&gt;$_&lt;/code&gt; very much decided by the surrounding context.]]></description>
		<content:encoded><![CDATA[<p>You&#8217;re right, that isn&#8217;t all it is. But the <code>fib()</code> example is not optimal to show the difference, so allow me to choose two other, clearer ones.</p>
<p>You want to add forty-two to every number in @numbers. So you use a <code>map</code>, naturally. With <code>$_</code>, it looks like this: <code>map { $_ + 42 }, @numbers</code>; with <code>*</code>, it looks like this: <code>map * + 42, @numbers</code>.</p>
<p>From the first example, we see that <code>*</code> is short not only for <code>$_</code>, but also for the surrounding <code>{}</code> block.</p>
<p>Now, think about what <code>@numbers[$_ - 5]</code> means. It means &#8220;the element in <code>@numbers</code> five places before what&#8217;s in <code>$_</code>&#8220;. (For the example, it doesn&#8217;t much matter what <code>$_</code> itself contains.)</p>
<p>Conversely, what does <code>@numbers[* - 5]</code> mean? It means &#8220;the elemens in <code>@numbers</code> five places before *mumble-mumble*&#8221;. Or, in code, <code>@numbers[ { $_ - 5 } ]</code>. The mumbling comes from the fact that the <code>$_</code> won&#8217;t be evaluated until the block is run, and a <code>$_</code> value is sent in as a parameter. Now, it so happens that array indexings evaluate blocks by sending in their number of elements (their &#8220;length&#8221;) as a parameter to the block, so the code actually comes to mean <code>@numbers[ @numbers - 5 ]</code>, or &#8220;the fifth last element in <code>@numbers</code>&#8220;.</p>
<p>Summing up, <code>*</code> means not just <code>$_</code>, but <code>$_</code> in a code block which is possibly run at a later time, when it&#8217;s more convenient, with a value of <code>$_</code> very much decided by the surrounding context.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sitaram</title>
		<link>http://perl6advent.wordpress.com/2009/12/16/day-16-we-call-it-the-old-switcheroo/#comment-236</link>
		<dc:creator><![CDATA[Sitaram]]></dc:creator>
		<pubDate>Thu, 31 Dec 2009 08:38:27 +0000</pubDate>
		<guid isPermaLink="false">http://perl6advent.wordpress.com/?p=272#comment-236</guid>
		<description><![CDATA[Could you elaborate on the &quot;*&quot;.  For example, I notice that the fib() example works even if I replace the lone &quot;*&quot; with &quot;$_&quot;.

Is &quot;*&quot; just a 50% shorter version of $_ under special cases?  I can&#039;t believe that&#039;s all it is :)]]></description>
		<content:encoded><![CDATA[<p>Could you elaborate on the &#8220;*&#8221;.  For example, I notice that the fib() example works even if I replace the lone &#8220;*&#8221; with &#8220;$_&#8221;.</p>
<p>Is &#8220;*&#8221; just a 50% shorter version of $_ under special cases?  I can&#8217;t believe that&#8217;s all it is :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carl</title>
		<link>http://perl6advent.wordpress.com/2009/12/16/day-16-we-call-it-the-old-switcheroo/#comment-210</link>
		<dc:creator><![CDATA[carl]]></dc:creator>
		<pubDate>Wed, 23 Dec 2009 16:22:59 +0000</pubDate>
		<guid isPermaLink="false">http://perl6advent.wordpress.com/?p=272#comment-210</guid>
		<description><![CDATA[VZ, I don&#039;t have the whole story of the change, but it was definitely triggered by this discussion.

Consider yourself having had a direct influence on a Perl 6 keyword!]]></description>
		<content:encoded><![CDATA[<p>VZ, I don&#8217;t have the whole story of the change, but it was definitely triggered by this discussion.</p>
<p>Consider yourself having had a direct influence on a Perl 6 keyword!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: VZ</title>
		<link>http://perl6advent.wordpress.com/2009/12/16/day-16-we-call-it-the-old-switcheroo/#comment-209</link>
		<dc:creator><![CDATA[VZ]]></dc:creator>
		<pubDate>Wed, 23 Dec 2009 12:14:53 +0000</pubDate>
		<guid isPermaLink="false">http://perl6advent.wordpress.com/?p=272#comment-209</guid>
		<description><![CDATA[I don&#039;t know if this is by some chance related to this discussion but according to http://lith-ology.blogspot.com/2009/12/seven-days-between-parrot-and-camel_22.html &quot;proceed&quot; is the new keyword replacing &quot;continue&quot; inside a when clause. This seems to be much nicer to me, thanks to whoever came up with it!]]></description>
		<content:encoded><![CDATA[<p>I don&#8217;t know if this is by some chance related to this discussion but according to <a href="http://lith-ology.blogspot.com/2009/12/seven-days-between-parrot-and-camel_22.html" rel="nofollow">http://lith-ology.blogspot.com/2009/12/seven-days-between-parrot-and-camel_22.html</a> &#8220;proceed&#8221; is the new keyword replacing &#8220;continue&#8221; inside a when clause. This seems to be much nicer to me, thanks to whoever came up with it!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carl</title>
		<link>http://perl6advent.wordpress.com/2009/12/16/day-16-we-call-it-the-old-switcheroo/#comment-169</link>
		<dc:creator><![CDATA[carl]]></dc:creator>
		<pubDate>Sat, 19 Dec 2009 12:40:04 +0000</pubDate>
		<guid isPermaLink="false">http://perl6advent.wordpress.com/?p=272#comment-169</guid>
		<description><![CDATA[Now fixed. Thanks for noticing!]]></description>
		<content:encoded><![CDATA[<p>Now fixed. Thanks for noticing!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Tötterman</title>
		<link>http://perl6advent.wordpress.com/2009/12/16/day-16-we-call-it-the-old-switcheroo/#comment-168</link>
		<dc:creator><![CDATA[Paul Tötterman]]></dc:creator>
		<pubDate>Sat, 19 Dec 2009 11:13:06 +0000</pubDate>
		<guid isPermaLink="false">http://perl6advent.wordpress.com/?p=272#comment-168</guid>
		<description><![CDATA[I think there&#039;s a typo in the fib-function. If fib(0) and fib(1) return 0, the series will never grow. They should return 1.]]></description>
		<content:encoded><![CDATA[<p>I think there&#8217;s a typo in the fib-function. If fib(0) and fib(1) return 0, the series will never grow. They should return 1.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: patch</title>
		<link>http://perl6advent.wordpress.com/2009/12/16/day-16-we-call-it-the-old-switcheroo/#comment-157</link>
		<dc:creator><![CDATA[patch]]></dc:creator>
		<pubDate>Fri, 18 Dec 2009 00:10:39 +0000</pubDate>
		<guid isPermaLink="false">http://perl6advent.wordpress.com/?p=272#comment-157</guid>
		<description><![CDATA[As carl mentioned, this can also be accomplished by passing a scalar (really a single element list) to a &lt;code&gt;for&lt;/code&gt; loop.  Here&#039;s an example in Perl 5.

&lt;pre&gt;
for ($punch_card) {
  $_-&gt;bend;
  $_-&gt;fold;
  $_-&gt;mutilate;
}
&lt;/pre&gt;

I must admit that &lt;code&gt;given&lt;/code&gt; is much clearer though, especially for those who don&#039;t know the once-only loop idiom.  I commonly use it when I need to perform several substitutions or transliterations on one string.

&lt;pre&gt;
for ($phone) {
  tr{ABC} {2};
  tr{DEF} {3};
  tr{GHI} {4};
  tr{JKL} {5};
  tr{MNO} {6};
  tr{PQRS}{7};
  tr{TUV} {8};
  tr{WXYZ}{9};
}
&lt;/pre&gt;

However, for this example we won&#039;t even need &lt;code&gt;given&lt;/code&gt; in Perl 6.

&lt;pre&gt;
$phone.=trans(
  ABC  =&gt; 2,
  DEF  =&gt; 3,
  GHI  =&gt; 4,
  JKL  =&gt; 5,
  MNO  =&gt; 6,
  PQRS =&gt; 7,
  TUV  =&gt; 8,
  WXYZ =&gt; 9,
);
&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>As carl mentioned, this can also be accomplished by passing a scalar (really a single element list) to a <code>for</code> loop.  Here&#8217;s an example in Perl 5.</p>
<pre>
for ($punch_card) {
  $_-&gt;bend;
  $_-&gt;fold;
  $_-&gt;mutilate;
}
</pre>
<p>I must admit that <code>given</code> is much clearer though, especially for those who don&#8217;t know the once-only loop idiom.  I commonly use it when I need to perform several substitutions or transliterations on one string.</p>
<pre>
for ($phone) {
  tr{ABC} {2};
  tr{DEF} {3};
  tr{GHI} {4};
  tr{JKL} {5};
  tr{MNO} {6};
  tr{PQRS}{7};
  tr{TUV} {8};
  tr{WXYZ}{9};
}
</pre>
<p>However, for this example we won&#8217;t even need <code>given</code> in Perl 6.</p>
<pre>
$phone.=trans(
  ABC  =&gt; 2,
  DEF  =&gt; 3,
  GHI  =&gt; 4,
  JKL  =&gt; 5,
  MNO  =&gt; 6,
  PQRS =&gt; 7,
  TUV  =&gt; 8,
  WXYZ =&gt; 9,
);
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Moritz</title>
		<link>http://perl6advent.wordpress.com/2009/12/16/day-16-we-call-it-the-old-switcheroo/#comment-153</link>
		<dc:creator><![CDATA[Moritz]]></dc:creator>
		<pubDate>Thu, 17 Dec 2009 09:16:14 +0000</pubDate>
		<guid isPermaLink="false">http://perl6advent.wordpress.com/?p=272#comment-153</guid>
		<description><![CDATA[I think &lt;code&gt;as&lt;/code&gt; would be pretty ambiguous, whereas &lt;code&gt;when&lt;/code&gt; clearly marks branches.

I know that &lt;code&gt;when&lt;/code&gt; is four characters, but it&#039;s very easy to type on most keyboards because first and third characters are typed with the left hand, and second and fourth with the right hand :-)]]></description>
		<content:encoded><![CDATA[<p>I think <code>as</code> would be pretty ambiguous, whereas <code>when</code> clearly marks branches.</p>
<p>I know that <code>when</code> is four characters, but it&#8217;s very easy to type on most keyboards because first and third characters are typed with the left hand, and second and fourth with the right hand :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sam</title>
		<link>http://perl6advent.wordpress.com/2009/12/16/day-16-we-call-it-the-old-switcheroo/#comment-152</link>
		<dc:creator><![CDATA[sam]]></dc:creator>
		<pubDate>Thu, 17 Dec 2009 07:32:33 +0000</pubDate>
		<guid isPermaLink="false">http://perl6advent.wordpress.com/?p=272#comment-152</guid>
		<description><![CDATA[why isn&#039;t it &#039;as&#039; instead of &#039;when&#039;? that&#039;d save you from typing 2 extra characters each time.]]></description>
		<content:encoded><![CDATA[<p>why isn&#8217;t it &#8216;as&#8217; instead of &#8216;when&#8217;? that&#8217;d save you from typing 2 extra characters each time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carl</title>
		<link>http://perl6advent.wordpress.com/2009/12/16/day-16-we-call-it-the-old-switcheroo/#comment-151</link>
		<dc:creator><![CDATA[carl]]></dc:creator>
		<pubDate>Wed, 16 Dec 2009 19:44:58 +0000</pubDate>
		<guid isPermaLink="false">http://perl6advent.wordpress.com/?p=272#comment-151</guid>
		<description><![CDATA[Yes. Yes. (Yes, unless there was a &#039;continue&#039; in the &#039;default&#039; block.)]]></description>
		<content:encoded><![CDATA[<p>Yes. Yes. (Yes, unless there was a &#8216;continue&#8217; in the &#8216;default&#8217; block.)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
