The Art of the Metaobject Protocol- P2

The Art of the Metaobject Protocol- P2: The work described here is synthetic in nature, bringing together techniques and insights from several branches of computer. | How CLOS is Implemented 27 Object identity Different calls to make-instance must create distinct objects . non-eq . Slot storage There must be a place to store the current bindings of each instance s slots. Classification It must be possible to determine the class that a given object is an instance of. Reclassification change-class must change the class of an instance without changing its identity. For example the door instance of color-rectangle is laid out along the lines of Figure . The actual implementation of the low-level instance representation is not important to this presentation. We simply assume the existence of an abstract data type called standard instance with the following functional interface 12 allocate-std-instance class slot-storage returns a brand new standard instance whose class is class and whose slot storage is slot-storage . std-instance-p object returns true only when object is a standard instance . the result of a call to allocate-std-instance and not some other Common Lisp object like a cons or a symbol . std-instance-class instance provides access to the class of the standard instance instance . std-instance-slots instance provides access to the slot storage for the standard instance instance . allocate-slot-storage size initial-value returns a new chunk of storage big enough to hold the bindings of size number of slots all are initialized to initial-value . slot-contents slot-storage location provides access to the binding of the slot at a given location in slot-storage . Locations are numbered from zero. Class color-rectangle Slots clearp nil cyan 60 height 84 magenta 0 width 38 yellow 55 Figure The structure of an instance of color-rectangle. Determining the Class of an Instance Every object in Common Lisp is an instance of a CLOS class. Internally implementing generic function invocation and other operations requires that we be able to determine 12For the curious see std-instance 281 . 28 Chapter 1 the class of an

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.