<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<!-- name="generator" content="blosxom/2.0" -->
<channel  rdf:about="http://perlgeek.de/blog-en/">
    <title>Perlgeek.de   </title>
    <link>http://perlgeek.de/blog-en/</link>
    <description>Perl and Programming Blog.</description>
</channel>

  <item rdf:about="http://perlgeek.de/blog-en/perl-6/2012-sqlite-in-dbiish.html">
 <title>SQLite support for DBIish</title>
  <link>http://perlgeek.de/blog-en/perl-6/2012-sqlite-in-dbiish.html</link>
 <author>Moritz Lenz</author>
   <pubDate>Thu, May  3 11:02:47 2012</pubDate>
    <description>&lt;!-- 1336035767 --&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/perl6/DBIish/&quot;&gt;DBIish&lt;/a&gt;, the new database
interface for Rakudo Perl 6, now has a working SQLite backend. It uses
prepared statements and placeholders, and supports standard CRUD
operations.&lt;/p&gt;

&lt;p&gt;Previously the SQLite driver would randomly report &quot;Malformed UTF-8 string&quot;
or segfault, but usually worked pretty well when run under valgrind. The
problem turned out to be a mismatch between the caller's and the callee's
ideas about memory management.&lt;/p&gt;

&lt;p&gt;In particular, parrot's garbage collector would deallocate strings passed
to &lt;a href=&quot;http://www.sqlite.org/c3ref/bind_blob.html&quot;&gt;sqlite3_bind_text&lt;/a&gt;
after the call was done, but sqlite wants such values to stay around until
the next call to &lt;a
href=&quot;http://www.sqlite.org/c3ref/step.html&quot;&gt;sqlite3_step&lt;/a&gt; in the very
least.&lt;/p&gt;

&lt;p&gt;Fixing this mismatch was enabled &lt;a
    href=&quot;https://github.com/jnthn/zavolaj/commit/e94f45ca4dd5df3010ecb84051980f506e3cbe6d&quot;&gt;by
this patch&lt;/a&gt;, which lets you mark strings as explicitly managed. Such
strings keep their marshalled C string equivalent around until they are
garbage-collected themselves. So now &lt;a
    href=&quot;https://github.com/perl6/DBIish/commit/9b339432405228a895c76bf1193bdba3f935b99b&quot;&gt;the
sqlite driver keeps a copy of the strings&lt;/a&gt; as long as necessary, and the SQLite
tests pass reliably.&lt;/p&gt;

&lt;p&gt;Currently it still needs the &lt;code&gt;cstr&lt;/code&gt; branches in the nqp and
zavolaj repositories, but they will be merged soon -- certainly before the May
release of Rakudo.&lt;/p&gt;


</description>
  </item>
  <item rdf:about="http://perlgeek.de/blog-en/perl-6/2012-dbiish.html">
 <title>Meet DBIish, a Perl 6 Database Interface</title>
  <link>http://perlgeek.de/blog-en/perl-6/2012-dbiish.html</link>
 <author>Moritz Lenz</author>
   <pubDate>Sat, Apr 28 12:03:10 2012</pubDate>
    <description>&lt;!-- 1335607390 --&gt;

&lt;p&gt;In the aftermath of the Oslo Perl 6 hackathon 2012, I have decided to fork
and rename MiniDBI. MiniDBI is intended as a compatible port of Perl 5's
excellent DBI module to Perl 6. While working on the MiniDBI backends, I
noticed that I became more and more unhappy with that. Perl 6 is sufficiently
different from Perl 5 to warrant different design decisions in the database
interface layer.&lt;/p&gt;

&lt;p&gt;Meet &lt;a href=&quot;https://github.com/perl6/DBIish/&quot;&gt;DBIish&lt;/a&gt;. It started with
MiniDBI's code base, but has some substantial deviations from MiniDBI:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;Connection information is passed by named arguments to the driver
    (instead of a single DSN string)&lt;/li&gt;
    &lt;li&gt;Different naming of several methods. There's not much point in having
    both &lt;code&gt;fetchrow_array&lt;/code&gt; and &lt;code&gt;fetchrow_arrayref&lt;/code&gt; in
    Rakudo. &lt;code&gt;fetchrow&lt;/code&gt; simply returns an array or a list, and the
    caller decides what to do with it.&lt;/li&gt;
    &lt;li&gt;Backends only need to implement &lt;code&gt;fetchrow&lt;/code&gt; and
    &lt;code&gt;column_names&lt;/code&gt;, and get all the other fetching methods (like
    &lt;code&gt;fetchrow-hash&lt;/code&gt;, &lt;code&gt;fetchall-hash&lt;/code&gt;) for free.&lt;/li&gt;
    &lt;li&gt;Error handling from DB connection and statement handle are unified
    into a single row&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The latter two changes brought quite a reduction in backend code size.&lt;/p&gt;

&lt;p&gt;My plans for the future include experimenting with different names and
maybe totally different APIs. When a language has lazy lists, one can simply
return all rows lazily, instead of encouraging the user to fetch the rows one
by one.&lt;/p&gt;

&lt;p&gt;Currently the Postgresql and mysql backends support basic CRUD operations,
Postgresql with proper prepared statements and placeholders. An SQLite backend
is under way, but still needs better support from our native call interface.&lt;/p&gt;


</description>
  </item>
  <item rdf:about="http://perlgeek.de/blog-en/perl-6/2012-oslo-hackathon-rest.html">
 <title>Perl 6 Hackathon in Oslo: Report From The Second Day</title>
  <link>http://perlgeek.de/blog-en/perl-6/2012-oslo-hackathon-rest.html</link>
 <author>Moritz Lenz</author>
   <pubDate>Mon, Apr 23 09:24:30 2012</pubDate>
    <description>&lt;!-- 1335165870 --&gt;

&lt;p&gt;Second day of the &lt;a href=&quot;https://gist.github.com/1711730&quot;&gt;Perl 6 Patterns
Hackathon&lt;/a&gt;. My plans to get the rest of placeholders and prepared
statements working in the Postgresql backend for MiniDBI succeed about 10
minutes after midnight. I just wanted to give them a very quick try before
going to bed, and was successful. Then I went to sleep.&lt;/p&gt;

&lt;p&gt;It was night, and it was morning. Second day.&lt;/p&gt;

&lt;p&gt;Next I wrote an SQLite backend for MiniDBI. It blocked on missing features
in our native call infrastructure, on which arnsholt worked in parallel. So I
haven't had a chance to try the SQLite backend yet. It probably requires some
substantial amount of work before it will run, but at least it compiles.&lt;/p&gt;

&lt;p&gt;I also investigated prepared statements and placeholders for the mysql
backend. This is much less straight forward, because it requires filling in
members of structs, not just function calls. This by itself wouldn't be much a
problem, our native call infrastructure supports that. The problem is that
it's a struct of mixed &quot;private&quot; and &quot;public&quot; members, so modelling the
structure in Perl 6 requires modeling private data of the mysql client
library. While possible, I don't find it desirable, because it is rather
fragile.&lt;/p&gt;

&lt;p&gt;Another notable event was the hacking dojo, where about 8 of us
collaborated to write a roman numeral conversion, using pair programming, and
fixed cycles of first writing a failing test, then getting it to run in the
simplest possible way, and finally refactoring it. It was quite an interesting
and fun experience.&lt;/p&gt;

&lt;p&gt;I spent much of the rest of the hackathon discussing things. For example
Patrick Michaud gave a quick walk through of how lists and related types are
implemented and iterated in Rakudo.&lt;/p&gt;

&lt;p&gt;In the evening we had very tasty Vietnamese food, and generally a good
time.&lt;/p&gt;

&lt;p&gt;Again it was a very productive and enjoyable day, and I'm very grateful for
being invited to the Hackathon.&lt;/p&gt;



</description>
  </item>
  <item rdf:about="http://perlgeek.de/blog-en/perl-6/2012-oslo-hackathon-report.html">
 <title>Perl 6 Hackathon in Oslo: Report From The First Day</title>
  <link>http://perlgeek.de/blog-en/perl-6/2012-oslo-hackathon-report.html</link>
 <author>Moritz Lenz</author>
   <pubDate>Sat, Apr 21 22:10:48 2012</pubDate>
    <description>&lt;!-- 1335039048 --&gt;

&lt;p&gt;Yesterday I arrived in the beautiful city of Oslo to attend the &lt;a
href=&quot;https://gist.github.com/1711730&quot;&gt;Perl 6 Patterns Hackathon&lt;/a&gt;.
Yesterday we visited a pub, had great discussions, food and beverages, and
generally a very good time.&lt;/p&gt;

&lt;p&gt;Today we met at 10 am, and got straight to hacking. We are located in an
office in the 6th floor of a big building, with a nice view over the center of
town, harbor, and even the Holmenkollen.&lt;/p&gt;

&lt;p&gt;I worked on the backtrace printer, which in alarmingly many cases reported
&lt;code&gt;Error while creating error string: Method 'message' not found for
invocant of class 'Any'&lt;/code&gt;, which wasn't too helpful.&lt;/p&gt;

&lt;p&gt;It turns out there were actually two causes. One was a subtle error in the
backtrace printer that was triggered by &lt;a
    href=&quot;https://github.com/rakudo/rakudo/commit/6ef66c9521b14f33ded88c3da8569032488d2442&quot;&gt;stricter
    implementation of the specification&lt;/a&gt;, which was easy to find. The
second bug was harder to find, considering that you don't get easily get
backtraces from errors within the backtrace printer. In the end it was the
usage of a code object in boolean context, which turned out to be harmful.
Because regexes are also code objects, and in boolean context they search for
the outer &lt;code&gt;$_&lt;/code&gt; variable and try to match the regex against it.
Which failed. Hard to find, but easy to fix.&lt;/p&gt;

&lt;p&gt;My second big project today was database connectivity. Part of it was
pestering Jonathan to fix the issues that arose from module precompilation
mixed with calling C modules, and testing all the iterations he produced. I'm
happy to report that it now works fine, which speeds up development quite a
bit.&lt;/p&gt;

&lt;p&gt;I also fixed the postgres driver. The root cause for the failing tests
turned out to be rather simple too (a missing initialization), so simple that
it's embarrassing how long it took me to find out. On the plus side I improved
the code quite a bit in passing.&lt;/p&gt;

&lt;p&gt;So now all tests in &lt;a
href=&quot;https://github.com/mberends/MiniDBI&quot;&gt;MiniDBI&lt;/a&gt; pass, which is a nice
milestone, and an indication that we need more tests.&lt;/p&gt;

&lt;p&gt;Tomorrow I plan to change the postgres driver to use proper prepared
statments.&lt;/p&gt;

&lt;p&gt;But the real value of such hackathon comes from interacting with the other
hackers. I'm very happy about lots of discussions with other core hackers, as
well as feedback and patches from new users and hackers.&lt;/p&gt;

&lt;p&gt;At this occasion I'd also like to thank the organizers, Salve J. Nilsen,
Karl Rune Nilsen and Jan Ingvoldstad. It has been a great event so far, both fun and productive. You are
doing a great service to the Perl 6 community, and to the hackers you have
invited.&lt;/p&gt;



</description>
  </item>
  <item rdf:about="http://perlgeek.de/blog-en/perl-6/2012-rakudo-hack-dynamic-export-lists.html">
 <title>Rakudo Hack: Dynamic Export Lists</title>
  <link>http://perlgeek.de/blog-en/perl-6/2012-rakudo-hack-dynamic-export-lists.html</link>
 <author>Moritz Lenz</author>
   <pubDate>Thu, Apr 12 20:59:43 2012</pubDate>
    <description>&lt;!-- 1334257183 --&gt;

&lt;p&gt;Rakudo's meta programming capabilities are very good when it comes to
objects, classes and methods. But sometimes people want to generate
subroutines on the fly and use them, and can't seem to find a way to do
it.&lt;/p&gt;

&lt;p&gt;The problem is that subroutines are usually stored (and looked up from) in
the lexical pad (ie the same as &lt;code&gt;my&lt;/code&gt;-variables), and those lexpads
are immutable at run time.&lt;/p&gt;

&lt;p&gt;Today I found a solution that lets you dynamically install subroutines with
a computed name into a module, and you can then &lt;code&gt;use&lt;/code&gt; that module
from elsewhere, and have all the generated subroutines available.&lt;/p&gt;

&lt;pre&gt;
&lt;span class=&quot;synStatement&quot;&gt;module&lt;/span&gt; A {
    &lt;span class=&quot;synPreProc&quot;&gt;BEGIN&lt;/span&gt; {
        &lt;span class=&quot;synSpecial&quot;&gt;my&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;$name&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synSpecial&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;synSpecial&quot;&gt;my&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;$x&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;sub&lt;/span&gt; { &lt;span class=&quot;synIdentifier&quot;&gt;say&lt;/span&gt; &lt;span class=&quot;synSpecial&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;OH HAI from &amp;amp;foo&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;'&lt;/span&gt; }
                &lt;span class=&quot;synPreProc&quot;&gt;but&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;role&lt;/span&gt; { &lt;span class=&quot;synStatement&quot;&gt;method&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;name&lt;/span&gt; { &lt;span class=&quot;synIdentifier&quot;&gt;$name&lt;/span&gt; } }&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
        trait_mod&lt;span class=&quot;synStatement&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;is&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;&amp;gt;&lt;/span&gt;(&lt;span class=&quot;synStatement&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;export&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;$x&lt;/span&gt;)&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
    }
}
&lt;/pre&gt;

&lt;p&gt;Inside the module first we need a &lt;code&gt;BEGIN&lt;/code&gt; block, so that the
&lt;code&gt;is export&lt;/code&gt; trait will run while the module is being compiled, and
thus knows which module to associate the subroutine to.&lt;/p&gt;

&lt;p&gt;Next comes the actual code object that is to be installed. Since the
&lt;code&gt;export&lt;/code&gt; trait inspects the name of the subroutine, we need to give
it one. Doing that dynamically can be done by overriding the &lt;code&gt;name&lt;/code&gt;
method, here by mixing in a role with such a method into the code object.&lt;/p&gt;

&lt;p&gt;Finally comes the part where the export trait is applied. The code here
uses knowledge of the calling conventions that hide behind a trait.&lt;/p&gt;

&lt;p&gt;A different script can then write&lt;/p&gt;

&lt;pre&gt;
&lt;span class=&quot;synPreProc&quot;&gt;use&lt;/span&gt; A&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
foo()&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;And access the dynamically exported sub just like any other.&lt;/p&gt;

&lt;p&gt;In future there will hopefully be much nicer APIs for this kind of
fiddling, but for now I'm glad that a workaround has been found.&lt;/p&gt;


</description>
  </item>
  <item rdf:about="http://perlgeek.de/blog-en/perl-6/2012-hackathon-preparations.html">
 <title>Perl 6 Hackathon in Oslo: Be Prepared!</title>
  <link>http://perlgeek.de/blog-en/perl-6/2012-hackathon-preparations.html</link>
 <author>Moritz Lenz</author>
   <pubDate>Tue, Apr 10 22:52:08 2012</pubDate>
    <description>&lt;!-- 1334091128 --&gt;

&lt;p&gt;The Oslo Perl Mongers &lt;a
href=&quot;https://gist.github.com/1711730&quot;&gt;invite to the Perl 6 Patterns
Hackathon in Oslo&lt;/a&gt;. I have &lt;a
href=&quot;http://perlgeek.de/blog-en/perl-6/2012-upcoming-p6-hackathon.html&quot;&gt;previously
suggested that we hack on database connectivity&lt;/a&gt;, and so far only got
positive feedback. If you want to help, here is what you can do to be
prepared:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;Get a github account&lt;/li&gt;
    &lt;li&gt;Build and install Rakudo&lt;/li&gt;
    &lt;li&gt;Build and install zavolaj/NativeCall&lt;/li&gt;
    &lt;li&gt;download MiniDBI&lt;/li&gt;
    &lt;li&gt;install and prepare databases to talk to&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To hack efficiently on those projects, and to benefit from last-minute
fixes, you should obtain Rakudo, NativeCall and MiniDBI from their git source
repositories -- that last release is already outdated.&lt;/p&gt;

&lt;p&gt;Here are the instructions in detail. If at any point you run into problems,
feel free to ask &lt;a href=&quot;http://perl6.org/community/irc&quot;&gt;on the #perl6 IRC
channel&lt;/a&gt; or the perl6-users@perl.org mailing list.&lt;/p&gt;

&lt;h2&gt;Get a Github account&lt;/h2&gt;

&lt;p&gt;All the interesting Perl 6 code lives in git repositories on &lt;a
href=&quot;https://github.com/&quot;&gt;github&lt;/a&gt;. If you don't have an account already, &lt;a
href=&quot;https://github.com/signup/free&quot;&gt;sign up -- it's free&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;Build and install Rakudo&lt;/h2&gt;

&lt;p&gt;This step &lt;a href=&quot;http://rakudo.org/how-to-get-rakudo/&quot;&gt;is described well
    on the Rakudo homepage&lt;/a&gt;. Please follow the instruction in section
&quot;Building the compiler from source&quot;.&lt;/p&gt;

&lt;p&gt;For the following steps it is important that you have a fresh
&lt;code&gt;perl6&lt;/code&gt; executable file in your $PATH. If you have downloaded
rakudo to &lt;code&gt;/home/you/p6/rakudo/&lt;/code&gt;, you can run the command

&lt;pre&gt;
PATH=$PATH:/home/you/p6/rakudo/install/bin
&lt;/pre&gt;

&lt;p&gt;(and put it in your ~/.bashrc file if you want it permanently available,
not just in this shell).&lt;/p&gt;

&lt;h2&gt;Build and install zavolaj/NativeCall&lt;/h2&gt;

&lt;p&gt;NativeCall.pm is the high-level interface for calling C functions from
Perl 6 code. Install it:&lt;/p&gt;

&lt;pre&gt;
$ git clone git://github.com/jnthn/zavolaj.git
$ cd zavolaj
$ cp lib/NativeCall.pm6 ~/.perl6/lib/
&lt;/pre&gt;

&lt;p&gt;If you download and install &lt;a
href=&quot;https://github.com/masak/ufo/&quot;&gt;ufo&lt;/a&gt;, you can use it create a
Makefile for zavolaj. Then you can also run &lt;code&gt;make test&lt;/code&gt;. On Linux it might not find the
test libraries (which is mostly harmless, because you usually call libraries
that are installed into your operating system, like those from mysql or
postgres). In this case you should run &lt;code&gt;LD_LIBRARY_PATH=. make
test&lt;/code&gt; instead.&lt;/p&gt;

&lt;h2&gt;Download MiniDBI&lt;/h2&gt;

&lt;p&gt;That's not hard at all:&lt;/p&gt;

&lt;pre&gt;
$ git clone git://github.com/mberends/MiniDBI.git
&lt;/pre&gt;

&lt;h2&gt;Install and Prepare Databases&lt;/h2&gt;

&lt;p&gt;So far, MiniDBI has (somewhat limited) support for mysql and postgres.
Since it is always easiest to start from (at least somewhat) working code, I
strongly recommend that you install at least one of those database
engines.&lt;/p&gt;

&lt;p&gt;Most modern Linux systems allow an easy installation via the package
manager, and there are installers available for other operating systems. Be
sure to also install the headers or development files if they come as extra
packages.&lt;/p&gt;

&lt;h3&gt;Mysql&lt;/h3&gt;

&lt;p&gt;As mysql &lt;code&gt;root&lt;/code&gt; user, run these statements:&lt;/p&gt;

&lt;pre&gt;
CREATE DATABASE zavolaj;
CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'testpass';
GRANT SELECT         ON   mysql.* TO 'testuser'@'localhost';
GRANT CREATE         ON zavolaj.* TO 'testuser'@'localhost';
GRANT DROP           ON zavolaj.* TO 'testuser'@'localhost';
GRANT INSERT         ON zavolaj.* TO 'testuser'@'localhost';
GRANT DELETE         ON zavolaj.* TO 'testuser'@'localhost';
GRANT LOCK TABLES    ON zavolaj.* TO 'testuser'@'localhost';
GRANT SELECT         ON zavolaj.* TO 'testuser'@'localhost';
&lt;/pre&gt;

&lt;h3&gt;Postgres&lt;/h3&gt;

&lt;p&gt;Launch &lt;code&gt;psql&lt;/code&gt; as the &lt;code&gt;postgres&lt;/code&gt; user and run these
statements:&lt;/p&gt;

&lt;pre&gt;
CREATE DATABASE zavolaj;
CREATE ROLE testuser LOGIN PASSWORD 'testpass';
GRANT ALL PRIVILEGES ON DATABASE zavolaj TO testuser;
&lt;/pre&gt;

&lt;p&gt;You should now be able to connect with:&lt;/p&gt;

&lt;pre&gt;psql --host=localhost --dbname=zavolaj --username=testuser --password
&lt;/pre&gt;

&lt;p&gt;(psql will ask you for the password. Enter &lt;code&gt;testpass&lt;/code&gt;).&lt;/p&gt;

&lt;h3&gt;Other Databases&lt;/h3&gt;

&lt;p&gt;If you want to work on a backend for another database, it helps to have
that database installed. &lt;a href=&quot;http://sqlite.org/&quot;&gt;Sqlite&lt;/a&gt; is
an obvious choice (easy to install, zero setup), but of course there are
other free database too, like &lt;a href=http://firebirdsql.org/&quot;&gt;firebird&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;Project ideas&lt;/h2&gt;

&lt;p&gt;There is a lot of stuff to do. What follows is only a loose, incomplete
collection of ideas.&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;Fix the postgres backend to actually pass its tests&lt;/li&gt;
    &lt;li&gt;Both mysql and postgres backends don't implement placeholders
    properly; change them (or one of them) to pass the placeholder values out
    of band.&lt;/li&gt;
    &lt;li&gt;Write an sqlite backend&lt;/li&gt;
    &lt;li&gt;Currently the user builds a DSN (&quot;data source name&quot;) string out of the
    driver name, database name, db host name and so on, and then the driver
    parses it again. One could change that to pass all the information as
    named parameters instead.&lt;/li&gt;
    &lt;li&gt;Improve test coverage. For example test that numbers round-trip with
    the correct types.&lt;/li&gt;
    &lt;li&gt;Write a small application that uses a database. That's the best way to
    see if MiniDBI and the backends work.&lt;/li&gt;
&lt;/ul&gt;




</description>
  </item>
  <item rdf:about="http://perlgeek.de/blog-en/perl-6/2012-upcoming-p6-hackathon.html">
 <title>Upcoming Perl 6 Hackathon in Oslo, Norway</title>
  <link>http://perlgeek.de/blog-en/perl-6/2012-upcoming-p6-hackathon.html</link>
 <author>Moritz Lenz</author>
   <pubDate>Tue, Mar 20 18:15:52 2012</pubDate>
    <description>&lt;!-- 1332263752 --&gt;

&lt;p&gt;The Oslo Perl Mongers are &lt;a
href=&quot;https://gist.github.com/1711730&quot;&gt;inviting to the Perl 6 Patterns
Hackathon in Oslo&lt;/a&gt; in one month, and I very much look forward to being
there.&lt;/p&gt;

&lt;p&gt;Hackathons can be quite fun and productive if many programmers focus on the
same goal. So to make the hackathon a success, I'm willing to work on whatever
we decide to set as our goal(s).&lt;/p&gt;

&lt;p&gt;One topic that is dear to me, and that is approachable by a horde of
programmers (and guided by one or two Rakudo core hackers) is bringing
database access into a usable state.&lt;/p&gt;

&lt;p&gt;With &lt;a
href=&quot;http://6guts.wordpress.com/2012/01/29/this-months-rakudo-star-release-and-whats-coming-next/&quot;&gt;muchly
    improved support for calling C functions&lt;/a&gt; and &lt;a
href=&quot;https://github.com/jnthn/zavolaj/&quot;&gt;NativeCall.pm&lt;/a&gt; we should have
enough infrastructure for access mysql, postgres and SQLite databases. &lt;a
href=&quot;https://github.com/mberends/MiniDBI&quot;&gt;MiniDBI&lt;/a&gt; aims to provide some
basic convenience, but currently only the mysql driver partially works.&lt;/p&gt;

&lt;p&gt;I believe that with concentrated effort, MiniDBI and the rest of the
infrastructure can be improved to the point that it is usable, and other
modules can start to rely on it. Databases usable in Perl 6, doesn't that
sound good?&lt;/p&gt;

&lt;p&gt;I'll see what kind of feedback I get on this idea, and if it's positive,
I'll follow up with instructions on how to install the prerequisites for
hacking on MiniDBI and its drivers.&lt;/p&gt;


</description>
  </item>
  <item rdf:about="http://perlgeek.de/blog-en/perl-6/2011-02-exceptions.html">
 <title>Current State of Exceptions in Rakudo and Perl 6</title>
  <link>http://perlgeek.de/blog-en/perl-6/2011-02-exceptions.html</link>
 <author>Moritz Lenz</author>
   <pubDate>Tue, Feb 28 11:54:25 2012</pubDate>
    <description>&lt;!-- 1330426465 --&gt;
&lt;p&gt;It's been a while since my last update on my grant work on exceptions for
Perl 6 and Rakudo, and I can report lots of progress.&lt;/p&gt;

&lt;p&gt;The work on Rakudo's exception system made me realize that we conflated two
concepts in the base exception type: on the one hand the infrastructure for
reporting errors and backtraces, and on the other hand holding some sort of
error message as an attribute.&lt;/p&gt;

&lt;p&gt;As a result, we now have a base class called &lt;code&gt;Exception&lt;/code&gt; from
which all exception types must inherit. When a non-&lt;code&gt;Exception&lt;/code&gt;
object is passed to &lt;code&gt;die()&lt;/code&gt;, it is wrapped in an object of class
&lt;code&gt;X::AdHoc&lt;/code&gt;. Other error classes can decide to generate the error
message without having an attribute for it (for example hard-coded in a
method).&lt;/p&gt;

&lt;p&gt;Typed exceptions are now thrown not only from the setting, but also from
the compiler itself, namely the grammar and the action methods. In fact the
majority of errors from these two parts of the compiler are now handled with
dedicated exception types.&lt;/p&gt;


&lt;p&gt;The most user-visible change is a new and improved backtrace printer, which
produces usually much shorter and more readable backtraces. The old one is
still available on demand. Consider the program&lt;/p&gt;

&lt;pre&gt;
&lt;span class=&quot;synStatement&quot;&gt;sub&lt;/span&gt; f {
    g() &lt;span class=&quot;synStatement&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
}
&lt;span class=&quot;synStatement&quot;&gt;sub&lt;/span&gt; g { &lt;span class=&quot;synStatement&quot;&gt;die&lt;/span&gt; &lt;span class=&quot;synSpecial&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;OH NOEZ&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;'&lt;/span&gt; }
f&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;The old backtrace printer produced:

&lt;pre&gt;
OH NOEZ
  in sub g at /home/moritz/p6/rakudo/ex.pl:4
  in block &amp;lt;anon&amp;gt; at /home/moritz/p6/rakudo/ex.pl:2
  in method reify at src/gen/CORE.setting:4471
  in method reify at src/gen/CORE.setting:4376
  in method reify at src/gen/CORE.setting:4376
  in method gimme at src/gen/CORE.setting:4740
  in method eager at src/gen/CORE.setting:4715
  in method eager at src/gen/CORE.setting:1028
  in sub eager at src/gen/CORE.setting:5000
  in sub f at /home/moritz/p6/rakudo/ex.pl:2
  in block &amp;lt;anon&amp;gt; at /home/moritz/p6/rakudo/ex.pl:5
  in &amp;lt;anon&amp;gt; at /home/moritz/p6/rakudo/ex.pl:1
&lt;/pre&gt;

&lt;p&gt;Where the eager, gimme and reify methods come from the 'for' lop, which is
compiled to the equivalent of &lt;code&gt;eager (1..10).map: { g() }&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The new backtrace printer produces&lt;/p&gt;

&lt;pre&gt;
OH NOEZ
  in sub g at ex.pl:4
  in sub f at ex.pl:2
  in block &amp;lt;anon&amp;gt; at ex.pl:5
&lt;/pre&gt;


&lt;p&gt;It is also a special pleasure to report that after a &lt;a
href=&quot;http://irclog.perlgeek.de/perl6/2012-02-27#i_5216391&quot;&gt;walk through a
change to throw a typed exception&lt;/a&gt;, we've received a &lt;a
href=&quot;https://github.com/rakudo/rakudo/pull/59&quot;&gt;pull request by a new
developer&lt;/a&gt; which also changes an exception from X::AdHoc to a dedicated
type.&lt;/p&gt;



</description>
  </item>
  <item rdf:about="http://perlgeek.de/blog-en/perl-6/prisoners-dilemma-results.html">
 <title>Results from the Prisoner's Dilemma Challenge</title>
  <link>http://perlgeek.de/blog-en/perl-6/prisoners-dilemma-results.html</link>
 <author>Moritz Lenz</author>
   <pubDate>Sat, Feb 18 12:00:00 2012</pubDate>
    <description>&lt;!-- 1329562800 --&gt;

&lt;p&gt;The &lt;a
href=&quot;http://perlgeek.de/blog-en/perl-6/iterated-prisoners-dilemma.html&quot;&gt;Iterated
Prisoner's Dilemma Challenge&lt;/a&gt; is now closed; several interesting solutions
have been submitted.&lt;/p&gt;

&lt;p&gt;Of the &lt;a href=&quot;https://gist.github.com/1710688&quot;&gt;basic strategies&lt;/a&gt;,
&lt;em&gt;tit-for-tat&lt;/em&gt; (doing what the opponent did the last time, starting off
with cooperating) is usually the strongest. Since the &lt;em&gt;random&lt;/em&gt;
strategy is, well, random, the results fluctuate a bit.&lt;/p&gt;

&lt;p&gt;Most submitted strategies are a variation on &lt;em&gt;tit-for-tat&lt;/em&gt;,
modified in some way or another to make it stronger. All submissions
contained a strategy that is stronger than &lt;em&gt;tit-for-tat&lt;/em&gt; when tested
against the basic strategies only, though the interaction with other new
strategies made some of them come out weaker than &lt;em&gt;tit-for-tat&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;Submitted Strategies&lt;/h2&gt;

&lt;p&gt;Without any further ado, here are the strategies and a few comments on
them.&lt;/p&gt;

&lt;h3&gt;Turn the Other Cheek&lt;/h3&gt;

&lt;pre&gt;
&lt;span class=&quot;synComment&quot;&gt;## Dean Serenevy; received on 2012-02-07&lt;/span&gt;
&lt;span class=&quot;synIdentifier&quot;&gt;%strategies&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;turn-other-cheek-no-deal-with-devil-once-bit-twice-shy-variety-is-the-spice-o-life&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;sub&lt;/span&gt; (&lt;span class=&quot;synStatement&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;@mine&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;*%&lt;/span&gt;) {
    &lt;span class=&quot;synSpecial&quot;&gt;my&lt;/span&gt; (&lt;span class=&quot;synIdentifier&quot;&gt;$bitten&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;$shy&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;$they-coop&lt;/span&gt;) &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; (&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;False&lt;/span&gt;)&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;synStatement&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;@mine&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;Z&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;$me&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;$them&lt;/span&gt; {
        &lt;span class=&quot;synStatement&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;$them&lt;/span&gt;          { &lt;span class=&quot;synIdentifier&quot;&gt;$they-coop&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt; }
        &lt;span class=&quot;synStatement&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;$me&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;$them&lt;/span&gt; { &lt;span class=&quot;synIdentifier&quot;&gt;$bitten&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;++;&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;$shy&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt; }
        &lt;span class=&quot;synStatement&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;$me&lt;/span&gt;           { &lt;span class=&quot;synIdentifier&quot;&gt;$shy&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;++&lt;/span&gt; }
    }

    &lt;span class=&quot;synSpecial&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;True&lt;/span&gt;  &lt;span class=&quot;synStatement&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;$bitten&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;               &lt;span class=&quot;synComment&quot;&gt;# Cooperate if we have never been bitten&lt;/span&gt;
    &lt;span class=&quot;synSpecial&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;True&lt;/span&gt;  &lt;span class=&quot;synStatement&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;$bitten&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;$shy&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;synComment&quot;&gt;# Turn the other cheek once&lt;/span&gt;
    &lt;span class=&quot;synSpecial&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;False&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;unless&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;$they-coop&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;             &lt;span class=&quot;synComment&quot;&gt;# Screw you too!&lt;/span&gt;
    &lt;span class=&quot;synSpecial&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;$shy&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;&amp;gt;=&lt;/span&gt; (&lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;**&lt;/span&gt; (&lt;span class=&quot;synIdentifier&quot;&gt;$bitten&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;))&lt;span class=&quot;synStatement&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;rand&lt;/span&gt;      &lt;span class=&quot;synComment&quot;&gt;# Once-bitten rand() shy&lt;/span&gt;
}&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;

&lt;/pre&gt;

&lt;h3&gt;Inevitable Betrayal&lt;/h3&gt;

&lt;pre&gt;
&lt;span class=&quot;synComment&quot;&gt;## Andrew Egeler, received 2012-02-09&lt;/span&gt;

&lt;span class=&quot;synIdentifier&quot;&gt;%strategies&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;inevitable-betrayal&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;&amp;amp;inevitable-betrayal&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;synStatement&quot;&gt;sub&lt;/span&gt; inevitable-betrayal (&lt;span class=&quot;synStatement&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;$total&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;*%&lt;/span&gt;) { &lt;span class=&quot;synStatement&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt; &lt;span class=&quot;synSpecial&quot;&gt;&amp;lt;&lt;/span&gt;
&lt;span class=&quot;synConstant&quot;&gt;($total-1) ?? @theirs[*-1] // True !! False }&lt;/span&gt;

&lt;span class=&quot;synConstant&quot;&gt;%strategies&amp;lt;evil-inevitable-betrayal&amp;gt; = &amp;amp;evil-inevitable-betrayal;&lt;/span&gt;
&lt;span class=&quot;synConstant&quot;&gt;sub evil-inevitable-betrayal (:@theirs, :$total, *%) { +@theirs &amp;lt;&lt;/span&gt;
&lt;span class=&quot;synConstant&quot;&gt;($total-1) ?? @theirs[*-1] // False !! False }&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;These are variations on &lt;em&gt;tit-for-tat&lt;/em&gt; and &lt;em&gt;evil-tit-for-tat&lt;/em&gt;
which always defect in the last round, because then the opponent can't
retaliate anymore.&lt;/p&gt;

&lt;p&gt;In a typical Iterated Prisoner's Dilemma contest, strategies don't know how
many rounds are being played, just to avoid this behavior.&lt;/p&gt;

&lt;h3&gt;Tit for D'oh and Watch for Random&lt;/h3&gt;

&lt;pre&gt;
&lt;span class=&quot;synComment&quot;&gt;## Solomon Foster, receievd 2012-02-10&lt;/span&gt;

&lt;span class=&quot;synIdentifier&quot;&gt;%strategies&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;tit-for-doh&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;$total&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;*%&lt;/span&gt; {
    &lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;$total&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;??&lt;/span&gt;  (&lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt;[&lt;span class=&quot;synStatement&quot;&gt;*-&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;] &lt;span class=&quot;synStatement&quot;&gt;//&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;True&lt;/span&gt;) &lt;span class=&quot;synStatement&quot;&gt;!!&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;False&lt;/span&gt;
}

&lt;span class=&quot;synIdentifier&quot;&gt;%strategies&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;watch-for-random&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;*%&lt;/span&gt; {
    &lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;grep&lt;/span&gt;(&lt;span class=&quot;synStatement&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;False&lt;/span&gt;) &lt;span class=&quot;synStatement&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;??&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;False&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;!!&lt;/span&gt; (&lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt;[&lt;span class=&quot;synStatement&quot;&gt;*-&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;] &lt;span class=&quot;synStatement&quot;&gt;//&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;True&lt;/span&gt;)
}&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;&lt;em&gt;tit-for-doh&lt;/em&gt; is the same as &lt;em&gt;inevitable-betrayal&lt;/em&gt;.
&lt;em&gt;watch-for-random&lt;/em&gt; defects forever once the opponent has defected too
often.&lt;/p&gt;

&lt;h3&gt;Me&lt;/h3&gt;

&lt;pre&gt;
&lt;span class=&quot;synComment&quot;&gt;## Audrey Tang, received 2012-02-17&lt;/span&gt;
&lt;span class=&quot;synIdentifier&quot;&gt;%strategies&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;me&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;*%&lt;/span&gt; {
    &lt;span class=&quot;synSpecial&quot;&gt;my&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;role&lt;/span&gt; Me {}&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
    (&lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt;[&lt;span class=&quot;synStatement&quot;&gt;*-&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;] &lt;span class=&quot;synStatement&quot;&gt;//&lt;/span&gt; Me)&lt;span class=&quot;synStatement&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;does&lt;/span&gt;(Me) &lt;span class=&quot;synPreProc&quot;&gt;but&lt;/span&gt; Me
}&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;This strategy uses a mixin in its returned boolean values to find out when
it plays against itself, or against a strategy that copies its values from
&lt;code&gt;@theirs&lt;/code&gt; (ie tit-for-tat derivatives), in which case it cooperates.
This games the system, though doesn't explicitly violates the stated rules.&lt;/p&gt;

&lt;p&gt;Audrey also deserves two dishonorable mentions for two solutions that game
the test harness or the other strategies by exploiting the technically
imperfect sandboxing:&lt;/p&gt;

&lt;pre&gt;
   &lt;span class=&quot;synConstant&quot;&gt;au&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;*%&lt;/span&gt; {
       &lt;span class=&quot;synPreProc&quot;&gt;use&lt;/span&gt; MONKEY_TYPING&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
       &lt;span class=&quot;synSpecial&quot;&gt;my&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;role&lt;/span&gt; TRUE {}&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
       &lt;span class=&quot;synPreProc&quot;&gt;augment&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;Bool&lt;/span&gt; {
           &lt;span class=&quot;synStatement&quot;&gt;method&lt;/span&gt; Stringy(&lt;span class=&quot;synType&quot;&gt;Bool&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;D&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;:&lt;/span&gt;) {
               &lt;span class=&quot;synIdentifier&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;.^&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;does&lt;/span&gt;(TRUE) &lt;span class=&quot;synStatement&quot;&gt;??&lt;/span&gt; &lt;span class=&quot;synSpecial&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;!!&lt;/span&gt; &lt;span class=&quot;synSpecial&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;'&lt;/span&gt;
           }
       }
       &lt;span class=&quot;synType&quot;&gt;False&lt;/span&gt; &lt;span class=&quot;synPreProc&quot;&gt;but&lt;/span&gt; TRUE&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
   }&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; 

   &lt;span class=&quot;synConstant&quot;&gt;amnesia&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;@mine&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;*%&lt;/span&gt; {
       &lt;span class=&quot;synSpecial&quot;&gt;my&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;role&lt;/span&gt; Uh {}&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
       &lt;span class=&quot;synSpecial&quot;&gt;my&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;$rv&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; (&lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt;[&lt;span class=&quot;synStatement&quot;&gt;*-&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;] &lt;span class=&quot;synStatement&quot;&gt;//&lt;/span&gt; Uh)&lt;span class=&quot;synStatement&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;does&lt;/span&gt;(Uh) &lt;span class=&quot;synPreProc&quot;&gt;but&lt;/span&gt; Uh&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
       &lt;span class=&quot;synIdentifier&quot;&gt;@mine&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; ()&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
       &lt;span class=&quot;synIdentifier&quot;&gt;$rv&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
   }&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;Those two strategies did not compete in the tournament&lt;/p&gt;

&lt;h3&gt;Lenient in the Beginning, Then Strict&lt;/h3&gt;

&lt;p&gt;I've written my own two strategies before the tournament started. &lt;a
href=&quot;http://moritz.faui2k3.org/files/prisoner-moritz.pl.txt&quot;&gt;Here is the
original&lt;/a&gt;, I've only changed the signatures to run under current
Niecza:&lt;/p&gt;

&lt;pre&gt;
&lt;span class=&quot;synComment&quot;&gt;# a tit for tat, but a bit more friendly at the beginning&lt;/span&gt;
&lt;span class=&quot;synComment&quot;&gt;# to avoid hacking on forever on evil-tit-for-tat,&lt;/span&gt;
&lt;span class=&quot;synComment&quot;&gt;# but be very stringent when the other one defects too often&lt;/span&gt;
&lt;span class=&quot;synStatement&quot;&gt;sub&lt;/span&gt; moritz-ctft(&lt;span class=&quot;synStatement&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;$total&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt;  &lt;span class=&quot;synStatement&quot;&gt;*%&lt;/span&gt;) {
    &lt;span class=&quot;synSpecial&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;True&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;synSpecial&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;False&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;grep&lt;/span&gt;(&lt;span class=&quot;synStatement&quot;&gt;*.&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;not&lt;/span&gt;)&lt;span class=&quot;synStatement&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;elems&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;&amp;gt;&lt;/span&gt; (&lt;span class=&quot;synIdentifier&quot;&gt;$total&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;10&lt;/span&gt;)&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt;[&lt;span class=&quot;synStatement&quot;&gt;*-&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;]&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
}&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;synIdentifier&quot;&gt;%strategies&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;moritz-ctft&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;&amp;amp;moritz-ctft&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;synComment&quot;&gt;# the evil clone...&lt;/span&gt;
&lt;span class=&quot;synStatement&quot;&gt;sub&lt;/span&gt; moritz-ectft(&lt;span class=&quot;synStatement&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;$total&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;,&lt;/span&gt;  &lt;span class=&quot;synStatement&quot;&gt;*%&lt;/span&gt;) {
    &lt;span class=&quot;synSpecial&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;True&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;synSpecial&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;False&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;grep&lt;/span&gt;(&lt;span class=&quot;synStatement&quot;&gt;*.&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;not&lt;/span&gt;)&lt;span class=&quot;synStatement&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;elems&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;&amp;gt;&lt;/span&gt; (&lt;span class=&quot;synIdentifier&quot;&gt;$total&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;10&lt;/span&gt;)&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;synComment&quot;&gt;# did you believe in happy ends?&lt;/span&gt;
    &lt;span class=&quot;synSpecial&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;False&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;$total&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;synIdentifier&quot;&gt;@theirs&lt;/span&gt;[&lt;span class=&quot;synStatement&quot;&gt;*-&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;]&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
}&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;synIdentifier&quot;&gt;%strategies&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;moritz-ectft&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;&amp;amp;moritz-ectft&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;;&lt;/span&gt;
&lt;/pre&gt;

&lt;h2&gt;Results&lt;/h2&gt;

&lt;p&gt;The results vary quite a bit between runs, mostly because of the
&lt;em&gt;random&lt;/em&gt; strategy.&lt;/p&gt;

&lt;p&gt;Here is the output from a sample run. Please don't use this for
determining the &quot;winner&quot;, because it is just a random sample with no
statistical significance.&lt;/p&gt;

&lt;pre&gt;
SUMMARY
2588    moritz-ectft
2577    me
2560    moritz-ctft
2491    inevitable-betrayal
2483    tit-for-tat
2480    tit-for-doh
2399    turn-other-cheek-no-deal-with-devil-once-bit-twice-shy-variety-is-the-spice-o-life
2319    watch-for-random
2272    good
1876    evil-inevitable-betrayal
1862    evil-tit-for-tat
1538    random
1145    bad
&lt;/pre&gt;

&lt;p&gt;You see, &lt;em&gt;inevitable-betrayal&lt;/em&gt; and &lt;em&gt;tit-for-doh&lt;/em&gt; are exactly
the same strategy, but the random fluctuations place them on different sides
of &lt;em&gt;tit-for-tat&lt;/em&gt;. Which is why I won't declare a winner at all, there
is simply no fair way to determine one.&lt;/p&gt;

&lt;p&gt;At first I was surprised how well the &lt;em&gt;me&lt;/em&gt; strategy performed. But
then I noticed that with the given game harness, a strategy fighting against
itself counts double (once for the first copy, once for the second copy). With
only 13 strategies participating, and such close results, harmonizing
perfectly with yourself gives you a critical advantage.&lt;/p&gt;

&lt;h3&gt;Visualizations&lt;/h3&gt;

&lt;p&gt;For each strategy you can find an image that shows how it worked with or
against another strategy. Green means cooperate, red means defect, and the
height of the bar is proportional to the resulting score.&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;&lt;a href=&quot;http://perlgeek.de/images/blog/prisoner/bad.png&quot;&gt;bad&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://perlgeek.de/images/blog/prisoner/evil-inevitable-betrayal.png&quot; width=&quot;566&quot; height=&quot;1248&quot;&gt;evil-inevitable-betrayal&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://perlgeek.de/images/blog/prisoner/evil-tit-for-tat.png&quot;&gt;evil-tit-for-tat&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://perlgeek.de/images/blog/prisoner/good.png&quot;&gt;good&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://perlgeek.de/images/blog/prisoner/inevitable-betrayal.png&quot;&gt;inevitable-betrayal&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://perlgeek.de/images/blog/prisoner/me.png&quot;&gt;me&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://perlgeek.de/images/blog/prisoner/moritz-ctft.png&quot;&gt;moritz-ctft&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://perlgeek.de/images/blog/prisoner/moritz-ectft.png&quot;&gt;moritz-ectft&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://perlgeek.de/images/blog/prisoner/random.png&quot;&gt;random&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://perlgeek.de/images/blog/prisoner/tit-for-doh.png&quot;&gt;tit-for-doh&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://perlgeek.de/images/blog/prisoner/tit-for-tat.png&quot;&gt;tit-for-tat&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://perlgeek.de/images/blog/prisoner/turn-other-cheek-no-deal.png&quot;&gt;turn-the-other-cheek-no-deal...&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;http://perlgeek.de/images/blog/prisoner/watch-for-random.png&quot;&gt;watch-for-random&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Trying to Be Fair&lt;/h3&gt;

&lt;p&gt;In an attempt to reduce the impact of the &lt;em&gt;random&lt;/em&gt; strategy, I've
changed it to use the same random sequence against each player (and of course
against itself, which totally skews that particular result).&lt;/p&gt;

&lt;p&gt;Again the rankings vary between different runs of the same program, but now
at least same strategies produce mostly the same result
(&lt;em&gt;turn-the-other-cheek&lt;/em&gt; also has a random component). An example output
from such a run is&lt;/p&gt;

&lt;pre&gt;
SUMMARY
2558    moritz-ectft
2543    moritz-ctft
2532    me
2457    inevitable-betrayal
2457    tit-for-doh
2445    tit-for-tat
2387    turn-other-cheek-no-deal-with-devil-once-bit-twice-shy-variety-is-the-spice-o-life
2314    watch-for-random
2248    good
1856    evil-inevitable-betrayal
1844    evil-tit-for-tat
1359    random
1100    bad
&lt;/pre&gt;

&lt;h2&gt;TL;DR&lt;/h2&gt;

&lt;p&gt;It was a lot of fun! Thanks to everybody who submitted a strategy.&lt;/p&gt;


</description>
  </item>
  <item rdf:about="http://perlgeek.de/blog-en/perl-6/iterated-prisoners-dilemma.html">
 <title>Mini-Challenge: Write Your Prisoner's Dilemma Strategy</title>
  <link>http://perlgeek.de/blog-en/perl-6/iterated-prisoners-dilemma.html</link>
 <author>Moritz Lenz</author>
   <pubDate>Tue, Feb  7 08:41:42 2012</pubDate>
    <description>&lt;!-- 1328600502 --&gt;

&lt;p&gt;Here is a small task we considered for the &lt;a
href=&quot;http://strangelyconsistent.org/blog/the-2011-perl-6-coding-contest&quot;&gt;Perl
6 Coding Contest&lt;/a&gt;, but not chose to not pursue. But it's a nice little
challenge for your leisure time.&lt;/p&gt;

&lt;p&gt;In the &lt;a
href=&quot;http://en.wikipedia.org/wiki/Prisoner%27s_dilemma&quot;&gt;Prisoner's
Dilemma&lt;/a&gt;, two suspected criminals can choose to not betray each other
(which we call &quot;cooperate&quot;), or betraying the other (&quot;defecting&quot;).
If only one suspect betrays the other, the traitor gets released and
the betrayed one gets a long sentence; if both betray each other, both get a
rather long sentence. If both cooperate, both get rather short sentences.&lt;/p&gt;

&lt;p&gt;It becomes more interesting when the dilemma is repeated multiple times.
Now instead of prison sentences the contestants are assigned scores, which
add up over multiple rounds.&lt;/p&gt;

&lt;p&gt;I challenge you to write one or two strategies for the iterated prisoner's
dilemma, and send them to moritz@faui2k3.org no later than Friday
February 17.&lt;/p&gt;

&lt;p&gt;You'll find &lt;a href=&quot;https://gist.github.com/1710688&quot;&gt;some basic
strategies and a harness here&lt;/a&gt;. It runs on both newest Rakudo and
Niecza.&lt;/p&gt;

&lt;p&gt;The scoring is as follows, where &lt;code&gt;True&lt;/code&gt; means cooperate and
&lt;code&gt;False&lt;/code&gt; means defect:&lt;/p&gt;

&lt;pre&gt;
my %scoring =
    'True True' =&amp;gt; [4, 4],
    'True False' =&amp;gt; [0, 6],
    'False True' =&amp;gt; [6, 0],
    'False False' =&amp;gt; [1, 1],
&lt;/pre&gt;

&lt;p&gt;Your strategy should be a subroutine or block that accepts the named
parameters &lt;code&gt;mine&lt;/code&gt; and &lt;code&gt;theirs&lt;/code&gt;, which are lists
of previous decisions of your own algorithm and of its opponents, and
&lt;code&gt;total&lt;/code&gt;, which is the number of laps to be played. It should
return &lt;code&gt;True&lt;/code&gt; if it wishes to cooperate, and &lt;code&gt;False&lt;/code&gt; to
defect.&lt;/p&gt;

&lt;p&gt;Here is an example strategy that starts off with cooperating, and then
randomly chooses a previous reaction of the current opponent:&lt;/p&gt;

&lt;pre&gt;
sub example-strategy(:@theirs, *%) {
    @theirs.roll // True;
}
&lt;/pre&gt;

&lt;p&gt;Your strategy or strategies will play against each other and against the
example strategies in the gist above. It is not allowed to submit strategies
that commit suicide to actively support another strategy.&lt;/p&gt;

&lt;p&gt;I too have written two strategies that will take participate in the
contest. Here is the checksum to convince you I won't alter the strategies
in response to the submissions:&lt;/p&gt;

&lt;pre&gt;
6d4ba99b66e4963a658c8dcfc72922dd0f74e0ad  prisoner-moritz.pl
&lt;/pre&gt;


</description>
  </item>
  <item rdf:about="http://perlgeek.de/blog-en/perl-6/perl-6-in-2011.html">
 <title>Perl 6 in 2011 - A Retrospection</title>
  <link>http://perlgeek.de/blog-en/perl-6/perl-6-in-2011.html</link>
 <author>Moritz Lenz</author>
   <pubDate>Sat, Dec 31 10:00:00 2011</pubDate>
    <description>&lt;!-- 1325322000 --&gt;
&lt;p&gt;The change of year is a good occasion to look back. Here I want to
reflect on the development of Perl 6, its compilers and ecosystem.&lt;/p&gt;

&lt;p&gt;At the start of the year, masak's &lt;a
href=&quot;http://strangelyconsistent.org/p6cc2010/&quot;&gt;Perl 6 Coding Contest&lt;/a&gt;
continued from 2010, concluding in the &lt;a
href=&quot;http://strangelyconsistent.org/blog/announcing-the-winner-of-p6cc2010&quot;&gt;announcement
of the winner&lt;/a&gt;. I must admit that I still haven't read all the books I
won :-)&lt;/p&gt;

&lt;h2&gt;Specification&lt;/h2&gt;

&lt;p&gt;2011 was a rather quiet year in terms of spec changes; they were a
mixture of responses to compiler writer and user feedback, and
some simplifications and cleanups.&lt;/p&gt;

&lt;p&gt;Positional parameters used to be allowed to be called by name; this
feature is now gone. That both makes the signature binder simpler, and
removes accidental dependencies on names that weren't meant to be public.
Read the &lt;a href=&quot;https://gist.github.com/984783&quot;&gt;full justification&lt;/a&gt;
for more background.&lt;/p&gt;

&lt;p&gt;A small change that illustrates the cleanup of old, p5-inherited features
was the change that &lt;a
href=&quot;https://github.com/perl6/specs/commit/e84b11137cc55ecd9f17f58976c08d361054ea05&quot;&gt;made
&amp;amp;eval stop catching exceptions&lt;/a&gt;. There is really no good reason for it
to catch them, except Perl 5 legacy.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;say&lt;/code&gt; now uses a different stringification than
&lt;code&gt;print&lt;/code&gt;. The reasoning is that &lt;code&gt;print&lt;/code&gt; is aimed at
computer-readable output, whereas &lt;code&gt;say&lt;/code&gt; is often used for
debugging. As an example, undefined values stringify to the empty string
(and produce a warning), whereas &lt;code&gt;say&lt;/code&gt; calls the &lt;code&gt;.gist&lt;/code&gt;
method on the object to be said, which produces the type name on undefined
values.&lt;/p&gt;

&lt;p&gt;An area that has been greatly solidified due to implementation progress is
&lt;em&gt;Plain Old Documentation&lt;/em&gt; or &lt;em&gt;Pod&lt;/em&gt;. Tadeusz Sośnierz' Google
Summer of Code project ironed out many wrinkles and inconsistencies, and
changed my perception of this part of the spec from &quot;speculative&quot; to &quot;under
development&quot;.&lt;/p&gt;

&lt;h2&gt;Rakudo&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;http://rakudo.org/&quot;&gt;Rakudo&lt;/a&gt; underwent a huge refactoring this year; it is now &lt;a
href=&quot;http://pmthium.com/2011/02/08/new-nqp-repository-new-nom-rakudo-branch/&quot;&gt;bootstrapped
by a new compiler called &quot;nqp&quot;, and uses a new object model&lt;/a&gt; (nom).&lt;/p&gt;

&lt;p&gt;It allows us to gain speed and memory advantages from gradual typing; for
example the &lt;a
href=&quot;https://github.com/colomon/mandelbrot/blob/master/bin/mandelbrot-color.pl&quot;&gt;mandelbrot
fractral generator&lt;/a&gt; used to take 18 minutes to run on a machine of mine,
and now takes less than 40 seconds. Speedups in other areas are not as big,
but there is still much room for improvement in the optimizer.&lt;/p&gt;

&lt;p&gt;With the nom branch came support for different object representations. It
makes it possible to store object attributes in simple C-like structs, which
in turn makes it much easier and more convenient to &lt;a
href=&quot;https://github.com/jnthn/zavolaj/&quot;&gt;interoperate with C
libraries&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Tadeusz' work on Pod gave Rakudo support for converting Pod to plain text
and HTML, and attach documentation objects to routines and other objects.&lt;/p&gt;

&lt;p&gt;Rakudo now also has lazy lists, much better role handling, &lt;a
href=&quot;http://news.perlfoundation.org/2011/02/hague-grant-application-struct.html&quot;&gt;typed
exceptions for a few errors&lt;/a&gt;, the &lt;code&gt;-n&lt;/code&gt; and &lt;code&gt;-p&lt;/code&gt; command
line options, support for big integers, NFA-based support for proto regexes
and improvements to many built-in functions, methods and operators.&lt;/p&gt;


&lt;h2&gt;Niecza&lt;/h2&gt;

&lt;p&gt;It is hard to accurately summarize the development of &lt;a
href=&quot;https://github.com/sorear/niecza/&quot;&gt;Niecza&lt;/a&gt; in a few
sentences; instead of listing the many, many new features I should give
an impression on how it feels and felt for the user.&lt;/p&gt;

&lt;p&gt;At the start of 2011, programming in niecza was a real adventure. Running 
some random piece of Perl 6 code that worked with Rakudo rarely worked, most
of the time it hit a missing built-in, feature or bug.&lt;/p&gt;

&lt;p&gt;Now it often just works, and usually much faster than in Rakudo. There are
still some missing features, but Stefan O'Rear and his fellow contributors
work tirelessly on catching up to Rakudo, and it some areas Niecza is clearly
ahead (for example Unicode support in regexes, and longest-token
matching).&lt;/p&gt;

&lt;p&gt;Since Niecza is implemented on top of the Common Language Runtime (CLR)
(which means .NET or mono), it makes it easy to use existing CLR-based
libraries. Examples include &lt;a
href=&quot;http://perl6advent.wordpress.com/2011/12/17/day-17-gtk-mandelbrot/&quot;&gt;an
interactive fractal generator&lt;/a&gt; and a small &lt;a
href=&quot;http://perl6advent.wordpress.com/2011/12/05/tetris-on-niecza/&quot;&gt;Tetris
game in Perl 6.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Perlito&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;http://www.perlito.org/&quot;&gt;Perlito&lt;/a&gt; aims to be a minimal compiler
with multiple backends, which can be used for embedding and experimenting with
Perl 6. It had several releases in 2011, and has interesting features like a
Javascript backend.&lt;/p&gt;

&lt;h2&gt;Ecosystem&lt;/h2&gt;

&lt;p&gt;The presence of two usable compilers (and in the case of Rakudo, two viable
but very different branches) has led to many questions about the different
compilers. The new &lt;a href=&quot;http://perl6.org/compilers/features&quot;&gt;Perl 6
Compiler Feature matrix&lt;/a&gt; tries to answer the questions about the state of
the implemented features in the compilers.&lt;/p&gt;

&lt;p&gt;With &lt;a href=&quot;https://github.com/tadzik/panda/&quot;&gt;Panda&lt;/a&gt; we now have a
module installer that actually works with Rakudo. It still has some lengths to
go in terms of stability and feature completeness, but it is fun to work
with.&lt;/p&gt;

&lt;p&gt;The new &lt;a href=&quot;http://modules.perl6.org/&quot;&gt;Perl 6 Modules&lt;/a&gt; page gives
an overview of existing Perl 6 modules; we hope to evolve it into a real CPAN
equivalent.&lt;/p&gt;

&lt;h2&gt;Community&lt;/h2&gt;

&lt;p&gt;This year we had another &lt;a
href=&quot;http://perl6advent.wordpress.com/2011/12/01/perl-6-advent-calendar-2011/&quot;&gt;Perl
6 Advent Calendar&lt;/a&gt;, with much positive feedback both from the Perl 6
community and the wider programming community.&lt;/p&gt;

&lt;p&gt;We were also happy to welcome several new prolific contributors to the Perl
6 compilers and modules. The atmosphere in the community still feels relaxed,
friendly and productive -- I quite enjoy it.&lt;/p&gt;

&lt;p&gt;The year ends like it started: with a &lt;a
href=&quot;http://strangelyconsistent.org/blog/the-2011-perl-6-coding-contest&quot;&gt;Perl
6 Coding Contest&lt;/a&gt;. This is a good opportunity to dive into Perl 6, provide
feedback to compiler writers, and most of all have fun.&lt;/p&gt;

 
</description>
  </item>
  <item rdf:about="http://perlgeek.de/blog-en/perl-6/grant-report-errors-4.html">
 <title>Fourth Grant Report: Structured Error Messages</title>
  <link>http://perlgeek.de/blog-en/perl-6/grant-report-errors-4.html</link>
 <author>Moritz Lenz</author>
   <pubDate>Mon, Dec 19 10:28:48 2011</pubDate>
    <description>&lt;!-- 1324286928 --&gt;
&lt;p&gt;Progress on my &lt;a
href=&quot;http://news.perlfoundation.org/2011/02/hague-grant-application-struct.html&quot;&gt;grant
for error message&lt;/a&gt; is slow but steady. Since my last report, I've done the
following things:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;Merged the &lt;code&gt;nom-exceptions&lt;/code&gt; Rakudo  branch, so now you
    can reliably throw Perl 6 objects as exceptions.&lt;/li&gt;
    &lt;li&gt;Implemented several error classes and roles in Rakudo&lt;/li&gt;
    &lt;li&gt;Started to throw typed errors both from runtime libraries and from
        inside the compiler&lt;/li&gt;
    &lt;li&gt;Hacked the default exception printer Rakudo to be much more flexible,
        for example you can now write exception classes that supress
        backtraces from the standard handler.&lt;/li&gt;
    &lt;li&gt;Wrote tests for typed run time and compile time errors, and at the
        same time developed a test function that makes it easy to write such
        tests.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's time for a quick review of how far I am along the various deliverables
in the original grant proposal.&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;D1: Specification. I think the hard work here is done already,
        what remains to do is finding good default and how to manipulate them
        (for example, how to generally switch on/off printing of
        backtraces?).&lt;/li&gt;
    &lt;li&gt;D2: Error catalogue, tests: I've not worked on this one too much.
        The error classes and roles so far mostly served to exercise the
        implementation; going through the existing errors from the various
        compilers and formalizing them will be quite a bit of work, but only
        moderately complicated.&lt;/li&gt;
    &lt;li&gt;D3: Implementation, documentation. Like D1, the hard part is mostly 
        done. We can now
       throw errors from within the compiler actions and from the setting,
       next up will be the grammar. Then all places where errors are thrown
       need to be changed to use the new error classes. Again that'll be much
       work, but easy to do. Documentation is still missing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All in all I feel I'm well on the way, and most complex decisions have been
made. &lt;/p&gt;


&lt;p&gt;For a more user oriented view of the new exception system I'd like to
point you to my &lt;a
    href=&quot;http://perl6advent.wordpress.com/2011/12/15/day-15-something-exceptional/&quot;&gt;Perl
    6 advent calendar post on exceptions&lt;/a&gt;.&lt;/p&gt;


</description>
  </item>
  <item rdf:about="http://perlgeek.de/blog-en/perl-6/three-functions-of-smartmatch.html">
 <title>The Three-Fold Function of the Smart Match Operator</title>
  <link>http://perlgeek.de/blog-en/perl-6/three-functions-of-smartmatch.html</link>
 <author>Moritz Lenz</author>
   <pubDate>Wed, Oct 12 11:37:08 2011</pubDate>
    <description>&lt;!-- 1318412228 --&gt;
&lt;p&gt;In Perl 5, if you want to match a regex against a particular
string, you write &lt;code&gt;$string =~ $regex&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In the design process of Perl 6, people have realized that you cannot
only match against regexes, but lots of other things can act as
patterns too: types (checking type conformance), numbers, strings,
junctions (composites of values), subroutine signatures and so on. So
&lt;em&gt;smart matching&lt;/em&gt; was born, and it's now written as
&lt;code&gt;$topic ~~ $pattern&lt;/code&gt;. Being a general comparison mechanism
is the first function of the smart match operator.&lt;/p&gt;

&lt;p&gt;But behold, there were problems. One of them was the perceived need
for special syntactic forms on the right hand side of the smart match
operator to cover some cases. Those were limited and hard to
implement. There was also the fact that now we had two different ways
to invoke regexes: smart matching, and direct invocation as
&lt;code&gt;m/.../&lt;/code&gt;, which matches against the topic variable
&lt;code&gt;$_&lt;/code&gt;. That wasn't really a problem as such, but it was an
indicator of design smell.&lt;/p&gt;

&lt;p&gt;And that's where the second function of the smart match operator
originated: topicalization. Previously, &lt;code&gt;$a ~~ $b&lt;/code&gt; mostly
turned into a method call, &lt;code&gt;$b.ACCEPTS($a)&lt;/code&gt;. The new idea
was to &lt;a
href=&quot;https://github.com/perl6/specs/commit/f2dff276c272399a92a841818842ad663d70f23b&quot;&gt;set
the topic variable to $a in a small scope&lt;/a&gt;, which allowed many
special cases to go away. It also nicely unified with
&lt;code&gt;given $topic { when $matcher  { ... } }&lt;/code&gt;, which was
already specified as being a topicalizer.&lt;/p&gt;

&lt;p&gt;In the new model, &lt;code&gt;MATCH ~~ PAT&lt;/code&gt; becomes something like
&lt;code&gt;do { $_ = MATCH; PAT.ACCEPTS($_) }&lt;/code&gt; -- which means that if
&lt;code&gt;MATCH&lt;/code&gt; accesses &lt;code&gt;$_&lt;/code&gt;, it automatically does what the
user wants.&lt;/p&gt;

&lt;p&gt;Awesomeness reigned, and it worked out great.&lt;/p&gt;

&lt;p&gt;Until the compiler writers actually started to implement a few more
cases of regex matching. The first thing we noticed was that
&lt;code&gt;if $str ~~ $regex { ... }&lt;/code&gt; behaved quite unexpectedly.
What happend was that &lt;code&gt;$_&lt;/code&gt; got set to &lt;code&gt;$str&lt;/code&gt;,
the match was conducted and returned a Match object. And then called
&lt;code&gt;$match.ACCEPTS($str)&lt;/code&gt;, which failed. A quick hack around
that was to modify &lt;code&gt;Match.ACCEPTS&lt;/code&gt; to always return the
invocant (ie the Match on which it was called), but of course that was
only a stop gap solution.&lt;/p&gt;

&lt;p&gt;The reason it doesn't work for other, more involved cases of regex
invocations is that they don't fit into the &quot;does $a match $b?&quot;
schema. Two examples:&lt;/p&gt;

&lt;pre&gt;
# :g for &amp;quot;global&amp;quot;, all matches
my @matches = $str ~~ m:g/pattern/; 

if $str ~~ s/pattern/substitution/ { ... }
&lt;/pre&gt;

&lt;p&gt;People expect those to work. But global matching of a regex isn't a
simple conformance check, and that is reflected in the return value: a
list. So should we special-cases smart-matching against a list, just
because we can't get global matching to work in smart-matching
otherwise? (People have also proposed to return a kind of aggregate
Match object instead of a list; that comes with the problem that Match
objects aren't lazy, but lists are. You could &quot;solve&quot; that with a
LazyMatch type; watch the pattern of workarounds unfold...)&lt;/p&gt;

&lt;p&gt;A substitution is also not a simple matching operation. In Perl 5,
a s/// returns the number of successful substitutions. In Perl 6, that
wouldn't work with the current setup of the smart match operator,
where it would then smart-match the string against the returned number
of matches.&lt;/p&gt;

&lt;p&gt;So to summarize, the smart match operator has three functions:
comparing values to patterns, topicalization, and conducting regex
matches.&lt;/p&gt;

&lt;p&gt;These three functions are distinct enough to start to interact in
weird ways, which limits the flexibility in choice of return values
from regex matches and substitutions.&lt;/p&gt;

&lt;p&gt;I don't know what the best way forward is. Maybe it is to
reintroduce a dedicated operator for regex matching, which seems to be
the main feature with which topicalization interacts badly. Maybe
there are other good ideas out there. If so, I'd love to hear about
them.&lt;/p&gt;


</description>
  </item>
  <item rdf:about="http://perlgeek.de/blog-en/perl-6/grant-report-errors-3.html">
 <title>Third Grant Report: Structured Error Messages</title>
  <link>http://perlgeek.de/blog-en/perl-6/grant-report-errors-3.html</link>
 <author>Moritz Lenz</author>
   <pubDate>Mon, Aug 29 10:56:41 2011</pubDate>
    <description>&lt;!-- 1314608201 --&gt;
&lt;p&gt;Progress on my &lt;a
href=&quot;http://news.perlfoundation.org/2011/02/hague-grant-application-struct.html&quot;&gt;grant
for error message&lt;/a&gt; is slower than expected, as expected :-). Yes, you've
read that sentence before.&lt;/p&gt;

&lt;p&gt;In the past months, general hacking on the nom branch of Rakudo was just
too much fun -- and partially a prerequisite for the exceptions work.&lt;/p&gt;

&lt;p&gt;I did manage to redo the backtraces that are generated from error
messages.&lt;/p&gt;

&lt;p&gt;Backtraces are now generated mostly in Perl 6 code, making them much more
hackable. There's a &lt;code&gt;Backtrace&lt;/code&gt; class, which is a list of
&lt;code&gt;Backtrace::Frame&lt;/code&gt; objects, each knowing the code object associated
with it, as well as line number and file. (This is both specced and works in
Rakudo)&lt;/p&gt;

&lt;p&gt;Routines can have the &lt;code&gt;is hidden_from_backtrace&lt;/code&gt; trait, which
makes them not show up in the default backtrace stringification (one can still
request a &lt;code&gt;.full&lt;/code&gt; string representation). This is useful for
routines which are internally used to generate exceptions, like
&lt;code&gt;die()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Rakudo also has a &lt;code&gt;--ll-exceptions&lt;/code&gt; command line option which
provides PIR-level backtraces, in the rare case the Perl 6 level backtraces
hide too much information.&lt;/p&gt;

&lt;p&gt;I've also started the &lt;code&gt;nom-exceptions&lt;/code&gt; branch in Rakudo, which
aims at lifting current limitations in Rakudo's exception handling. Currently
&lt;code&gt;die()&lt;/code&gt; and friends generate a parrot exception, and then there's a
routine that fills the error variable &lt;code&gt;$!&lt;/code&gt;. This routine generates
a new &lt;code&gt;Exception&lt;/code&gt; object, and sticks the parrot exception into
it.&lt;/p&gt;

&lt;p&gt;This practice means that if you create a subclass of
&lt;code&gt;Exception&lt;/code&gt;, instantiate it and throw it, you still only get an
&lt;code&gt;Exception&lt;/code&gt; in the error handler, not an object of the subclass.
Since the actual exception type is very important for the ongoing work, that
has to change. The branch mentioned earlier allows one to generate a Perl 6
exception, and pass that on as the payload of the parrot exception, which is
then unwrapped when filling &lt;code&gt;$!&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;As a proof of concept this works, but it suffers from not being robust
enough -- as it is, we could accidentally unwrap the payload of a
&lt;code&gt;CONTROL&lt;/code&gt; exception, placing meaningless junk into &lt;code&gt;$!&lt;/code&gt;.
So this needs a bit more work, which I plan to do this week (or next, if it
proves to be more difficult than anticipated).&lt;/p&gt;

&lt;p&gt;As always, your feedback is very welcome.&lt;/p&gt;


</description>
  </item>
  <item rdf:about="http://perlgeek.de/blog-en/perl-6/why-rakudo-needs-nqp.html">
 <title>Why Rakudo needs NQP</title>
  <link>http://perlgeek.de/blog-en/perl-6/why-rakudo-needs-nqp.html</link>
 <author>Moritz Lenz</author>
   <pubDate>Wed, Aug 24 13:43:55 2011</pubDate>
    <description>&lt;!-- 1314186235 --&gt;

&lt;p&gt;&lt;a href=&quot;http://rakudo.org/&quot;&gt;Rakudo&lt;/a&gt;, a popular &lt;a
href=&quot;http://perl6.org/&quot;&gt;Perl 6&lt;/a&gt; compiler, is built on top of a smaller
compiler called &quot;NQP&quot;, short for &lt;em&gt;Not Quite Perl&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Reading through a &lt;a
    href=&quot;http://www.modernperlbooks.com/mt/2011/08/no-policy-can-save-wrong-code.html&quot;&gt;recent
    ramble by chromatic&lt;/a&gt;, I felt like he said &quot;Rakudo needs NQP to be able
to ditch Parrot, once NQP runs on a different platform&quot; (NQP is the &quot;another
layer&quot;, which sits between Rakudo and Parrot, mentioned in the next-to-final
paragraph).&lt;/p&gt;

&lt;p&gt;I'm sure chromatic knows that VM independence is the least important reason
for having NQP at all, but the casual reader might not, so let me explain the
real importance of NQP for Rakudo here.&lt;/p&gt;

&lt;p&gt;The short version is just a single word: &lt;a
    href=&quot;http://en.wikipedia.org/wiki/Bootstrapping_%28compilers%29&quot;&gt;bootstrapping&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The longer version is that large parts of Rakudo are written in Perl 6
itself (or a subset thereof), and something is needed to break the
circularity.&lt;/p&gt;

&lt;p&gt;In particular the base of the compiler is written in a subset of Perl 6,
and NQP compiles those parts to bytecode, which can then compile the rest of
the compiler.&lt;/p&gt;

&lt;p&gt;This is not just because we have a fancy for Perl 6, and thus want to write
as much of the code in Perl 6, but there are solid technical reasons for
writing the compiler in Perl 6.&lt;/p&gt;

&lt;p&gt;In Perl 6, the boundary between run time and compile time is blurred, as
well as the boundary between the compiler, the run time library and user-space
code. For example you alter the grammar with which your source code is parsed, by
injecting your own grammar rules.&lt;/p&gt;

&lt;p&gt;&quot;Your own grammar rules&quot; above refers to user-space code, while the grammar
that is being altered is part of the compiler. If we had written the compiler
in something else than Perl 6 (for example Java), it would be horribly
difficult to inject user-space Perl 6 code into compiled code from a different
language.&lt;/p&gt;

&lt;p&gt;And the code not only needs to be injected, but the data passed back
and forth between the compiler and the user space need to be Perl 6 objects, so all
important data structures in the compiler need to be Perl 6 based anyway.&lt;/p&gt;

&lt;p&gt;And it's not just for grammar modifications: At its heart, Perl 6 is an
object oriented language. When the compiler sees a class definition, it
translates them to a series of method calls on the &lt;a
href=&quot;http://en.wikipedia.org/wiki/Metaobject&quot;&gt;metaobject&lt;/a&gt;, which again
needs to be a Perl 6 object, otherwise it wouldn't be easily usable and
extensible from the user space.&lt;/p&gt;

&lt;p&gt;Now you might think that grammar modifications and changes to the
Metaobject are pretty obscure features, and you could get along just fine
with an incomplete Perl 6 compiler that neglected those two areas. But even
then you'd have lots of interactions between run time and compile time. For
example consider a numeric literal like &lt;code&gt;42&lt;/code&gt;. Obviously that needs
to be constructed of type &lt;code&gt;Int&lt;/code&gt;. What's less obvious is that it
needs to be constructed to be of type Int at compile time already, because
Perl 6 code can run interleaved with the compilation. So the compiler needs to
be able to handle Perl 6 objects in all their generality, which is a huge pain
if the compiler is not written in Perl 6.&lt;/p&gt;

&lt;p&gt;Rakudo has cheated on that front in the past, and consequently has
had lots of bugs and limitations due to non-Perl 6 objects leaking out at
unexpected ends. If you ever got a &quot;Null PMC Access&quot; from Rakudo, you know what I
mean.&lt;/p&gt;

&lt;p&gt;The lesson we learned was that &lt;strong&gt;you need a Perl 6 compiler to
implement a Perl 6 compiler&lt;/strong&gt;, even if that first Perl 6 compiler can
handle only a rather limited subset of Perl 6.&lt;/p&gt;


&lt;p&gt;And there are also quite some benefits to this approach. For example &lt;a
    href=&quot;http://pmthium.com/2011/07/14/new-regex-engine-for-nqp-and-nom-now-passing-7k-spectests/&quot;&gt;NQP's new
    regex engine&lt;/a&gt; is implemented as a role in NQP. It is mixed into an NQP
class which allows us to build Rakudo, but it is also mixed in a Perl 6 class,
which allows the generation of &lt;a
href=&quot;http://perlcabal.org/syn/S05.html#Match_objects&quot;&gt;Perl 6-level Match
objects&lt;/a&gt; without any need to create NQP-level match objects first, and then
wrap them in Perl 6 Match objects.&lt;/p&gt;

&lt;p&gt;That's what NQP does for us. It allows us to actually write a Perl 6
compiler.&lt;/p&gt;


</description>
  </item>
 
</rdf:RDF>
