Metaprogramming Elixir: Write Less Code, Get More Done (and by Chris McCord

By Chris McCord

Write code that writes code with Elixir macros. Macros make metaprogramming attainable and outline the language itself. during this ebook, you will find out how to use macros to increase the language with quickly, maintainable code and percentage performance in methods you by no means inspiration attainable. you will discover the right way to expand Elixir together with your personal first class beneficial properties, optimize functionality, and create domain-specific languages.

Metaprogramming is one in every of Elixir's maximum beneficial properties. possibly you've gotten performed with the fundamentals or written a couple of macros. Now you need to take it to the following point. This publication is a guided sequence of metaprogramming tutorials that take you step-by-step to metaprogramming mastery. you will expand Elixir with robust positive factors and write quicker, extra maintainable courses in methods unrivaled through different languages.

You'll commence with the fundamentals of Elixir's metaprogramming process and learn the way macros have interaction with Elixir's summary layout. Then you will expand Elixir together with your personal firstclass positive factors, write a checking out framework, and realize how Elixir treats resource code as development blocks, instead of rote strains of directions. you will proceed your trip by utilizing complex code iteration to create crucial libraries in strikingly few traces of code. ultimately, you are going to create domain-specific languages and research while and the place to use your abilities effectively.

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

Show description

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

Best compilers books

Constraint Databases

This e-book is the 1st accomplished survey of the sphere of constraint databases. Constraint databases are a reasonably new and lively region of database examine. the major concept is that constraints, resembling linear or polynomial equations, are used to symbolize huge, or perhaps limitless, units in a compact method.

Principles of Program Analysis

Application research makes use of static options for computing trustworthy information regarding the dynamic habit of courses. purposes contain compilers (for code improvement), software program validation (for detecting mistakes) and differences among information illustration (for fixing difficulties equivalent to Y2K). This booklet is exclusive in offering an summary of the 4 significant methods to software research: info stream research, constraint-based research, summary interpretation, and kind and impact platforms.

R for Cloud Computing: An Approach for Data Scientists

R for Cloud Computing appears at a few of the initiatives played through enterprise analysts at the machine (PC period) and is helping the person navigate the wealth of data in R and its 4000 applications in addition to transition a similar analytics utilizing the cloud. With this knowledge the reader can choose either cloud proprietors and the occasionally complicated cloud atmosphere in addition to the R programs which can aid method the analytical initiatives with minimal attempt, rate and greatest usefulness and customization.

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

Example text

Our macro will peek inside the representation of the assertions in order to print the correct test output. run .. FAILURE: Expected: 10 to be less than: 1 As always, we’ll start small by experimenting in iex with a few example expressions that our macro will accept: iex> quote do: 5 == 5 {:==, [context: Elixir, import: Kernel], [5, 5]} iex> quote do: 2 < 10 {:<, [context: Elixir, import: Kernel], [2, 10]} A simple numerical comparison yields a straightforward AST. We received the operator as an atom, representing the Kernel function call to perform, and the left-hand side and right-hand side values are contained in the list of arguments.

Assert(unquote(operator), unquote(lhs), unquote(rhs)) end Using bind_quoted here doesn’t gain us much, but let’s imagine a different example to see why using it is good practice. inspect on the results only when in debug mode. puts "=================" unquote(expression) end else expression end end end report erratum • discuss Chapter 2. log macro that accepts an expression. If the configured :log_level at compile time is :debug, we print a debug output of the expression on line 6. After printing, we execute the expression as normal on line 8.

Html report erratum • discuss Building an Internationalization Library • 49 Building an Internationalization Library Almost all user-facing applications are best served by an internationalization layer where language snippets can be stored and referenced programmatically. Let’s use code generation to produce an internationalization library in fewer lines of code than you thought possible. This is the most advanced exercise you’ve done so far, so let’s start by breaking down our implementation into a rubric that you can use to attack complex metaprogramming problems.

Download PDF sample

Rated 4.98 of 5 – based on 24 votes