Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!gatech!udel!princeton!phoenix!eliot From: eliot@phoenix.Princeton.EDU (Eliot Handelman) Newsgroups: comp.lang.lisp Subject: Re: Question about INTERN Message-ID: <5783@idunno.Princeton.EDU> Date: 29 Jan 91 18:15:09 GMT References: <1991Jan29.055536.1523@magnus.ircc.ohio-state.edu> Sender: news@idunno.Princeton.EDU Organization: Princeton University, New Jersey Lines: 52 In article <1991Jan29.055536.1523@magnus.ircc.ohio-state.edu> murthy@magnus.ircc.ohio-state.edu (Murthy S Gandikota) writes: ; ; ;(setf my-house (make-house :rooms 4 :area 100)) ; ;(setf any-house my-house) ; ;(defun get-slot-value (obj slot) ;;;this function returns the value of the slot in obj ;(PROG (obj1 value) ; (setf obj1 obj) ; (if (equal (type-of obj) 'symbol) (setf obj1 (eval obj))) ; (setf value (eval `(,(intern (format nil "~a-~a" (type-of obj1) slot)) ; ,obj))) ; (RETURN value))) ; ;(get-slot-value my-house 'rooms) returns error The problem is that TYPE-OF doesn't guarantee returning the most specific type of an object, so if this used to work and now doesn't it's almost certainly because your two TYPE-OF's aren't behaving consistently. Common Lisp says that (TYPE-OF any-house) might return T. There's no portable way to find out what the type of an object is. But if you know the name of the slot then you might also know the name of the object, which could reduce your overhead. There's also no portable way to get the name of the structure slot-accessor, given the structure and the slot. If I know that the structure is HOUSE and the slot I'm looking for is ROOM, it would be nice to be able to get a handle on the accessor without having to build its name yourself, but it can't be done. If you do go the way of concatenation and interning, it's better to do this: (defun build-room-slot-accessor (slot) (intern (concatenate 'string "HOUSE-" (symbol-name slot)))) Then rewrite your function as a macro: (defmacro get-slot-value (obj slot) ;;this function returns the value of the slot in obj `(,(build-room-slot-accessor slot) ,obj))) I don't understand what this is supposed to do: ;(if (equal (type-of obj) 'symbol) (setf obj1 (eval obj))) If (setq a ) and (setq b a) and (setq c b) then A ==> B ==> C ==> ;; that is, the same room.