While watching The Upside Down Dimension of Elixir - An Introduction to Metaprogramming, I was reminded of a long-standing question I’ve had about
unquote. Specifically, how do these names relate to the tasks being performed?
So, I Googled around a bit and found Quoting Without Confusion, which explains these names in terms of their Lispish origin. Suddenly, it all became clear…
=> (quote (+ a 42)) (+ a 42)
In English, “quote” and “unquote” can be used to enclose verbatim expressions, keeping the reader from interpreting them as being part of the current document. Here is some discussion on this.
quote keeps Lisp from evaluating the enclosed expression. So, instead of being resolved using the current value of
(+ a 42) sticks around as an expression. So, it can be saved and evaluated later (possibly with some other value of
Since Lisp expressions are simply textual renditions of ASTs, we can think of
quote as meaning “produce the AST for this expression”. Elixir’s use follows this meaning pretty closely, if we ignore issues of compilation and data representation. WFM…