data-structures - Emacs Lisp : Standard way to verify tree structures?

标签 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 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/

相关文章:

java - 反转循环双向链表

c - 二维数组列主序

.net - 当我遍历字典(.NET通用数据结构)时,它的顺序是否与添加它们的顺序相同?

java - 如何使用 Google 的 Guava 库提取 Java 中的泛型类型

emacs - 如何在 emacs minibuffer 中模拟返回

emacs - Emacs 中的代码完成键绑定(bind)

java - 调整 HashMap 存储桶的大小

typescript - 如何让接口(interface)包含子类型,同时本身也是有效类型

types - 在 F# 中声明内部类型

emacs - 如何一次将钩子(Hook)应用于多个 Emacs 模式?