2
(defvar-local hash-entries nil)
(put 'hash-entries "key" "val")
(message "%S" hash-entries)

I try to add a key-value pair to the hash variable, hash-entries using the function put.

But when i print it, it prints nil instead of its contents, (key . val)

Madhavan
  • 1,957
  • 12
  • 28

1 Answers1

3

put is not for hash tables. What you want is puthash.

(puthash KEY VALUE TABLE)

Associate KEY with VALUE in hash table TABLE.

Also you cannot just use puthash on nil, you need to actually create a hash table first with make-hash-table. If you want to use strings as the has keys make sure you pass :test 'equal to make-hash-table.

For all the information you need to use hash tables you can consult this part of the manual.


put is for storing properties on a symbol, not the symbols value. You can read more about what put actually does here. It's extremely rare that you would actually ever need to use put for something.

Jordon Biondo
  • 12,332
  • 2
  • 41
  • 62