런타임에 클래스를 생성해야합니다. 예를 들어 평가에 의존하지 않아도됩니다.Common-Lisp에서 런타임에 클래스를 이식 가능하게 만드는 방법 CLOS
(defparameter *my-class*
(make-instance 'standard-class
:name 'my-class
:direct-slots '((:name x :readers (get-x) :writers ((setf get-x))))))
(defparameter *my-instance* (make-instance *my-class*))
(setf (get-x *my-instance*) 42) ;; => 42
: 메타 클래스 프로토콜은 완전히 공통 리스프에서 표준화되지 않는다는 것을 알고는
The Common Lisp Object System MetaObject Protocol을 탐색 한 후, 나는 클래스를 생성 인스턴스화하고, 숫자로 인스턴스의 슬롯 값을 설정하려면 다음 코드를 시도
불행하게도이 코드는 SBCL에서 제대로 작동하지만 클래스 생성이 작동하는 것 같다 CCL에 있지만, 다음과 같은 오류가 발생 (make-instance *my-class*)
인스턴스 작성 :
There is no applicable method for the generic function:
#<STANDARD-GENERIC-FUNCTION INITIALIZE-INSTANCE #x30200002481F>
when called with arguments:
(#<error printing CONS #x302001A9F6A3>
[Condition of type CCL:NO-APPLICABLE-METHOD-EXISTS]
내가 closer-mop 패키지보고 시도를 숨겨야하는 메타에 대한 다양한 구현 간의 차이점 - 객체 프로토콜,하지만 내 모든 범위에서 유용한 기능이나 클래스를 찾을 수 없습니다.
그래서 질문입니다 : 클래스를 만들고 런타임시에 직접 metaclass level of CLOS를 사용하여 이식 할 수있는 이식성있는 방법이 있습니까?
, 당신은 [보장 수준 (http://mop.lisp.se/dictionary.html#ensure-class) 시도하거나 수있는 [확인-클래스 사용하여 클래스 (http://mop.lisp.se/dictionary.html#ensure-class-using-class). – coredump
직접 수퍼 클래스도 지정하면 CCL이 작동하는 것처럼 보입니다. : direct-superclasses (list (find-class 'standard-object))' – jkiiski
감사합니다. @jkiiski, 문제는 내가 수퍼 클래스를 지정해야한다는 것입니다. 답변으로 게시하면 동의 할 것입니다. – Renzo