Reputation: 383
I understand that both suppress evaluation of a symbol or expression. But the backtick is used for macro definitions while the apostrophe is used for symbols (among other things). What is the difference, semantically speaking, between these two notations?
Upvotes: 4
Views: 1022
Reputation: 48745
A standard quote is a true constant literal and similar lists and list that end with the same structure can share values:
'(a b c d) ; ==> (a b c d)
A backquoted structure might not be a literal. It is evaluated as every unquote needs to be evaluated and inserted into place. This means that something like `(a ,@b ,c d)
actually gets expanded to something similar to (cons 'a (append b (cons c '(d))))
.
The standard is very flexible on how the implementations solves this so if you try to macroexpand
the expression you get many different solutions and sometimes internal functions. The result though is well explained in the standard.
NB: Even though two separate evaluation produces different values the implementation is still free to share structure and thus in my example '(d)
has the potential to be shared and if one would use mutating concatenation of the result might end up with an infinite structure.
A parallel to this is that in some algol languages you have two types of strings. One that interpolates variables and one that don't. Eg. in PHP
"Hello $var"; // ==> 'Hello Shoblade'
'Hello $var'; // ==> 'Hello $var'
Upvotes: 5
Reputation: 85767
Backticks allow for ,foo
and ,@foo
to interpolate dynamic parts into the quoted expression.
'
straight up quotes everything literally.
If there are no comma parts in the expression, `
and '
can be used interchangeably.
Upvotes: 6