{"id":489,"date":"2010-06-10T22:20:28","date_gmt":"2010-06-10T21:20:28","guid":{"rendered":"http:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/"},"modified":"2010-06-10T22:20:28","modified_gmt":"2010-06-10T21:20:28","slug":"perl6-hacking-grammars-digestmd5-and-caffeine-levels","status":"publish","type":"post","link":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/","title":{"rendered":"Perl6 hacking, grammars, Digest::MD5 and caffeine levels"},"content":{"rendered":"<p>I&#39;ll be brief. Need some sleep. :)<\/p>\n<p><span class='imgright'><img alt='' src='http:\/\/files.myopera.com\/cstrep\/blog\/camelia-logo.png' \/><\/span> <a href=\"http:\/\/www.rakudo.org\" rel=\"nofollow\">Perl 6 is here. Now.<\/a> And there&#39;s an immense work waiting to be done: rewriting Perl5&#39;s CPAN. Ain&#39;t that easy? :)<\/p>\n<p>Anyway, during last couple of weeks, I spent most of my spare time playing with Perl 6:<\/p>\n<ul>\n<li><a href=\"http:\/\/github.com\/cosimo\/perl6-puppet-parser\" rel=\"nofollow\">learning how <b>Grammars<\/b> work<\/a>, and that&#39;s an astonishingly powerful feature<\/li>\n<li>Porting <a href=\"http:\/\/search.cpan.org\/dist\/Digest-MD5\" rel=\"nofollow\">Perl5&#39;s Digest::MD5 module<\/a> to Perl 6<\/li>\n<li>Improving how the <a href=\"http:\/\/perlcabal.org\/syn\/\" rel=\"nofollow\">official spec documents for Perl 6<\/a> look<\/li>\n<\/ul>\n<h2>Grammars<\/h2>\n<p>My poor excuse to (try to) learn grammars was to build a Perl6 class that could parse a <a href=\"http:\/\/www.puppetlabs.com\" rel=\"nofollow\">puppet<\/a> module and build some documentation for it. Puppet itself uses a grammar to parse its modules, so I thought it wouldn&#39;t be impossible to port it to Perl6 and use it to parse puppet code.<\/p>\n<p>Well, turns out it&#39;s not so easy, but at least I&#39;m learning how grammars work and having fun.<\/p>\n<h2>Perl6 Digest::MD5<\/h2>\n<p>This is extremely fascinating, because it&#39;s touching the <a href=\"http:\/\/www.parrot.org\" rel=\"nofollow\">Parrot core<\/a>. In Parrot, there&#39;s already a <b>Digest::MD5<\/b> module, so all you have to do (but again, not so easy), is to write a Perl6 &quot;wrapper&quot; around the Parrot code.<\/p>\n<p>And how do you do that? With <a href=\"http:\/\/en.wikipedia.org\/wiki\/Parrot_intermediate_representation\" rel=\"nofollow\"><code>PIR<\/code> blocks<\/a>. This stuff is great. Seriously. It&#39;s like going back to Assembly, in some sense(tm). Here&#39;s an example of this <b>glue PIR code<\/b>:<\/p>\n<pre>class Digest::MD5 {\r\n\r\n    multi method md5_hex (Str $message) {\r\n\r\n        pir::load_bytecode(&#39;Digest\/MD5.pbc&#39;);\r\n\r\n        my $md5_sum = Q:PIR {\r\n            .local pmc md5sum, md5_sum_get\r\n            md5sum = get_root_global [&#39;parrot&#39;; &#39;Digest&#39;], &#39;_md5sum&#39;\r\n            $P0 = find_lex &#39;$message&#39;\r\n            $P1 = md5sum($P0)\r\n            md5_sum_get = get_root_global [&#39;parrot&#39;; &#39;Digest&#39;], &#39;_md5_hex&#39;\r\n            %r = md5_sum_get($P1)\r\n        };\r\n\r\n        return $md5_sum;\r\n    }\r\n\r\n    multi method md5_hex (@message) {\r\n        my Str $message = @message.join(&#39;&#39;);\r\n        return Digest::MD5.md5_hex($message);\r\n    }\r\n\r\n}\r\n<\/pre>\n<p>Even if you don&#39;t understand Perl 6 or PIR, you can probably recognize a <b>class definition<\/b>, and <b>polimorphic methods<\/b>. <code>md5_hex()<\/code> is in fact defined twice:<\/p>\n<ul>\n<li><code>multi method md5_hex (Str $message)<\/code><\/li>\n<li><code>multi method md5_hex (@message)<\/code><\/li>\n<\/ul>\n<p>You don&#39;t have to write polimorphic methods, but you <b>can do it<\/b> if you want. Yes, there&#39;s more than one way, and there always will be. I don&#39;t like dictators, even if they are benevolent, and Python code looks so flat and dull, seriously. There&#39;s no personality in Python code. Yes, sigils are great.<\/p>\n<p>Digest::MD5 is also using <a href=\"http:\/\/github.com\/masak\/ufo\" rel=\"nofollow\">alien technology (UFO)<\/a>.<\/p>\n<h2>Synopsis documents<\/h2>\n<p>Nothing fancy there, just improved the existing CSS. For an example, go read <a href=\"http:\/\/perlcabal.org\/syn\/S03.html\" rel=\"nofollow\">Synopsis 03<\/a> about operators.<\/p>\n<p>Good night!<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#39;ll be brief. Need some sleep. :) Perl 6 is here. Now. And there&#39;s an immense work waiting to be done: rewriting Perl5&#39;s CPAN. Ain&#39;t that easy? :) Anyway, during last couple of weeks, I spent most of my spare time playing with Perl 6: learning how Grammars work, and that&#39;s an astonishingly powerful feature [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[410,288,50,426,290,408,286,425],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Perl6 hacking, grammars, Digest::MD5 and caffeine levels - Random hacking<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Perl6 hacking, grammars, Digest::MD5 and caffeine levels - Random hacking\" \/>\n<meta property=\"og:description\" content=\"I&#039;ll be brief. Need some sleep. :) Perl 6 is here. Now. And there&#039;s an immense work waiting to be done: rewriting Perl5&#039;s CPAN. Ain&#039;t that easy? :) Anyway, during last couple of weeks, I spent most of my spare time playing with Perl 6: learning how Grammars work, and that&#039;s an astonishingly powerful feature [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/\" \/>\n<meta property=\"og:site_name\" content=\"Random hacking\" \/>\n<meta property=\"article:published_time\" content=\"2010-06-10T21:20:28+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/files.myopera.com\/cstrep\/blog\/camelia-logo.png\" \/>\n<meta name=\"author\" content=\"cosimo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"cosimo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/\"},\"author\":{\"name\":\"cosimo\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"headline\":\"Perl6 hacking, grammars, Digest::MD5 and caffeine levels\",\"datePublished\":\"2010-06-10T21:20:28+00:00\",\"dateModified\":\"2010-06-10T21:20:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/\"},\"wordCount\":346,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"image\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/files.myopera.com\/cstrep\/blog\/camelia-logo.png\",\"keywords\":[\"digest::md5\",\"grammars\",\"perl\",\"perl5\",\"perl6\",\"pir\",\"rakudo\",\"synopses\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/\",\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/\",\"name\":\"Perl6 hacking, grammars, Digest::MD5 and caffeine levels - Random hacking\",\"isPartOf\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/files.myopera.com\/cstrep\/blog\/camelia-logo.png\",\"datePublished\":\"2010-06-10T21:20:28+00:00\",\"dateModified\":\"2010-06-10T21:20:28+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/#primaryimage\",\"url\":\"http:\/\/files.myopera.com\/cstrep\/blog\/camelia-logo.png\",\"contentUrl\":\"http:\/\/files.myopera.com\/cstrep\/blog\/camelia-logo.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.streppone.it\/cosimo\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Perl6 hacking, grammars, Digest::MD5 and caffeine levels\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#website\",\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/\",\"name\":\"Random hacking\",\"description\":\"Assume nothing. Code defensively. Keep it simple, stupid!\",\"publisher\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.streppone.it\/cosimo\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\",\"name\":\"cosimo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g\",\"caption\":\"cosimo\"},\"logo\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/author\/cosimo\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Perl6 hacking, grammars, Digest::MD5 and caffeine levels - Random hacking","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/","og_locale":"en_US","og_type":"article","og_title":"Perl6 hacking, grammars, Digest::MD5 and caffeine levels - Random hacking","og_description":"I&#39;ll be brief. Need some sleep. :) Perl 6 is here. Now. And there&#39;s an immense work waiting to be done: rewriting Perl5&#39;s CPAN. Ain&#39;t that easy? :) Anyway, during last couple of weeks, I spent most of my spare time playing with Perl 6: learning how Grammars work, and that&#39;s an astonishingly powerful feature [&hellip;]","og_url":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/","og_site_name":"Random hacking","article_published_time":"2010-06-10T21:20:28+00:00","og_image":[{"url":"http:\/\/files.myopera.com\/cstrep\/blog\/camelia-logo.png"}],"author":"cosimo","twitter_card":"summary_large_image","twitter_misc":{"Written by":"cosimo","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/#article","isPartOf":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/"},"author":{"name":"cosimo","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"headline":"Perl6 hacking, grammars, Digest::MD5 and caffeine levels","datePublished":"2010-06-10T21:20:28+00:00","dateModified":"2010-06-10T21:20:28+00:00","mainEntityOfPage":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/"},"wordCount":346,"commentCount":0,"publisher":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"image":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/#primaryimage"},"thumbnailUrl":"http:\/\/files.myopera.com\/cstrep\/blog\/camelia-logo.png","keywords":["digest::md5","grammars","perl","perl5","perl6","pir","rakudo","synopses"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/","url":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/","name":"Perl6 hacking, grammars, Digest::MD5 and caffeine levels - Random hacking","isPartOf":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/#primaryimage"},"image":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/#primaryimage"},"thumbnailUrl":"http:\/\/files.myopera.com\/cstrep\/blog\/camelia-logo.png","datePublished":"2010-06-10T21:20:28+00:00","dateModified":"2010-06-10T21:20:28+00:00","breadcrumb":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/#primaryimage","url":"http:\/\/files.myopera.com\/cstrep\/blog\/camelia-logo.png","contentUrl":"http:\/\/files.myopera.com\/cstrep\/blog\/camelia-logo.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2010\/06\/perl6-hacking-grammars-digestmd5-and-caffeine-levels\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.streppone.it\/cosimo\/blog\/"},{"@type":"ListItem","position":2,"name":"Perl6 hacking, grammars, Digest::MD5 and caffeine levels"}]},{"@type":"WebSite","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#website","url":"https:\/\/www.streppone.it\/cosimo\/blog\/","name":"Random hacking","description":"Assume nothing. Code defensively. Keep it simple, stupid!","publisher":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.streppone.it\/cosimo\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1","name":"cosimo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g","caption":"cosimo"},"logo":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/"},"url":"https:\/\/www.streppone.it\/cosimo\/blog\/author\/cosimo\/"}]}},"_links":{"self":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts\/489"}],"collection":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/comments?post=489"}],"version-history":[{"count":0,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts\/489\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/media?parent=489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/categories?post=489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/tags?post=489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}