CLOS:在initarg,slot-writer时强制插槽有一个特定的类型?

时间:2014-10-01 14:16:58

标签: validation types common-lisp assert clos

如何在CLOS中强制执行插槽类型。

我知道(locally (declare (optimize safety))) (defclass foo () ((num :type number...可以回答,但我认为它不够便携。 (仅限SBCL,而不是CLISP 2.49)

或者,我应该实施这些东西吗? (用于检查指定:type s后的每个插槽。)

  1. defmethod :after (setf SLOT)
  2. defmethod :after initialize-instance
  3. 有没有更简单的方法呢?

    并且,是否有任何“MOP”或元类用于钩子“插槽更新”?

    感谢。

    编辑:我认为这与CLOS: How to make a slot have an enforced type of vector of symbols?的问题不同,因为我需要有关“元类”或slot-value-with-class事情的更多信息。

    编辑:我发现closer-mop提供了可取的便携式方式。

    CL-USER> (nth 0 (closer-mop:class-slots (find-class 'foo-class)))
    CL-USER> (closer-mop:slot-definition-type *)
    

0 个答案:

没有答案