[elephant-devel] Transient slots in non-persistent objects

Peter Bengtson peter at peterbengtson.com
Wed Oct 20 17:28:15 UTC 2004


Would this work?

;;;
;;; Patch Elephant to allow specification of transient slots for 
non-persistent objects
;;;

(in-package :elephant)

(defun slots-and-values (o)
   (declare (optimize (speed 3) (safety 0)))
   (let ((class (class-of o)))
     (loop for sd in (compute-slots class)
	  for slot-name = (slot-definition-name sd)
	  with ret = ()
	  do
	  (when (and (persistent-slot-p class slot-name)
	             (slot-boundp o slot-name)
		         (eq :instance (slot-definition-allocation sd)))
	    (push (slot-value o slot-name) ret)
	    (push slot-name ret))
	  finally (return ret))))


(defmethod persistent-slot-p ((class t) (slot-name t))
   t)


(export 'persistent-slot-p)


;;;
;;; This would be used in the application in the following manner, 
assuming there is
;;; a class called CLIENT with a slot called CLIENT-SOCKET containing 
transient data:

(in-package :cl-user)

(defmethod persistent-slot-p ((class client) (slot-name (eql 
'client-socket)))
   nil)


	/ Peter





More information about the elephant-devel mailing list