From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/elisp/dotted-pair-notation.html | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 devdocs/elisp/dotted-pair-notation.html (limited to 'devdocs/elisp/dotted-pair-notation.html') diff --git a/devdocs/elisp/dotted-pair-notation.html b/devdocs/elisp/dotted-pair-notation.html new file mode 100644 index 00000000..2c60b7fb --- /dev/null +++ b/devdocs/elisp/dotted-pair-notation.html @@ -0,0 +1,35 @@ +

Dotted Pair Notation

Dotted pair notation is a general syntax for cons cells that represents the CAR and CDR explicitly. In this syntax, (a . b) stands for a cons cell whose CAR is the object a and whose CDR is the object b. Dotted pair notation is more general than list syntax because the CDR does not have to be a list. However, it is more cumbersome in cases where list syntax would work. In dotted pair notation, the list ‘(1 2 3)’ is written as ‘(1 . (2 . (3 . nil)))’. For nil-terminated lists, you can use either notation, but list notation is usually clearer and more convenient. When printing a list, the dotted pair notation is only used if the CDR of a cons cell is not a list.

Here’s an example using boxes to illustrate dotted pair notation. This example shows the pair (rose . violet):

    --- ---
+   |   |   |--> violet
+    --- ---
+     |
+     |
+      --> rose
+
+

You can combine dotted pair notation with list notation to represent conveniently a chain of cons cells with a non-nil final CDR. You write a dot after the last element of the list, followed by the CDR of the final cons cell. For example, (rose violet +. buttercup) is equivalent to (rose . (violet . buttercup)). The object looks like this:

    --- ---      --- ---
+   |   |   |--> |   |   |--> buttercup
+    --- ---      --- ---
+     |            |
+     |            |
+      --> rose     --> violet
+
+

The syntax (rose . violet . buttercup) is invalid because there is nothing that it could mean. If anything, it would say to put buttercup in the CDR of a cons cell whose CDR is already used for violet.

The list (rose violet) is equivalent to (rose . (violet)), and looks like this:

    --- ---      --- ---
+   |   |   |--> |   |   |--> nil
+    --- ---      --- ---
+     |            |
+     |            |
+      --> rose     --> violet
+
+

Similarly, the three-element list (rose violet buttercup) is equivalent to (rose . (violet . (buttercup))). It looks like this:

    --- ---      --- ---      --- ---
+   |   |   |--> |   |   |--> |   |   |--> nil
+    --- ---      --- ---      --- ---
+     |            |            |
+     |            |            |
+      --> rose     --> violet   --> buttercup
+
+

As a somewhat peculiar side effect of (a b . c) and (a . (b . c)) being equivalent, for consistency this means that if you replace b here with the empty sequence, then it follows that (a . c) and (a . ( . c)) are equivalent, too. This also means that ( . c) is equivalent to c, but this is seldom used.

+

+ Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc.
Licensed under the GNU GPL license.
+ https://www.gnu.org/software/emacs/manual/html_node/elisp/Dotted-Pair-Notation.html +

+
-- cgit v1.2.3