By Chris McCord

Write code that writes code with Elixir macros. Macros make metaprogramming attainable and outline the language itself. during this ebook, you are going to easy methods to use macros to increase the language with quick, maintainable code and percentage performance in methods you by no means concept attainable. you will find the right way to expand Elixir together with your personal first class positive aspects, optimize functionality, and create domain-specific languages.

Metaprogramming is one in all Elixir's maximum beneficial properties. probably you could have performed with the fundamentals or written a number of macros. Now you must 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 are going to expand Elixir with strong positive aspects and write speedier, extra maintainable courses in methods unequalled via different languages.

You'll begin with the fundamentals of Elixir's metaprogramming procedure and learn how macros engage with Elixir's summary layout. Then you will expand Elixir along with your personal firstclass positive aspects, write a checking out framework, and notice how Elixir treats resource code as development blocks, instead of rote strains of directions. you are going to proceed your trip by utilizing complex code iteration to create crucial libraries in strikingly few traces of code. eventually, you will create domain-specific languages and study whilst and the place to use your talents effectively.

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

Show description

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

Similar compilers books

Joel on Software: And on Diverse and Occasionally Related Matters That Will Prove of Interest to Software Developers, Designers, and Managers, and to Those Who, Whether by Good Fortune or Ill Luck, Work with Them in Some Capacity

Joel Spolsky all started his mythical net log, www. joelonsoftware. com, in March 2000, so that it will provide insights for making improvements to the realm of programming. Spolsky established those observations on years of private event. the end result only a handful of years later? Spolsky's technical wisdom, caustic wit, and striking writing talents have earned him prestige as a programming guru!

From Linear Operators to Computational Biology Essays in Memory of Jacob T. Schwartz

Foreword. - creation. - Nature as Quantum computing device. - Jack Schwartz Meets Karl Marx. - SETL and the Evolution of Programming. - determination technique for common Sublanguages of Set conception XVII: regularly happening Decidable Extensions of Multi-level Syllogistic. - Jack Schwartz and Robotics: The Roaring Eighties.

Principles of Compilers: A New Approach to Compilers Including the Algebraic Method

"Principles of Compilers: a brand new method of Compilers together with the Algebraic technique" introduces the tips of the compilation from the average intelligence of people by means of evaluating similarities and alterations among the compilations of traditional languages and programming languages. The notation is created to record the resource language, aim languages, and compiler language, vividly illustrating the multilevel strategy of the compilation within the method.

Formal Techniques for Safety-Critical Systems: Third International Workshop, FTSCS 2014, Luxembourg, November 6-7, 2014. Revised Selected Papers

This e-book constitutes the refereed lawsuits of the 3rd foreign Workshop on Formal recommendations for Safety-Critical structures, FTSCS 2014, held in Luxembourg, in November 2014. The 14 revised complete papers offered including invited talks have been rigorously reviewed and chosen from forty submissions.

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

Sample text

Looping! looping! ^C^C Our first step is complete. We were able to repeatedly execute a block of code given an expression. Now we need the ability to break out of execution once the expression is no longer true. Elixir’s for comprehension has no built-in way to terminate early, but with a careful try/catch block, we can throw a value to stop execution. Let’s throw and catch a :break value to halt the infinite loop. cycle([:ok]) do if unquote(expression) do unquote(block) else throw :break end end catch :break -> :ok end end end end report erratum • discuss Custom Language Constructs • 25 On line 5, we wrapped our entire for comprehension within a try/catch block.

We experimented with explicitly overriding hygiene and explored the different contexts a macro enters throughout its lifecycle. We’ll use these virtues to drive our implementations throughout the rest of this book. Further Exploration We’ve unlocked the secrets of the abstract syntax tree that underlies all the Elixir code you write. Through quoting expressions, manipulating ASTs, and defining macros, you’re well on your way to advanced metaprogramming. In the coming chapter, we’ll be building more advanced macros to create custom language constructs, and we’ll write a mini testing framework that can infer meaning about Elixir expressions.

We call the place where code is injected a context. A context is the scope of the caller’s bindings, imports, and aliases. To the caller of a macro, the context is precious. It holds your view of the world, and by virtue of immutability, you don’t expect your variables, imports, and aliases to change out from underneath you. Elixir macros strike an excellent balance for safeguarding your context while allowing explicit access where neccesary. Let’s see how to inject code safely and the available tools to reach into the caller’s context when necessary.

Download PDF sample

Metaprogramming Elixir: Write Less Code, Get More Done (and by Chris McCord
Rated 4.07 of 5 – based on 15 votes