作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我找到我要找的东西时,我需要提前从 maphash
退出。
(defun find-in-hash (str hash)
(let ((match nil))
(maphash (lambda (key value)
(if (string-prefix-p str key)
(setq match key))) hash)
match))
我将如何在 Emacs Lisp 中做到这一点?
最佳答案
如 how to interrupt maphash 中所述您可以将 maphash
放置在一个 block 内并通过 return-from
退出该 block ,即使用表单
(block stop-mapping
(maphash
;; Function to call for all entries in ht.
;; A condition for when to stop mapping.
(return-from stop-mapping)
ht))
请注意,这需要 cl
,可以通过 (require 'cl)
要求。 As mentioned in a comment通过
(catch 'stop-mapping
(maphash
;; Function to call for all entries in ht.
;; A condition for when to stop mapping.
(throw 'stop-mapping retval)
ht))
关于emacs - 如何从 Emacs Lisp 中的 maphash 中脱颖而出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15942513/
我正在尝试编写一个小型宏系统来在 Emacs Lisp 中执行迭代任务。我曾想当然地认为,除了 while 循环之外什么都没有。没有更多的原语或一些隐藏的功能,但我决定,我最好问问。 “隐藏功能”是指
我正在尝试编写一个小型宏系统来在 Emacs Lisp 中执行迭代任务。我曾想当然地认为,除了 while 循环之外什么都没有。没有更多的原语或一些隐藏的功能,但我决定,我最好问问。 “隐藏功能”是指
这个问题在这里已经有了答案: Suppress warning for function arguments not used in LISP (1 个回答) 关闭 8 年前。 我有以下内容,我正在
当我找到我要找的东西时,我需要提前从 maphash 退出。 (defun find-in-hash (str hash) (let ((match nil)) (maphash (lam
我是一名优秀的程序员,十分优秀!