Skip to content

Commit

Permalink
Adding some macro features refs #2514
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ committed Dec 23, 2018
1 parent ff236f4 commit 909627c
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions doc/Language/experimental.pod6
Expand Up @@ -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<quasi> is the
routine that performs this task.
=begin code :skip-test<need use experimental>
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<need use experimental>
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<need use experimental>
macro is-mighty( $who ) {
quasi { {{{$who}}} ~ " is mighty!"}
};
say is-mighty "Freija";# OUTPUT: «Freija is mighty!␤»
=end code
=end pod
Expand Down

0 comments on commit 909627c

Please sign in to comment.