About This Title

Pages: 128
Published: January 2015
ISBN: 9781680500417
In Print

Metaprogramming Elixir

Write Less Code, Get More Done (and Have Fun!)

by Chris McCord

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.

eBook Formats:

  • PDF for desktop/tablets

  • epub for Apple Books, e-readers

  • mobi for Kindle readers

Get all eBook formats here for $11.00 (USD)

Add to Cart we accept visa, mastercard, amex, discover, paypal


Paperback Formats:

Please support indie bookstores!
Find indie bookstores in the U.S. Find indie bookstores around the world.


Metaprogramming is one of Elixir’s greatest features. Maybe you’ve played with the basics or written a few macros. Now you want to take it to the next level. This book is a guided series of metaprogramming tutorials that take you step by step to metaprogramming mastery. You’ll extend Elixir with powerful features and write faster, more maintainable programs in ways unmatched by other languages.

You’ll start with the basics of Elixir’s metaprogramming system and find out how macros interact with Elixir’s abstract format. Then you’ll extend Elixir with your own first-class features, write a testing framework, and discover how Elixir treats source code as building blocks, rather than rote lines of instructions. You’ll continue your journey by using advanced code generation to create essential libraries in strikingly few lines of code. Finally, you’ll create domain-specific languages and learn when and where to apply your skills effectively.

When you’re done, you will have mastered metaprogramming, gained insights into Elixir’s internals, and have the confidence to leverage macros to their full potential in your own projects.

What You Need

You’ll need a computer, Elixir 1.x, and have a solid grasp of Elixir basics.

Resources

Releases:

  • P1.0 2015/01/27

Contents & Extracts

  • Acknowledgements
  • Introduction
    • Metaprogramming—An Essential Feature
    • How to Read This Book
    • Running the Code Exercises
    • Online Resources
  • The Language of Macros excerpt
    • The World Is Your Playground
    • Macro Rules
    • The Abstract Syntax Tree—Demystified
    • Macros: The Building Blocks of Elixir
    • Code Injection and the Caller’s Context
    • Further Exploration
  • Extending Elixir with Metaprogramming
    • Custom Language Constructs
    • Smarter Testing with Macros
    • Extending Modules
    • Using Module Attributes for Code Generation
    • Compile-Time Hooks
    • Further Exploration
  • Advanced Compile-Time Code Generation
    • Generating Functions from External Data
    • MIME-Type Conversion in Ten Lines of Code
    • Building an Internationalization Library excerpt
    • Code Generation from Remote APIs
    • Further Exploration
  • How to Test Macros
    • Setting Up Your Test Suite
    • Deciding What to Test
    • Integration Testing
    • Unit Tests
    • Test Simple and Test Fast
    • Further Exploration
  • Creating an HTML Domain-Specific Language
    • Getting Domain Specific
    • Start by Defining the Minimum Viable API
    • Support the Entire HTML Spec with Macros
    • Enhance Your API with HTML Attribute Support
    • Generate Less Code by Walking the AST
    • To DSL or Not to DSL?
    • Further Exploration
  • With Great Power Comes Great Responsibility (and Fun!)
    • When and Where to Use Macros
    • Avoiding Common Pitfalls
    • Bending the Rules
    • Build the Future

Author

Chris McCord is a programmer with a passion for science and building things. He spends his free time crafting the Phoenix Web Framework, speaking at conferences, and teaching others the tools of the trade. He loves community outreach and helping to grow Elixir’s wonderful community.

eBook Formats:

  • PDF for desktop/tablets

  • epub for Apple Books, e-readers

  • mobi for Kindle readers

Get all eBook formats here for $11.00 (USD)

Add to Cart we accept visa, mastercard, amex, discover, paypal


Paperback Formats:

Please support indie bookstores!
Find indie bookstores in the U.S. Find indie bookstores around the world.

Related Titles:

About This Title

Pages: 128
Published: January 2015
ISBN: 9781680500417
Edition: 1
In Print