Quote / Quasiquote

Symbols are mostly used as references to other values and are implicitly resolved wherever they appear. Sometimes however you may want have a symbol stay a symbol. To achieve this you can use quote and quasiquote.

1. Quote

If you want to simply return a value as is, meaning a symbol without resolving it, or a list instead of evaluating it as a from then you can use quote.

Since this is quite the common occurence there is a special reader form to make this more convenient: '. By prefixing any symbol with a single quote it will be used as is, without any attempt to resolve it.

Quote can not only be used to inhibit the implicit behaviour of symbol resolution, but can also stop expressions from being evaluated and instead being passed along as simple lists. This allows for the easy inclusion of literal lists.

'a ; You can quote symbols
a

'(1 2 3) ; Or forms, making them plain lists
(1 2 3)

2. Quasiquote

What is one supposed to do if one wants to quote only parts of an expression though? You could build it up using cons,list and quote but there is a more convenient way for that: quasiquote.

Just like quote there is an associated reader form, the backtick: ` which mostly works just like a regular quote, with the distinction that contained unquote and unquote-splicing forms won't be quoted but actually be evaluated, they have the reader form ~ and ~@, just like Clojure.

Reasoning

I chose the Clojure style over Scheme/Lisp because using a , for unquoting would make it non-whitespace, making its use as a thousands separator very problematic.

`(1 2 ~(+ 1 1 1)) ; To unquote you can use a tilde
(1 2 3)

`(1 ~@(list 2 3)) ; And ~@ for unquote-splicing
(1 2 3)

Implementation detail

Unlike in other Lisp/Scheme implementations Quasiquote is just a regular macro, this shouldn't make a difference in most cases but might trip you up if you delve deeper into the runtime.