Python dictionary or map in elisp

What is the equivalent of a python dictionary such as {'a':1, 'b':2} in elisp? And again, does elisp have any map-down api?

+6
source share
2 answers

Association lists are the most commonly used associative containers in elisp. This is just a list of cells with key values ​​like this ((key . value)) . You can use the assoc function to get the value corresponding to the key, and rassoc to get the key with the desired value.

Elisp comes with a built-in mapcar function that displays the map, but AFAIK is not a good fold tool. You can emulate it using any of the provided loops. However, the best solution is to use cl-lib and slip into CommonLisp ground. In particular, it supplies cl-mapcar and cl-reduce .

+6
source

In addition to association lists (whose algorithmic complexity is suitable for small tables, but not large), there are hash tables that can be built using make-hash-table and puthash , or if you prefer immediate values, you can write them as #s(hash-table data a 1 b 2) .

+7
source

Source: https://habr.com/ru/post/980192/


All Articles