Subject: Re: a simple question
From: rpw3@rpw3.org (Rob Warnock)
Date: Fri, 15 Sep 2006 23:00:17 -0500
Newsgroups: comp.lang.lisp
Message-ID: <fNmdnT_RVqNM65bYnZ2dnUVZ_oCdnZ2d@speakeasy.net>
<Glenn.Ehrlich@specastro.com> wrote:
+---------------
| Shawn wrote:
| > My text book says:
| > (cons (list 1 2) (list 3 4))
| > is a list of 3 elements...
| > I cannot understand it. ...
| 
| The runtime structure of the result ((1 2) 3 4)
| looks like this (make sure you're in a courier fort or some other mono
| spaced font):
|        .
|       / \
|      /   \
|     /     \
|    /       \
|   .         .
|  / \       / \
| 1   .     3   .
|    / \       / \
|   2  nil    4  nil
+---------------

Yes, but this just confuses the OP more, I'd guess, since he probably
doesn't understand that one should read the "list structure" in the
"down & to the right" directions of your diagram. If you redraw the
periods as boxes [with the CAR on the left and CDR on the right] and
rotate the diagram 45 degrees counterclockwise, you get the more
traditional "boxes & arrows" depiction:

	  +---------- This is the single cell created by the CONS above.
	  |
	  |            +------------+-- These were created by (LIST 3 4).
	  |            |            |
	  V            V            V

      +---+---+    +---+---+    +---+---+
      | * | *----->| * | *----->| * |NIL|
      +-|-+---+    +-|-+---+    +-|-+---+
	|            |            |
	|            3            4
	V
      +---+---+     +---+---+
      | * | *-----> | * |NIL|   <--- These two were created by (LIST 1 2).
      +-|-+---+     +-|-+---+
	|             |
	1             2

Or, since fixnums will fit *inside* the cons cells, you can also
depict them this way:

      +---+---+    +---+---+    +---+---+
      | * | *----->| 3 | *----->| 4 |NIL|
      +-|-+---+    +---+---+    +---+---+
	|
	|
	V
      +---+---+     +---+---+
      | 1 | *-----> | 2 |NIL|
      +---+---+     +---+---+


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607