Metaprogramming Elixir

Book description

Write code that writes code with Elixir macros. Macros make metaprogramming possible and define the language itself. In this book, you'll learn how to use macros to extend the language with fast, maintainable code and share functionality in ways you never thought possible. You'll discover how to extend Elixir with your own first-class features, optimize performance, and create domain-specific languages.

Publisher resources

View/Submit Errata

Table of contents

  1. Metaprogramming Elixir
    1. Copyright
    2. For the Best Reading Experience...
    3. ​Dedication
    4. Table of Contents
    5. Early praise for Metaprogramming Elixir
    6. Acknowledgements
    7. Introduction
      1. Metaprogramming—An Essential Feature
      2. How to Read This Book
      3. Running the Code Exercises
      4. Online Resources
    8. Chapter 1: The Language of Macros
      1. The World Is Your Playground
      2. Macro Rules
      3. The Abstract Syntax Tree—Demystified
      4. Macros: The Building Blocks of Elixir
      5. Code Injection and the Caller’s Context
      6. Further Exploration
    9. Chapter 2: Extending Elixir with Metaprogramming
      1. Custom Language Constructs
      2. Smarter Testing with Macros
      3. Extending Modules
      4. Using Module Attributes for Code Generation
      5. Compile-Time Hooks
      6. Further Exploration
    10. Chapter 3: Advanced Compile-Time Code Generation
      1. Generating Functions from External Data
      2. MIME-Type Conversion in Ten Lines of Code
      3. Building an Internationalization Library
      4. Code Generation from Remote APIs
      5. Further Exploration
    11. Chapter 4: How to Test Macros
      1. Setting Up Your Test Suite
      2. Deciding What to Test
      3. Integration Testing
      4. Unit Tests
      5. Test Simple and Test Fast
      6. Further Exploration
    12. Chapter 5: Creating an HTML Domain-Specific Language
      1. Getting Domain Specific
      2. Start by Defining the Minimum Viable API
      3. Support the Entire HTML Spec with Macros
      4. Enhance Your API with HTML Attribute Support
      5. Generate Less Code by Walking the AST
      6. To DSL or Not to DSL?
      7. Further Exploration
    13. Chapter 6: With Great Power Comes Great Responsibility (and Fun!)
      1. When and Where to Use Macros
      2. Avoiding Common Pitfalls
      3. Bending the Rules
      4. Build the Future
      5. You May Be Interested In…

Product information

  • Title: Metaprogramming Elixir
  • Author(s): Chris McCord
  • Release date: January 2015
  • Publisher(s): Pragmatic Bookshelf
  • ISBN: 9781680500417