[Bese-devel] Lisp question

R. Mattes rm at mh-freiburg.de
Thu Jan 5 19:02:35 UTC 2006


On Thu, 2006-01-05 at 13:27 -0500, Waldo Rubinstein wrote:
> I apologize for posting this Lisp-related question here, but I have  
> been looking for a Lisp mailing list and could not find it. Since  
> I've been learning Lisp to use UCW, I hope you guys understand me.  
> Addtionally, If anyone can point me to a Lisp mailing list, I would  
> appreciate it.
> 
> Anyway, I'm developing a small test program with multiple modules. I  
> defined a file as:
> 
> (defpackage :my-package (:use common-lisp :it.bese.ucw :it.bese.yacml))
> (in-package my-package)
> 
> (defclass my-class () (attr1 attr2 attr3))
> 
> (defun get-my-class ()
>    (let ((klass (make-instance 'my-class)))
>      (setf (slot-value klass 'attr1 123))
>      (setf (slot-value klass 'attr2 456))
>      (setf (slot-value klass 'attr3 789))
>      klass))
> 
> When in REPL, if I do:
> 
> CL-USER> (in-package my-package)
> MY-PACKAGE> (setf klass (my-package::get-my-class))
> #<MY-PACKAGE::MY-CLASS #x8A98CAE>
> 
> MY-PACKAGE> (slot-value klass 'attr1)
> 123
> 
> However, when I do the following at the REPL:
> 
> MY-PACKAGE> (in-package cl-user)
> CL-USER> (setf klass (my-package::get-my-class))
> #<MY-PACKAGE::MY-CLASS #x8A98CAE>
> 
> CL-USER> (slot-value klass 'attr1)
> 
> I get a debug window:
> 
> #<MY-PACKAGE:MY-CLASS #x8A98CAE> has no slot named ATTR1.
>    [Condition of type SIMPLE-ERROR]
> 
> It seems as if when I'm not in my package, I cannot refer to class  
> attributes defined there. Help please.

That one is easy: a slot name is a symbol. All symbols live in
packages. You need to call:

 (slot-value klass 'my-pacakge::attr1)

[this looks slightly ugly. But then, direct access to slots
isn't either, use accessors and export those from my-package]

 HTH Ralf Mattes
 

> Thanks,
> Waldo
> 
> _______________________________________________
> bese-devel mailing list
> bese-devel at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/bese-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <https://mailman.common-lisp.net/pipermail/bese-devel/attachments/20060105/04c4861e/attachment.sig>


More information about the bese-devel mailing list