Grant Report: Implementation of Macros in Rakudo

Carl Mäsak writes:

This is a report on the progress that I have made with my current Hague Grant, Implementation of macros in Rakudo. We're now at the halfway point of the grant, and Rakudo has an early, working implementation of macros.

Here is the status of the deliverables identified in the original report:

D1. (Macro declarations and invocation. Rudimentary quasiquotes.) Completed. In Rakudo, you can now declare macros just like you declare ordinary subroutines. There's also a quasi block construct, often used inside the macro body to "quote" a piece of code as an abstract syntax tree (AST) and return it in this form to the caller. Finally, macro expansion works, which means that AST so returned gets spliced into the mainline code and gets run at runtime. My progress is summarized in these blog posts: one, two, three.

D2. (Quasiquote splicing.) Completed. Subexpressions in a quasi block surrounded with {{{ }}} delimiters are evaluated at quasi evaluation time, and their value is expected to be an AST, which is spliced into the quasi AST. Special care has to be taken to preserve the original lexical context of the things spliced in. The support for this had to be coded both in nqp and Rakudo. My progress is summarized in these blog posts: one, two.

D3. (Hygienic macros and the COMPILING:: pseudopackage.) Underway. In the current implementation, macros are already hygienic. Making them (optionally) unhygienic is supposed to happen through the COMPILING:: pseudopackage, which provides a sort of escape hatch back to the mainline code and its lexical context. This is what I expect to do next.

D4. ("Delayed" declarations of routines and types within quasiquotes.) Not started yet.

D5. (Updates to the S06 to align the spec with the implementation.) The synopsis has stood up unexpectedly well in the face of implementation, and has been a big help in clarifying semantics in some cases. I have discussed extensively with Larry Wall and Jonathan Worthington about whether the {{{ }}} syntax needs to be replaced with something more generic. This ongoing discussion is expected to eventually land in S06 and STD.pm6 as changes.

D6. (Spectests to cover the implemented features.) Two new spectest files cover the new macro features implemented in Rakudo, including some tests for bugs that were discovered along the way. All tests pass. The test files exercise quasi blocks and unquoting, respectively. We've also started passing a couple of tests from a pre-existing test file exercising opaque ASTs.

D7. (Regular reports on implementation progress.) Though I hesitate to call the reports "regular", I have blogged about my progress whenever the implementation has taken yet another step forward. Furthermore, it turns out that writing pieces smaller than blog posts and publishing them as gists helps a lot in advancing discussion and understanding of macros. I've made sure to link to any such gists from the subsequent blog post.

I'd like to thank Ian Hague and the Perl Foundation for funding this grant. I'd also like to take a moment to thank the community for their patience and support with regard to my work on this grant so far — it's wonderful to be a part of it, and to work with so many great people.

About TPF

The Perl Foundation - supporting the Perl community since 2000. Find out more at

About this Entry

This page contains a single entry by Karen Pauley published on December 2, 2012 10:51 PM.

Alien::Base Grant - Report #7 was the previous entry in this blog.

Improving Perl 5: Grant Report for Month 14 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

OpenID accepted here Learn more about OpenID
Powered by Movable Type 4.38