CLOS:我在这里做什么,在元类中设置一个槽?

时间:2013-06-24 15:15:13

标签: common-lisp clos

(ql:quickload :postmodern)
(defpackage :test-case
  (:use :cl)
  (:import :pomo))
(in-package :test-case)

;; (defclass dao-class (standard-class)
;;   ((direct-keys :initarg :keys :initform nil :reader direct-keys)
;;    (effective-keys :reader dao-keys)
;;    (table-name)
;;    (column-map :reader dao-column-map))
;;   (:documentation "Metaclass for database-access-object classes."))

(defclass definition ()
  ((id :col-type serial :reader definition-id)
   (content :col-type string :initarg :content :accessor definition-content)
   (word :col-type string :initarg :word :accessor definition-word))
  (:metaclass dao-class)
  (:keys id))

(pomo:dao-keys 'definition)
;; => (ID)
;; What I am setting with :keys? a slot in the meta class?

https://gist.github.com/PuercoPop/5850773

1 个答案:

答案 0 :(得分:3)

dao-classdirect-keys个广告位,其:initarg的名称为:keys,因此,如果我正确理解您的问题,答案是:“是的,{{1提供元类(:keys id)direct-keys广告位的值。“

编辑更准确地说,这里,由于措辞不太清楚...... dao-class是一个元类,即一个类,其实例本身就是类。在这种情况下, dao-classdefinition实例,其中包含插槽dao-class(在{{1}中声明}}),direct-keys中该插槽的值是通过dao-class选项提供的值初始化的。