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:

  1. 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.

  1. 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>.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset