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
Trending in Talks
Other Trending Topics
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
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
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
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
I agree that it was a solid introductory presentation. I found myself wishing it went a touch deeper, but I did enjoy it.
axelson
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
defmacrosince 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
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 representingx()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
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
Thanks for taking over the posting responsibility for these videos. I’ve been really busy lately.
axelson
You’re welcome! I think the discussion is very valuable
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.
@JEG2
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.
For sure, I’d love to have had another 30 minutes to talk so I could go deeper!
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/etcblocks 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
elixirconf2017tag to this post, thanks!axelson
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
Seems like a worthy goal to me and I would say that you nailed it.