Data structures Emacs Lisp:验证树结构的标准方法?

Data structures Emacs Lisp:验证树结构的标准方法?,data-structures,types,elisp,Data Structures,Types,Elisp,在emacs lisp中,各种树结构是常见的custom.el通过:type参数为defcustom提供了定义自定义变量预期形状的标准方法。但是,是否有一种标准方法来验证某些随机emacs lisp值的结构 比如说,我有一个表单列表 LIST = (ENTRY ...) ENTRY = (NAME . ((1 VAL1) (2 VAL2) ...)) 我能否以某种方式定义类似于自定义类型的结构,然后对照该结构定义进行检查?在文件lisp/wid edit.el中有以下功能: (defun wi

在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