Even small details make a difference!

In Lisp, the single quote character plays a central role. It is actually a read macro, which expands to the built-in function quote. Its purpose is to inhibit the evaluation of the following argument, and quote is one of the most often called functions.

But it is remarkable that almost all Lisp implementations handle this in a somewhat suboptimal way. They define quote to return its first argument, without evaluating it. So far so good. But when you think about that for a moment, you may ask: "Why only the first argument?"

This is inefficient, both in terms of space and time, and has no benefit at all. Yet almost all Lisp implementations stick to it.

PicoLisp breaks with that bad habit, and defines quote to return all arguments, without evaluating them.

Let's look at some examples: Quoted expressions like
   'a
   '(a b)
   '(a . x)
expand in traditional Lisps to
   (quote a)
   (quote (a b))
   (quote (a . x))
while in PicoLisp, they expand to
   (quote . a)
   (quote a b)
   (quote a . x)
This makes quite a difference, as it uses only half the space (two cells in traditional Lisp, but only one in PicoLisp):
   (quote a)
      +-------+-------+      +-------+-------+
      | quote |   ----+----> |   a   |  NIL  |
      +-------+-------+      +-------+-------+

   (quote . a)
      +-------+-------+
      | quote |   a   |
      +-------+-------+
   (quote (a b))
      +-------+-------+      +-------+-------+
      | quote |   ----+----> |   |   |  NIL  |
      +-------+-------+      +---+---+-------+
                                 |
                                 V
                             +-------+-------+      +-------+-------+
                             |   a   |   ----+----> |   b   |  NIL  |
                             +-------+-------+      +-------+-------+

   (quote a b)
      +-------+-------+      +-------+-------+      +-------+-------+
      | quote |   ----+----> |   a   |   ----+----> |   b   |  NIL  |
      +-------+-------+      +-------+-------+      +-------+-------+
   (quote (a . x))
      +-------+-------+      +-------+-------+
      | quote |   ----+----> |   |   |  NIL  |
      +-------+-------+      +---+---+-------+
                                 |
                                 V
                             +-------+-------+
                             |   a   |   x   |
                             +-------+-------+

   (quote a . x)
      +-------+-------+      +-------+-------+
      | quote |   ----+----> |   a   |   x   |
      +-------+-------+      +-------+-------+
The runtime code for a traditional quote has more work to do. It needs two pointer dereferences to get the data, while PicoLisp needs only one.

For that reason, quote is the shortest of all functions in PicoLisp, being
   any doQuote(any x) {return cdr(x);}
in C, or
   (code 'doQuote 2)
      ld E (E CDR)  # Get CDR
      ret
in asm.

http://picolisp.com/wiki/?articlequote

29jul11   abu
Revision History