by imdhmd · 7y ago · 0 comments
Edit: I think I understand now, hmm.
Dotted lists are pretty rare. They mostly show up in association lists, where key/value pairs are stored as
((name . dave) (type . user))
and adding a pair to the front of the list shadows any other pairs with the same key.That defines (a b . c). Edit: Note that (b . c) is a list.
How then should we represent the last cons cell in a list? We have two choices for what goes in the second element of the last cons cell:
1. The last piece of data, or
2. Nothing; i.e. a special non-pointer pointer. In Lisp this is called nil.
If we choose option 1 it's harder for code that traverses the list to be sure it has reached the end. It's also harder to splice a new element (a new cons cell) onto the end of the list dynamically.
Option 1 is the "dotted" form of ending a list and option 2 is the "proper" form.
Option 2 is more common in Lisp. From a type theory point of view, Option 2 restricts the second element of a cons cell to contain either a pointer to a cons cell or nil. This makes reasoning about code, compiling code, and optimizing code easier.
https://www.gnu.org/software/emacs/manual/html_node/elisp/Co...
It's not a form allowed by all the preceding rules, and I wasn't sure what it meant either.
Even if a definition for the notation (a b . c) is added, an example of such an improper list fully broken down into pairs would certainly still be appreciated by us readers who don't already think in Lisp :)