0

I would appreciate if someone could clarify the following difficulty. I encountered with the example illustrating how quote works.
we are given: (cdddr '(this list contains '(a quote)). it returns: ((quote (a quote))). if substitution model is used, it has to first of all calculate the quote inside of brackets '(a quote), but it at first evaluates the quote outside brackets (the very first quote). could someone clarify why it works like this.

sds
  • 58,617
  • 29
  • 161
  • 278
Oliver
  • 79
  • 1
  • 8
  • The argument you pass epanded is `(quote (this list contains (quote (a quote))))`. When evaluated `quote` then returns it's argument `(this list contains (quote (a quote)))` and `cdddr` or that is `((quote (a quote)))`. Inside quoted datum `quote` or shorthand `'`, `\` ` , and `,` has no computable effect and expands to pure symbols by the reader like in the part `(a quote)`. – Sylwester Jul 18 '17 at 19:17
  • thank you very much for the comment. Although it did not help to reply on the given question. The question was why the most outer "quote" evaluates at first but not the most inner "quote." – Oliver Jul 20 '17 at 10:16
  • That was what I answered. Special form `quote` evaluates to it's argument. Nothing in the argument `(this list contains (quote (a quote)))` will be evaluated further. Any occurences of lisp code inside quoted datum has no effect. It is only data, not code. Functions on the other hand evaluate all their arguments before they do anything so `(list this list contains '(a quote))` evaluates the parts as variables but `'(a quote)` becomes `(a quote)` since it was quoted. If it wasn't it would call the function `a` with the value of variable `quote` as the last argument to the function `list` – Sylwester Jul 20 '17 at 11:16
  • When using substitution model the primitives usually are only done once. It doesn't evaluate any more. eg `(list '+ 3 5)` becomes the list `(+ 3 5)` and not the result of the evaluation of that again. Same principle for `quote` `'(+ 3 5)` becomes `(+ 3 5)` and `'''x` becomes `''x` (also written `(quote (quote x))`) – Sylwester Jul 20 '17 at 11:23

0 Answers0