在 emacs lisp 中,各种树结构是常见的。 custom.el
通过:type
提供论据 defcustom
定义自定义变量的预期形状的标准方法。但是有没有一种标准的方法来验证一些随机 emacs lisp 值的结构?
可以说,我有一个表格列表
LIST = (ENTRY ...)
ENTRY = (NAME . ((1 VAL1) (2 VAL2) ...))
我可以以某种方式定义类似于自定义类型的结构,然后检查该结构定义吗?
最佳答案
在文件中 lisp/wid-edit.el
有这个功能:
(defun widget-type-match (widget value)
"Non-nil if the :type value of WIDGET matches VALUE.
The value of the :type attribute should be an unconverted widget type."
(widget-apply (widget-convert (widget-get widget :type)) :match value))
您可以根据自己的需要进行调整:
(defun my-type-match (type value)
(widget-apply (widget-convert type) :match value))
(my-type-match 'string "foo")
==> t
(my-type-match 'string 10)
==> nil
(my-type-match '(choice (const 1) (const 2) (const t)) 10)
==> nil
(my-type-match '(choice (const 1) (const 2) (const t)) 2)
==> t
关于data-structures - Emacs Lisp : Standard way to verify tree structures?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23983108/