Arc Forumnew | comments | leaders | submit | lemonodor's commentslogin
1 point by lemonodor 6165 days ago | link | parent | on: CL Question

Are you asking for a function in CL or in Arc?

This is what I use in CL:

  (defun class-slots (class)
    #+(or digitool openmcl) (ccl:class-slots class)
    #+sbcl (sb-mop:class-slots class)
    #+cmu (mop:class-slots class)
    #+lispworks (clos:class-slots class)
    #+allegro (mop:class-slots class))

  (defun slot-definition-name (slot-defn)
    #+(or digitool openmcl) (ccl:slot-definition-name slot-defn)
    #+sbcl (sb-mop:slot-definition-name slot-defn)
    #+cmu (mop:slot-definition-name slot-defn)
    #+lispworks (clos:slot-definition-name slot-defn)
    #+allegro (mop:slot-definition-name slot-defn))

  (defmethod clone-object ((object T))
    (let ((copy (allocate-instance (class-of object))))
      (loop for slot in (class-slots (class-of object))
	   do (let ((slot-name (slot-definition-name slot)))
		(when (slot-boundp object slot-name)
		  (setf (slot-value copy slot-name)
			(slot-value object slot-name)))))
      copy))

-----