<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0" xmlns:blogChannel="http://backend.userland.com/blogChannelModule">

<channel>
<title><![CDATA[Perl 6: Amazing Perl 6]]></title>
<link>http://www.perlfoundation.org/perl6/index.cgi?amazing_perl_6</link>
<description></description>
<pubDate>Wed, 03 Feb 2010 02:04:44 -0000</pubDate>
<webMaster>synedra@gmail.com</webMaster>
<generator>Socialtext Workspace v2.14.7.2</generator>

<item>
<title><![CDATA[Amazing Perl 6]]></title>
<link>http://www.perlfoundation.org/perl6/index.cgi?amazing_perl_6</link>
<description><![CDATA[<div class="wiki">
<p>
This page lists some amazing Perl 6 snippets. The list after the title refers to the keywords for the snippet.</p>
<h1 id="factorial">Factorial</h1>
<ul>
<li>custom operators</li>
<li>reduce operator</li>
<li>range operator</li>
<li>placeholder variable</li>
</ul>
<pre>
sub postfix:&lt;!&gt; { [*] 1..$^n }
say 5!;
</pre>
<br /><h2 id="explanation">Explanation</h2>
<h3 id="custom_operators">Custom Operators</h3>
<p>
There is a set of special sub declarations that interfere in the parsing of the language, these are the:</p>
<ul>
<li>prefix</li>
<li>postfix</li>
<li>circumfix</li>
<li>infix</li>
<li>postcircumfix</li>
</ul>
<p>
you declare them by using type:identifier, where the identifier is quoted using the '&lt;' and '&gt;', optionally « » when you want to use '&lt;' or '&gt;' as part of the identifier. Some examples of subs that come defined in Perl 6 core are:</p>
<ul>
<li>prefix:&lt;^&gt; which is the operator that turns ^100 into 0..99</li>
<li>postfix:&lt;i&gt; which allows you to use complex numbers as in 1 + 2i</li>
<li>circumfix:&lt;( )&gt; which creates a unflattened capture as in (1,2,(3,4,(5,6)))</li>
<li>infix:&lt;+&gt; which sums two values, as in 1 + 2</li>
<li>postcircumfix:&lt;{ }&gt; which is used as the hash subscript as in %a{$b}</li>
</ul>
<p>
So when you declare a sub postfix:&lt;!&gt; you are declaring a language operator that lives in the same level as any other Perl 6 operator.</p>
<h1 id="gather_take">Gather/Take</h1>
<ul>
<li>gather/take</li>
<li>lazy lists</li>
<li>bind</li>
</ul>
<pre>
my @a := gather for 1..1000 -&gt; $i { say $i; take $i };
say @a[10]; # prints 1 2 3 4 5 6 7 8 9 10
</pre>
</div>
]]></description>
<author>Flavio Poletti</author>
<guid isPermaLink="true">http://www.perlfoundation.org/perl6/index.cgi?amazing_perl_6</guid>
<pubDate>Wed, 03 Feb 2010 02:04:44 -0000</pubDate>
</item>

</channel>
</rss>