From: ·············@gmail.com
Subject: Automatically exporting the slots of an external class
Date: 
Message-ID: <1193540548.140212.283590@19g2000hsx.googlegroups.com>
Hi,

Is there a way of automatically exporting all the readers/accessors of
the slots of a class --- once the class has been made external to a
package?

Thanks,
Sachin.

From: Andreas Thiele
Subject: Re: Automatically exporting the slots of an external class
Date: 
Message-ID: <fg11nk$63p$03$1@news.t-online.com>
<·············@gmail.com> schrieb im Newsbeitrag ·····························@19g2000hsx.googlegroups.com...
> Hi,
>
> Is there a way of automatically exporting all the readers/accessors of
> the slots of a class --- once the class has been made external to a
> package?
>
> Thanks,
> Sachin.
>

Hi Sachin,

well I don't think there is a way built in. But it is a small MOP exercise.

The following example explains what you need:

(defpackage :test
  (:use :cl :cl-user)
  (:export :test1)
  )

(in-package :test)

(defclass test1 ()
  ((s1 :accessor r1)
   (s2 :reader r2)
   (s3 :writer r3)))

(in-package :cl-user)

(defun names (class-name)
  (mapcar 'slot-definition-name
          (class-direct-slots (find-class class-name))))

(defun readers (class-name)
  (mapcar 'slot-definition-readers
          (class-direct-slots (find-class class-name))))

(defun writers (class-name)
  (mapcar 'slot-definition-writers
          (class-direct-slots (find-class class-name))))

CL-USER 35 > (do-external-symbols (s :test) (princ s))
TEST1
NIL

CL-USER 36 > (names 'test:test1)
(TEST::S1 TEST::S2 TEST::S3)

CL-USER 37 > (readers 'test:test1)
((TEST::R1) (TEST::R2) NIL)

CL-USER 38 > (writers 'test:test1)
(((SETF TEST::R1)) NIL (TEST::R3))


Happy Lisping

Andreas
From: ·············@gmail.com
Subject: Re: Automatically exporting the slots of an external class
Date: 
Message-ID: <1193582335.181302.165420@22g2000hsm.googlegroups.com>
Thanks Andreas,


> well I don't think there is a way built in. But it is a small MOP exercise.


I was hoping to not use the mop as the mop is defined in different
packages in different lisps :-(
Anyways, here is what I came up with (for sbcl):


(defun Make-Slot-Accessors-External (&optional (package *package*))
  (labels ((export-slot-writers (slot-writer-list)
	     (dolist (slot-writer slot-writer-list)
	       (export (second slot-writer) package)))
	   (export-class-accessors (my-class)
	     (loop for slot in (sb-mop:class-direct-slots my-class)
		   for slot-reader-list = (sb-mop:slot-definition-readers slot)
		   for slot-writer-list = (sb-mop:slot-definition-writers slot)
		   do (export slot-reader-list package)
		   do (export-slot-writers slot-writer-list))))

    (do-external-symbols (symbol package)
      (let ((my-class (find-class symbol nil)))
	(when my-class
	  (export-class-accessors my-class))))))
From: Luigi Panzeri
Subject: Re: Automatically exporting the slots of an external class
Date: 
Message-ID: <m2640psxek.fsf@matley.muppetslab.org>
·············@gmail.com writes:

>
> I was hoping to not use the mop as the mop is defined in different
> packages in different lisps :-(
> Anyways, here is what I came up with (for sbcl):
>

You can use closer-mop. Just load it and substitute sb-mop:fun with
closer-mop:fun and you ll have portability
From: Thomas A. Russ
Subject: Re: Automatically exporting the slots of an external class
Date: 
Message-ID: <ymiabq19zli.fsf@blackcat.isi.edu>
·············@gmail.com writes:

> once the class has been made external to a
> package?

<pedantic>
Classes are never made external to a package.
Only symbols are made external to a package.
</pedantic>


This distinction can be important, because anything linked to that
external symbol (value, function, class definition, etc.) would be
accessible using the exported symbol syntax.

Also, it's good to not think about exporting symbols from packages
having anything to do (directly) with accessibility of the underlying
functions, classes, etc.


-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: ··············@gmail.com
Subject: Re: Automatically exporting the slots of an external class
Date: 
Message-ID: <1193956049.636375.227710@19g2000hsx.googlegroups.com>
> Is there a way of automatically exporting all the readers/accessors of
> the slots of a class --- once the class has been made external to a
> package?

you may find cl-def interesting:

(def (class eas) foo (bar)
  (slot1
   (slot2 :reader slot2-of)))

where eas means Export, Accessors, Slots:

(PROGN
  (EXPORT 'FOO)
  (EXPORT '(SLOT1 SLOT2))
  (EXPORT '(SLOT2-OF))
  (DEFCLASS FOO (BAR)
    (SLOT1
     (SLOT2 :READER SLOT2-OF))))

- attila