简体   繁体   English

如何将elisp列表放入elisp哈希中

[英]How to put a elisp list inside an elisp hash

I have this working bit of code 我有这段工作代码

(setq block_id nil)
(setq myHash (make-hash-table :test 'equal))
(puthash "5" "a" myHash)
(message (gethash "5" myHash))

it inserts a string in to the hash. 它在哈希中插入一个字符串。 and printss out "a" as its supposed to do. 并按预期方式打印出“ a”。 but how do I insert a list in to the hash? 但是如何在哈希表中插入列表? I tried 我试过了

(setq block_id nil)
(setq myHash (make-hash-table :test 'equal))
(puthash "5" ("list foo" "baa" "baz") myHash)
(message (gethash "5" myHash))

but I get a nil from the my emacs elisp repl. 但是我从我的emacs elisp repl中得到了零。

You have several errors. 您有几个错误。 You're not quoting the list, so it's trying to call the string "list foo" as a function. 您没有引用列表,因此它试图将字符串"list foo"作为函数调用。 Then you're calling message with the wrong type of argument. 然后,您正在使用错误的参数类型来调用message

(setq myHash (make-hash-table :test 'equal))
(puthash "5" '("list foo" "baa" "baz") myHash)
(message "%S" (gethash "5" myHash))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM