[armedbear-devel] SLOT-VALUE and SLOT-VALUE-USING-CLASS with DEFSTRUCT

Alessio Stalla alessiostalla at gmail.com
Thu Jun 17 20:20:30 UTC 2010


On Thu, Jun 17, 2010 at 6:24 AM, Tobias C Rittweiler <tcr at freebits.de> wrote:
> In article
> <AANLkTilR4sZL4IQ5sznTgw9nHHKCNq9-VtaYY20PmWBG at mail.gmail.com>,
>  Alessio Stalla <alessiostalla at gmail.com>
>  wrote:
>
>> On Mon, Jun 14, 2010 at 4:09 AM, William Wadsworth
>> <will.wadsworth.10 at gmail.com> wrote:
>> > Hi.
>> >
>> > The following transcript demonstrates the problem.
>> >
>> > --- BEGIN
>> > Armed Bear Common Lisp 0.20.0
>> > Java 1.6.0_20 Sun Microsystems Inc.
>> > Java HotSpot(TM) Client VM
>> > Low-level initialization completed in 0.667 seconds.
>> > Startup completed in 4.849 seconds.
>> > Type ":help" for a list of available commands.
>> > CL-USER(1): (defstruct x a b c)
>> > X
>> > CL-USER(2): (slot-value (make-x :a 10) 'a)
>> > #<THREAD "interpreter" {118958E}>: Debugger invoked on condition of
>> > type UNDEFINED-FUNCTION
>> >  The function SLOT-VALUE is undefined.
>> > Restarts:
>> >  0: CONTINUE     Try again.
>> >  1: USE-VALUE    Specify a function to call instead.
>> >  2: RETURN-VALUE Return one or more values from the call to SLOT-VALUE.
>> >  3: TOP-LEVEL    Return to top level.
>> > [1] CL-USER(3): :res
>> > CL-USER(4): (slot-value (make-x :a 10) 'a)
>> > #<THREAD "interpreter" {118958E}>: Debugger invoked on condition of
>> > type SIMPLE-ERROR
>> >  There is no applicable method for the generic function
>> > #<STANDARD-GENERIC-FUNCTION MOP::SLOT-VALUE-USING-CLASS {932FE}
>> >> when called with arguments (#<STRUCTURE-CLASS X {11EF443}> #<X {1184326}>
>> >> A).
>> > Restarts:
>> >  0: TOP-LEVEL Return to top level.
>> > [1] CL-USER(5): :res
>> > CL-USER(6):
>> > --- END
>> >
>> > DEFCLASS seems to work fine, though I would like to keep using DEFSTRUCT.
>> > I understand that the MOP is not really complete. However, Is there a
>> > workaround
>> > that will not resort in using DEFCLASS?
>>
>> At glance, what you ask is not there but can be implemented without
>> too much effort. Structures already carry (on the Java side)
>> information about their slots, which is used by the inspector. So,
>> stay tuned ;)
>>
>> Cheers,
>> Alessio
>
> I usually use WITH-SLOTS on structures, too, even though strictly,
> it's not portable. Many implementations seem to support it just fine.
> So yeah, go ahead and make it work on ABCL, too. :-)

I committed (r12756) a simple implementation of SLOT-VALUE and friends
(setf slot-value, slot-boundp, slot-makunbound) for structures. It
searches for slots by iterating through the list of slot names stored
in the structure-class, which is probably not very good
performance-wise (CLOS objects use a map). Structure slots are
initialized to NIL and can't be unbound, and
slot-boundp/slot-makunbound reflect this.

I also added the necessary autoloads to autoloads.lisp.

Bye,
Alessio




More information about the armedbear-devel mailing list