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?
--- Martin.
On Mon, Jun 14, 2010 at 4:09 AM, William Wadsworth will.wadsworth.10@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
In article AANLkTilR4sZL4IQ5sznTgw9nHHKCNq9-VtaYY20PmWBG@mail.gmail.com, Alessio Stalla alessiostalla@gmail.com wrote:
On Mon, Jun 14, 2010 at 4:09 AM, William Wadsworth will.wadsworth.10@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. :-)
-T.
On Thu, Jun 17, 2010 at 6:24 AM, Tobias C Rittweiler tcr@freebits.de wrote:
In article AANLkTilR4sZL4IQ5sznTgw9nHHKCNq9-VtaYY20PmWBG@mail.gmail.com, Alessio Stalla alessiostalla@gmail.com wrote:
On Mon, Jun 14, 2010 at 4:09 AM, William Wadsworth will.wadsworth.10@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
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
Regarding the initialization, this is not quite true; CLHS defstruct says
If a slot is not initialized in this way, it is initialized by evaluating slot-initform in the slot description at the time the constructor function is called. If no slot-initform is supplied, the consequences are undefined if an attempt is later made to read the slot's value before a value is explicitly assigned.
As consequences are undefined, always returning NIL is compliant, but you could also make it signal an error, and make SLOT-BOUNDP cover this case.
-T.
On Fri, Jun 18, 2010 at 6:41 AM, Tobias C Rittweiler tcr@freebits.de wrote:
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
Regarding the initialization, this is not quite true; CLHS defstruct says
If a slot is not initialized in this way, it is initialized by evaluating slot-initform in the slot description at the time the constructor function is called. If no slot-initform is supplied, the consequences are undefined if an attempt is later made to read the slot's value before a value is explicitly assigned.
As consequences are undefined, always returning NIL is compliant, but you could also make it signal an error, and make SLOT-BOUNDP cover this case.
Oh, thanks for pointing this out! I must admit I didn't check the CLHS but simply tried slot-makunbound on sbcl (which gives an error). Since I believe there's no such restriction in abcl, I could make it work like in classes.
Bye, Alessio
armedbear-devel@common-lisp.net