diff options
Diffstat (limited to 'devdocs/elisp/box-diagrams.html')
| -rw-r--r-- | devdocs/elisp/box-diagrams.html | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/devdocs/elisp/box-diagrams.html b/devdocs/elisp/box-diagrams.html new file mode 100644 index 00000000..f30af8eb --- /dev/null +++ b/devdocs/elisp/box-diagrams.html @@ -0,0 +1,54 @@ + <h4 class="subsubsection">Drawing Lists as Box Diagrams</h4> <p>A list can be illustrated by a diagram in which the cons cells are shown as pairs of boxes, like dominoes. (The Lisp reader cannot read such an illustration; unlike the textual notation, which can be understood by both humans and computers, the box illustrations can be understood only by humans.) This picture represents the three-element list <code>(rose violet buttercup)</code>: </p> <div class="example"> <pre class="example"> --- --- --- --- --- --- + | | |--> | | |--> | | |--> nil + --- --- --- --- --- --- + | | | + | | | + --> rose --> violet --> buttercup +</pre> +</div> <p>In this diagram, each box represents a slot that can hold or refer to any Lisp object. Each pair of boxes represents a cons cell. Each arrow represents a reference to a Lisp object, either an atom or another cons cell. </p> <p>In this example, the first box, which holds the <small>CAR</small> of the first cons cell, refers to or holds <code>rose</code> (a symbol). The second box, holding the <small>CDR</small> of the first cons cell, refers to the next pair of boxes, the second cons cell. The <small>CAR</small> of the second cons cell is <code>violet</code>, and its <small>CDR</small> is the third cons cell. The <small>CDR</small> of the third (and last) cons cell is <code>nil</code>. </p> <p>Here is another diagram of the same list, <code>(rose violet +buttercup)</code>, sketched in a different manner: </p> <div class="example"> <pre class="example"> --------------- ---------------- ------------------- +| car | cdr | | car | cdr | | car | cdr | +| rose | o-------->| violet | o-------->| buttercup | nil | +| | | | | | | | | + --------------- ---------------- ------------------- +</pre> +</div> <p>A list with no elements in it is the <em>empty list</em>; it is identical to the symbol <code>nil</code>. In other words, <code>nil</code> is both a symbol and a list. </p> <p>Here is the list <code>(A ())</code>, or equivalently <code>(A nil)</code>, depicted with boxes and arrows: </p> <div class="example"> <pre class="example"> --- --- --- --- + | | |--> | | |--> nil + --- --- --- --- + | | + | | + --> A --> nil +</pre> +</div> <p>Here is a more complex illustration, showing the three-element list, <code>((pine needles) oak maple)</code>, the first element of which is a two-element list: </p> <div class="example"> <pre class="example"> --- --- --- --- --- --- + | | |--> | | |--> | | |--> nil + --- --- --- --- --- --- + | | | + | | | + | --> oak --> maple + | + | --- --- --- --- + --> | | |--> | | |--> nil + --- --- --- --- + | | + | | + --> pine --> needles +</pre> +</div> <p>The same list represented in the second box notation looks like this: </p> <div class="example"> <pre class="example"> -------------- -------------- -------------- +| car | cdr | | car | cdr | | car | cdr | +| o | o------->| oak | o------->| maple | nil | +| | | | | | | | | | + -- | --------- -------------- -------------- + | + | + | -------------- ---------------- + | | car | cdr | | car | cdr | + ------>| pine | o------->| needles | nil | + | | | | | | + -------------- ---------------- +</pre> +</div><div class="_attribution"> + <p class="_attribution-p"> + Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br> + <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Box-Diagrams.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Box-Diagrams.html</a> + </p> +</div> |
