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
That’s a wrap on Code BEAM Europe 2026! Thanks to everyone who came to Haarlem or joined online, and to our speakers, trainers and sponso...
New
CodeSync
The Graveyard of Good Ideas - Quinn Wilton | ElixirConf US 2026 Comments welcome! View the <span class="hashtag-icon-plac...
New
CodeSync
Building High-Performing Engineering Teams | Christian Koch | ElixirConf US 2026 Rountable <span class="hashtag-icon-placeholder"></span>...
New
CodeSync
LT: E-mail is broken! | Zach Supalla | ElixirConf US 2026 https://www.youtube.com/watch?v=BoHx136rgbE Comments welcome! View the <span...
New
CodeSync
LT: Process Dictionary Debugger - Andrew Glassman | ElixirConf US 2026 https://www.youtube.com/watch?v=ATN67Hj0C-8 Comments welcome! V...
New
CodeSync
LT: Elixir for Gaming! Using Network to Power a Sophisticated Multiplayer Simulation - Mik Ahmed https://www.youtube.com/watch?v=wbkIld3...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
raa-ziq
Hi everyone :waving_hand: I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews