gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 06:51:56 26 4
gpt4 key购买 nike

在 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/

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