diff --git a/doc/Language/experimental.pod6 b/doc/Language/experimental.pod6 index f545d4144..8aaf49413 100644 --- a/doc/Language/experimental.pod6 +++ b/doc/Language/experimental.pod6 @@ -33,8 +33,41 @@ on via the pragma use experimental :macros; -Macro processing happens during parsing time. - +Macro processing happens during parsing time. A macro generates an abstract +syntax tree, which is grafted into the program syntax tree. C is the +routine that performs this task. + +=begin code :skip-test +macro does-nothing() { + quasi {} +}; +does-nothing; # OUTPUT: «» +=end code + +X<|quasi (macros)> +Macros are a kind of routine, so they can take arguments in exactly the same +way, and act also in almost the same way. + +=begin code :skip-test +macro is-mighty( $who ) { + quasi { "$who is mighty!"} +}; +say is-mighty "Freija"; # OUTPUT: « "Freija" is mighty!␤» +=end code + +X<|unquoting (macros)> +X<|{{{}}} (macros)> +"Almost" accounts for the fact that the argument is inserted as a literal, +including the quotes. Please note that we can also eliminate the parentheses for +a macro call, following the same rules as a routine. You can use the unquoting +construct C<{{{}}}> to get rid of this kind of thing: + +=begin code :skip-test +macro is-mighty( $who ) { + quasi { {{{$who}}} ~ " is mighty!"} +}; +say is-mighty "Freija";# OUTPUT: «Freija is mighty!␤» +=end code =end pod