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.
27
questions
43
votes
5answers
7k 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 ...
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 ...
12
votes
3answers
2k views
Best way to retrieve values in nested assoc-lists?
Suppose I've got an assoc-list like this:
(setq x '((foo . ((bar . "llama")
(baz . "monkey")))))
And I want the value at bar. I can do this:
(assoc-default 'bar (assoc-default '...
8
votes
3answers
2k 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 ...
7
votes
2answers
163 views
construct an association list from two vectors
I have two vectors, [apple orange] and [5 10]. How do I construct an association list ((apple 5) (orange 10)) from them?
6
votes
2answers
228 views
Is there a function like `assoc` that returns all matching values?
The assoc KEY LIST function returns the first element of an alist whose car is equal to KEY.
Is there a built-in Emacs Lisp function which returns all elements of the alist whose cars are equal to ...
6
votes
2answers
842 views
Why does emacs use both propertly lists and association lists?
http://www.gnu.org/software/emacs/manual/html_node/elisp/Plists-and-Alists.html gives some supposed differences between plists and alists. Basically it comes down to:
Alists can be used as stacks, ...
5
votes
2answers
553 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"))) =&...
4
votes
1answer
454 views
Is there any Emacs built-in to list the keys of an associton list?
I could not find any function to list the keys of an associton list in Emacs documentation. So I wrote a simple one.
(defun my/keys (alist)
"Return the keys of the given ALIST."
(let ((value ...
3
votes
1answer
215 views
“Dissasociate” auto-mode for specific files (in ESS)
I'd like to keep ess as automatic major mode for R files and everything else, except for Julia, for which I want to use julia-mode alone. However, I cannot find out how to "unbind" the file ...
2
votes
1answer
623 views
Saving persistent undo to a single directory, alist format
It looks like this can be achieved by modifying the variable
undo-tree-history-directory-alist, but I can't figure out how. I tried a number of lines, the last of which is
(setq undo-tree-history-...
2
votes
2answers
90 views
Assoc in a nested alist
I have the following nested alist:
(setq x '(foo . ((bar . ((chocolate . "edible") (gold . "inedible")))
(jar . "glass"))))
How can get entry (chocolate ...
2
votes
1answer
311 views
Read file lines into plist
I've been reading various tutorials on alist/plist access but can't figure this out. Let's say i have this file, test.txt:
oranges 1
apples 2
grapes 3
I want to iterate this file line by line, and ...
1
vote
2answers
242 views
How do I create and update an alist?
This naive attempt did not work:
;; function_key = dict()
(setq function-key '())
;; function_key["evil-next-line"] = 108
(add-to-list function-key '(evil-next-line . 108))
It just exploded with a (...
1
vote
3answers
70 views
Replace element in a list / add in case of absence, with custom test/key functions
add-to-list doesn't refresh item, it only checks for existence of item by equal or custom comparison function:
(add-to-list
'tramp-methods
'("gssh" (tramp-login-program "gcloud ...
1
vote
2answers
74 views
Enable mode association with backup files as well
I want to enable mode association with backup files as well. E.g., if I backup my my-markdown.md file as my-markdown.md.orig or my-markdown.md.lastweek etc, I want them still be associated with the ...
1
vote
1answer
37 views
Association in Elisp not found
I have a simple alist in elisp like this:
(defvar *oneliners*
'((js . "//")
(python . "#")
))
I am a bit surprised that searching for the python key gives me nil. I am calling it from ...
1
vote
1answer
252 views
how to implement a simple lookup table in lisp
I want to write an elisp function, when a country name is given, it returns the short code for the country.
I've been reading about hash tables, but still not sure how to hashify my data set and make ...
1
vote
1answer
925 views
How do you get data by key from a json list?
I loaded some json data into a string and have elisp parsing it using the json-read-from-string function. Now I want to do is access data from the JSON by key. When I print out the data via message, ...
0
votes
2answers
288 views
Why does `assoc` return nil for a plist?
I've got the following issue:
(setq testvar '(link (:type "http" :path "//pygments.org/docs" :format
bracket :raw-link "http://pygments.org/docs" :application nil)))
(setq testvar (nth 1 testvar))
(...
0
votes
1answer
38 views
Argument to ivy-read action when collection is an alist
The documentation of ivy-read states that if the collection supplied is an alist, the selected candidate is passed as a cons cell to the function supplied in the :action argument.
So why does the code ...
0
votes
2answers
80 views
How do I filter an alist to just the properties I care about?
To effectively use a service's API, I'm leveraging json-read to turn the JSON response into an understandable data structure:
(let ((json-object-type 'alist)
(json-array-type 'list)
(...
0
votes
1answer
59 views
Custom sort order based on certain elements of a list
Q: Ā Each sub-list within the main list contains one of five possible categories. How can I customize the sort in the following order:
CUSTOM SORT ORDER:
1. TASKS
2. EVENTS
3. UNDATED
4. ...
0
votes
1answer
86 views
Unexpected behavior when updating alist
Question: The code is below, the contents of the list myList were copied in the debugger.
(let* ((myList '(("Concept Index"
("Файл" "/home/alamd/example/funEl/expirement/...
0
votes
1answer
31 views
How not to propagate dired-actual-switches as a directory variable to the sub directories
I want to set dired-actual-switches for the directory /path/to/data, but not for data's subdirectories. So I generated the following .dir-locals.el file in /path/to/data:
;;; Directory Local ...
0
votes
0answers
38 views
elisp - construct a quasi-alist from variable [duplicate]
To construct a quasi-alist, case 1 is using hardcode string; case 2 is using a variable filename to replace the hadcode string. but case 2 doesn't work as expected (should the same as case 1).
#+...
0
votes
1answer
72 views
car on cons gets nil
I define an alist like this:
(setq major-mode-list
'(((emacs-lisp-mode inferior-emacs-lisp-mode) . ("Elisp" "Emacs"))
((haskell-mode) . ("Haskell" "Haskell"))
))
And match current major-...