gpt4 book ai didi

Emacs:gethash 在哈希表中看不到键

转载 作者:行者123 更新时间:2023-12-04 17:11:47 24 4
gpt4 key购买 nike

我在 ielm 中评估了以下 elisp 代码:

(setq foo-hash (make-hash-table))

(puthash "location" "house" foo-hash)

(defun foo-start ()
(interactive)
(message (gethash "location" foo-hash)))

但是,当我运行时 (foo-start)(gethash "location" foo-hash)我只有 nil附和。刚进入 foo-hash在 ielm 回声中: #s(hash-table size 65 test eql rehash-size 1.5 rehash-threshold 0.8 data ("location" "house"))
这是一个错误还是我做错了什么?

Emacs 版本:24.0.95.1

最佳答案

elisp 中的哈希表使用 eql默认情况下进行比较。字符串将不等于 eql除非它们是同一个对象。您可能想使用 equal ,它比较字符串的内容。用这个创建你的哈希表:

(make-hash-table :test 'equal)

关于Emacs:gethash 在哈希表中看不到键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10014352/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com