Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You'll get different behaviors depending on exactly what Lisp you're using (Scheme, Racket, Common Lisp, etc.) but in general, the system will accept <code>'x</code> as a <em>shorthand</em> or <em>syntactic sugar</em> for <code>(quote x)</code>. The two forms are exactly equivalent and their values are the same: the unevaluated <code>x</code>. When a result is coming out of the system, it might choose to print in the first way to make the result more intuitive to the user. A similar thing happens with <code>cons</code>, too. For instance,</p> <pre><code>(cons 1 2) ;=&gt; (1 . 2) </code></pre> <p>because that's the general way that cons cells (pairs) are printed. However, there's a special case defined for when the second part of the pair is another list (either the empty list <code>()</code> or another pair, and that's why we have the following. I've also written a bit more about how lists and cons cells are printed in an answer to <a href="https://stackoverflow.com/q/16379657/1281433">Recursive range in Lisp adds a period?</a>.</p> <pre><code>(cons 1 '()) ;=&gt; (1) (cons 1 '(2 3)) ;=&gt; (1 2 3) </code></pre> <p>Now, I've written the <em>values</em> of the expression above. E.g., the <em>value</em> of the form <code>(cons 1 '(2 3))</code> is the list <code>(1 2 3)</code>. As an additional complication, some systems (I'm thinking of some languages is Dr. Racket, in particular) don't print the <em>value</em> of a form in the interactive prompt, but rather print a form that would produce the same (for certain interpretations of “the same”) values. For instance, you might evaluate <code>'(1 . 2)</code> and see the output <code>(cons 1 2)</code> because that's another <em>form</em> that would produce the same value. This can be helpful if you're doing <em>pure</em> functional programming that has <a href="https://en.wikipedia.org/wiki/Referential_transparency_%28computer_science%29" rel="nofollow noreferrer">referential transparency</a>, but if you're not expecting it, it can lead to some confusion.</p> <p>A good way to see that we're getting the results that we should, regardless of how the system <em>prints</em> them, is to inspect them. We expect that <code>(list 'quote '(a b c))</code> should return a list whose <code>car</code> is the symbol <code>quote</code> and whose <code>cadr</code> is the list <code>(a b c)</code>. This is what we get (in Dr. Racket 5.3 with language R<sup>5</sup>RS):</p> <pre><code>&gt; (display (list 'quote '(a b c))) '(a b c) &gt; (display (car (list 'quote '(a b c)))) quote &gt; (display (cadr (list 'quote '(a b c)))) (a b c) </code></pre> <p>We get similar results if we use <code>'qmmmt</code> instead of <code>'quote</code>:</p> <pre><code>&gt; (display (list 'qmmmt '(a b c))) (qmmmt (a b c)) &gt; (display (car (list 'qmmmt '(a b c)))) qmmmt &gt; (display (cadr (list 'qmmmt '(a b c)))) (a b c) </code></pre> <p>The only difference is that in the first case, <code>display</code> displays the list whose <code>car</code> is the symbol <code>quote</code> using the shorthand that is available for such lists. That is, instead of displaying <code>(quote (a b c))</code> it displayed <code>'(a b c)</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload