Questions tagged [association-lists]

or alist for short, maps keys to values. It is a list of key-value pairs, where each pair is a cons whose car is the key and whose cdr is the value.

Filter by
Sorted by
Tagged with
35
votes
5answers
5k views

How to replace an element of an alist?

I have this by default in my auto-mode-alist: ("\\.js\\'" . javascript-mode) (even with emacs -Q). I'd like to substitute js2-mode for javascript-mode. Of course, I could use assq-delete-all and ...
3
votes
2answers
327 views

Replace element of alist using `equal` even if key does not exist

I have an alist whose keys are strings, and I need to set the value for one of its keys. If the key is not present, I need to add it. So for example, (alist-set "a" "bb" '(("a" . "b") ("c" . "d"))) =&...
15
votes
1answer
2k views

Is '(a . b) really a list?

I'm really confused with the . notation. Is '(a . b) a list? (listp '(a . b)) returns t but when I want to know its length (length '(a . b)) gives an error Wrong type argument: listp, b. The same is ...
6
votes
3answers
1k views

Looking for a simple way to update an alist without introducing degeneracies

In my .emacs file I have code like this: (setq default-frame-alist (assq-delete-all 'width default-frame-alist)) (add-to-list 'default-frame-alist (cons 'width new-width)) The ...