Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does the dot in the following emacs command mean

Tags:

emacs

lisp

elisp

Here is some doco I'm creating but...

I'm not sure what the dot '.' between the extension and the mode is for though in the following:


File Associations

Example: Associate *.mmd with markdown-mode:

      (setq auto-mode-alist (cons '("\\.mmd$" . markdown-mode) auto-mode-alist))

basically there is an alist (associative list / hashtable) called auto-mode-alist. That points extension -> to mode. Extension looks like it's a regular expression.

cons is a function that pre-pends an element to a list

setq means set quoted (which quotes auto-mode-list for you), otherwise instead of assigning to the symbol auto-mode-alist, you will assign to the results of evaluating that symbol...not what you want ;)

like image 345
ftravers Avatar asked Mar 16 '11 04:03

ftravers


2 Answers

Lists are built up from smaller pieces in Lisp. The dot notation indicates those smaller pieces.

(a b c d e)                       ; a normal list
(a . (b . (c . (d . (e . nil))))) ; the same list in primitive form

An item of the form (a . b) syntax is called a cons cell; a is the car and b is the cdr. (Those last terms come from the register names used to store them on the minicomputer Lisp was originally developed on, and are not otherwise meaningful. cons is short for "construct".) cons cell s are created with the cons function. Notice that the behavior for prepending to a list falls naturally out of the internal format of a list, as shown above, and that appending to a list with cons will not do what one might naïvely expect.

Alist s are by historical convention plain cons cell s instead of full lists, originally for speed.

like image 83
geekosaur Avatar answered Oct 13 '22 12:10

geekosaur


In lisp, on the low level, you can either have an simple value (a number or an atom) or a dotted pair, or cons cells. (Let's ignore modern stuff like vectors...). On top of these, data structures like lists (a b c) are constructed.

An alist or associative list, is a plain list where each element itself (a, b et.c.) is a dotted pair. For example:

((foo . 10) (bar . 20))

You can search an alist using assq or assoc, a pair is returned. You can apply car and cdr to get the left or right part of the pair, respectively.

A plain list is cleverly constructed the above so that (a b c) is represented as (a . (b . (c . nil))) Typically, one does not have to know this to understand alist:s, but the internal printing mechanism can sometimes get thrown of. Concretely, ((foo . nil) (bar . 20)) is typically printed as ((foo) (bar . 20)).

like image 33
Lindydancer Avatar answered Oct 13 '22 13:10

Lindydancer