From 909627c51d70e8c4e3a7db0fa29b32da5644ae1a Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Sun, 23 Dec 2018 10:04:38 +0100 Subject: [PATCH] Adding some macro features refs #2514 --- doc/Language/experimental.pod6 | 37 ++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) 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