By Chris McCord

Write code that writes code with Elixir macros. Macros make metaprogramming attainable and outline the language itself. during this booklet, you are going to how to use macros to increase the language with speedy, maintainable code and percentage performance in methods you by no means inspiration attainable. you will discover the way to expand Elixir along with your personal first class positive factors, optimize functionality, and create domain-specific languages.

Metaprogramming is considered one of Elixir's maximum beneficial properties. possibly you will have performed with the fundamentals or written a couple of macros. Now you must take it to the subsequent point. This booklet is a guided sequence of metaprogramming tutorials that take you step-by-step to metaprogramming mastery. you will expand Elixir with robust beneficial properties and write swifter, extra maintainable courses in methods unequalled by means of different languages.

You'll commence with the fundamentals of Elixir's metaprogramming procedure and learn the way macros engage with Elixir's summary layout. Then you will expand Elixir together with your personal first class gains, write a trying out framework, and observe how Elixir treats resource code as construction blocks, instead of rote traces of directions. you are going to proceed your trip through the use of complex code iteration to create crucial libraries in strikingly few strains of code. eventually, you are going to create domain-specific languages and examine while and the place to use your abilities effectively.

When you are performed, you've mastered metaprogramming, received insights into Elixir's internals, and feature the arrogance to leverage macros to their complete capability on your personal projects.

Show description

Read or Download Metaprogramming Elixir: Write Less Code, Get More Done (and Have Fun!) PDF

Similar compilers books

The Definitive Guide to SugarCRM: Better Business Applications (Books for Professionals by Professionals)

SugarCRM is certainly one of if now not the best Open resource CRM resolution available to buy at five. five million downloads and starting to be and with approximately 17,000 registered builders and plenty extra clients. this may be the authentic, definitive ebook written by way of SugarCRM and recommended by way of SugarCRM. additionally, this e-book will be additionally the single SugarCRM developer ebook so that it will tackle the platform comparable good points due to the fact SugarCRM five.

Methodologies and Software Engineering for Agent Systems: The Agent-Oriented Software Engineering Handbook

As info applied sciences develop into more and more disbursed and available to greater variety of humans and as advertisement and govt companies are challenged to scale their functions and companies to greater marketplace stocks, whereas lowering bills, there's call for for software program methodologies and appli- tions to supply the next beneficial properties: Richer program end-to-end performance; aid of human involvement within the layout and deployment of the software program; Flexibility of software program behaviour; and Reuse and composition of current software program functions and platforms in novel or adaptive methods.

Numeric Computation and Statistical Data Analysis on the Java Platform

Numerical computation, wisdom discovery and statistical information research built-in with strong second and 3D pix for visualisation are the foremost issues of this ebook. The Python code examples powered through the Java platform can simply be reworked to different programming languages, akin to Java, Groovy, Ruby and BeanShell.

Additional resources for Metaprogramming Elixir: Write Less Code, Get More Done (and Have Fun!)

Sample text

The run function definition was expanded within the MathTest module at our use Assertion declaration. The result is that run/0 was expanded in MathTest before any of the test macro accumulations were registered. We report erratum • discuss Compile-Time Hooks • 39 need a way to delay macro expansion until after we’ve done some code-generation work. Elixir provides a before_compile hook for this purpose. Compile-Time Hooks Elixir allows us to set a special module attribute, @before_compile, to notify the compiler that an extra step is required just before compilation is finished.

Extend macro. extend is just a regular macro that returned an AST containing the run/0 definition. This example underlines the building-block nature of Elixir’s code construction. With no other mechanism than defmacro and quote, we defined a function within another module! use: A Common API for Module Extension One reoccurring theme that you may have noticed in many Elixir libraries is the prevalence of the use SomeModule syntax. You have probably typed it many times in your own projects without fully understanding what it does.

Break end end catch :break -> :ok end end end 20 def break, do: throw :break end report erratum • discuss Chapter 2. Extending Elixir with Metaprogramming • 26 On line 19, we defined a break function for the caller that throws the :break value. The caller could throw the value, but providing a high-level break function abstracts the internal implementation and unifies the termination with the while macro. 0> iex> send pid, :hello Got :hello :hello iex> send pid, :ping Got :ping :ping iex> send pid, :stop Stopping...

Download PDF sample

Rated 4.00 of 5 – based on 25 votes