marick
I’d like to read the code that actually implements the action of unquote. It seems like it should be somewhere in the Erlang source, in elixir_parser.yrl, elixir_compile.erl, elixir_expand.erl, or elixir_erl_pass.erl, but I can’t find it.
It probably doesn’t help that I don’t know Erlang.
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
So i have been using ash framework for a while and i love it. However currently the issue im having with ash framework is the error handl...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
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
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
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
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
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex











Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dorgan
It seems
unquoteis not a function itself, but rather a special call handled here:https://github.com/elixir-lang/elixir/blob/master/lib/elixir/src/elixir_quote.erl
In essence,
quotetakes the ast and handles calls(as in ast call) tounquotedifferently depending if the:unquoteoption is true or falsemarick
Thanks. I now think I understand. For people interested, I offer the following. Let me know if I’ve gotten things wrong.
Given this:
quote do: inspect(1 + a), compilation works as follows.Quote processing is handled by do_quote. The syntax tree for the body of the
quotelooks like this:That matches a different
do_quote, whose signature is:do_quote({Name, Meta, Args}. In Erlang, variables are uppercased. There are guards that check thatNameis an atom andArgsis a list. There’s a bit of rearrangement that ends with a call todo_quote_tuple, which looks like this:Leftis:inspectandRightis:There’s a recursive descent into the list, then the
do_quoteon line 288 matches the single element:Here
unquoteis the way Erlang spells atoms. In an Elixir function, the signature would bedo_quote({:unquote, _meta, [expr]}All this version of
do_quotedoes is strip and return the single argument:… which may puzzle you as it did me. But let’s see how that three-tuple is used. Recall that it was calculated as part of this:
The interesting bit that the first three arguments came from a three-tuple of the form
{:inspect, meta, [{:unquote, ..., ...}]}Because of the last line, that’s transformed into:
That is:
quote, the original{:inspect, ..., ...}three-tuple was not quoted verbatim, but rather converted into a different three-tuple, with the shape{:{}, ..., ...}. The compiler interprets that shape as meaning "emit code to call this particular function. (Hold that thought.)unquote, the original{:+, ..., ...}three-tuple was quoted verbatim: was left as an instruction to the compiler to create a function call.It’s important to remember that the structure we’ve been building is destined to be compiled and then executed. The compiler is going to take that tree and turn it into a linear set of virtual machine (“BEAM”) instructions. Assuming a pretty simple virtual machine, that set of instructions will look something like this:
{:a, [], MacroExamples.ExpansionViewer}, the compiler produces instructions that say “Look up the value forain the compilation context and push it on the stack.”{:+, [import: Kernel], [1, {...above...}]}produces: “use the function:+inKerneland apply it to1and the top element on the stack. Put the result on top of the stack.”{:{}, ..., [:inspect, ..metadata.., [...above...]]}says “create a three-tuple with the first element:inspect, the second..metadata.., and the top of the stack.”I extracted my example from this code:
Therefore, the result of compiling and executing the
quoteexpression is{:inspect, ..., 6}. Which, since it’s a three-tuple in “here’s a function call, dear compiler” format, could be compiled again, had it been a return value from adefmacro.“I’ve taught you much, my little droogies.” … Maybe?