axelson

axelson

Scenic Core Team

Here’s today’s talk:

ElixirConf 2017 - Don’t Write Macros But Do Learn How They Work - by @jessejanderson

You may have heard that “most of Elixir was written in Elixir” but what does that even mean, and how is that possible? Metaprogramming allows us to write code that writes code and, in addition to powering most of Elixir itself, has allowed for many great projects including Phoenix to exist. Even if you don’t have ambitions to create the next Phoenix, understanding metaprogramming basics and learning how the Elixir expressions work under the hood can lead to greater understanding of the code you write every day.

All talks are available in the Elixir Conf 2017 Talks List

Showing Posts 1 to 10

sillypog

sillypog

I really enjoyed both this and Jesse’s previous talk at Erlang & Elixir Factory '17. He’s an entertaining speaker who gives really great breakdowns of these aspects of Elixir that newcomers to the language can get tripped up on.

JEG2

JEG2

Author of Designing Elixir Systems with OTP

I agree that it was a solid introductory presentation. I found myself wishing it went a touch deeper, but I did enjoy it.

axelson

axelson OP

Scenic Core Team

Having not delved into the AST form of Elixir I felt that this was a solid presentation on how to use macros. I especially liked the use of pattern matching with defmacro since I can see many ways that could be useful. It was definitely well presented and I liked the use of color/fading to highlight portions of code.

However, I do have a question. Why was the two element tuple made a literal but an empty tuple ({}), and a single-element tuple ({:example}) are not literals? It seems like it would be easier/more consistent for all tuples to be treated equally. If I had to take a stab at it, I would guess that it is somehow related to S-expressions and Lisp.

kylethebaker

kylethebaker

The reason that two-element tuples are special is so that keyword lists can be special. See the mailing list thread where José confirms it.

Zero and one item tuples could be special too, but I don’t think three item tuples could be. Since lists and atoms are literal I think there could be ambiguity between AST nodes and values. Something like {:x, [], []} might be representing x() or it might be the literal value {:x, [], []}.

So I think it could be either “all tuples are literals, except three item tuples”, or it could be “only two element tuples are literals”. I think having a single case where the rule doesn’t apply is more confusing than having a single case where the rule does apply. Though it could be that there is no ambiguity with three item tuples and I’m just overlooking something.

OvermindDL1

OvermindDL1

I actually really really really hate that things like 2-element tuples and literals are special cased, they lose their source positions and meta information. I wish everything, absolutely everything were 3-tuples.

Thankfully you can wrap literals in blocks to recover meta information, but you cannot do that to 2-tuples as things break I found out.

brightball

brightball

Thanks for taking over the posting responsibility for these videos. I’ve been really busy lately.

axelson

axelson OP

Scenic Core Team

You’re welcome! I think the discussion is very valuable :slight_smile:

jessejanderson

jessejanderson

Thanks for the feedback everyone, I really appreciate it!

@sillypog
Great to see you again at the conf - thanks for the kind words! The trick I’ve found is to trip up a lot myself, and then just try to document everything that didn’t make any sense to me. :stuck_out_tongue:

@JEG2
For sure, I’d love to have had another 30 minutes to talk so I could go deeper! :grin: I personally don’t have a ton of programming history prior to Elixir, so how macros work and especially the AST in general were difficult concepts for me to learn. I’ve heard some excellent talks that started just a couple levels above where my own knowledge was, so at the time I didn’t learn much because I couldn’t follow along.

So my top goal for this talk was that someone with very little background would walk out of the talk understanding 90% of what was covered, and that they could then watch any other Macro talks and be able to easily follow along by recognizing the same concepts. I also went long every time I did a run-through of the talk so I ended up cutting a couple of examples at the end that would’ve introduced a few more of concepts of Macros (e.g. I really wanted to do an example of __using__ but just didn’t have the time).

@axelson
As some others said, the reason for the 2-element tuple is to allow for the syntax of keyword lists, which I think might be important for the maintaining of do/else/etc blocks inside of the AST. I was planning to cover this in my original talk but had to cut it for time at the last minute. I’ve got the slide to prove it! There’s some additional info (though not a ton) in the Official Docs: Syntax Reference.

Also, could you add the elixirconf2017 tag to this post, thanks!

axelson

axelson OP

Scenic Core Team

Thanks for the additional info! Also I’ve tagged this with elixirconf2017, didn’t realize that tag existed, will check the other posts as well.

JEG2

JEG2

Author of Designing Elixir Systems with OTP

Seems like a worthy goal to me and I would say that you nailed it.

Where Next? Top

Trending in Talks Top

CodeSync
LT: Skode: an ASCII shorthand for audio experimentation - Joseph Stewart | ElixirConf EU 2026 Comments welcome! View the ...
New
ElixirConf
Lightning Talk: Kate Rezentes - Notion-land | ElixirConf US 2025 https://www.youtube.com/watch?v=nLWm8gIz8TI Comments welcome! View th...
New
ElixirConf
Lightning Talk: Ivy Markwell - Data migrations with Monarch | ElixirConf US 2025 https://www.youtube.com/watch?v=AF1z6Z3bJKY Comments ...
New
ElixirConf
Failing to Introduce Elixir - John Darrington https://www.youtube.com/watch?v=KjAH68yVnh8 Comments welcome! View the <span class="hasht...
New
CodeSync
Testing Concurrency and Fault Tolerance in Elixir/Nerves - Marta Habdas | ElixirConf EU 2026 Comments welcome! View the <...
New
CodeSync
Practical Data Orchestration in Elixir - Silvia Zeamer | ElixirConf EU 2026 Comments welcome! View the <span class="hasht...
New
ElixirConf
Lightning Talk: Joseph Koski - Functional Program with Elixir | ElixirConf US 2025 Comments welcome! View the <span class...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews