Exercises
If you are already finding macros empowering, here are some exercises for you to try so that you can tinker with macros some more:
- Write a macro that accepts the following language:
language = HELLO recipient; recipient = <String>;
For instance, the following strings would be acceptable in this language:
HELLO world! HELLO Rustaceans!
Make the macro generate code that outputs a greeting that's directed to the recipient.
- Write a macro that takes an arbitrary number of elements and outputs an unordered HTML list in a literal string, for instance,
html_list!([1, 2]) => <ul><li>1/<li><li>2</li></ul>
.