[armedbear-devel] How to access Java fields?

Greetings, I know how to gain access to and execute Java methods via jmethod and jcall, however, I don't know how to get and set instance and static fields (or variables) within a Java class. Any help would be greatly appreciated. BTW, I've now got a Lisp macro that maps all the methods in a Java class into a corresponding CLOS class. Thanks. Blake McBride

#'jfield *Arguments: **class-ref-or-field field-or-instance *&optional *instance value* This function retrieves or modifies a field in a Java class or instance. The valid argument patterns for this operation are: - *class-ref field-name*: to retrieve the value of a static field. - *class-ref field-name instance-ref*: to retrieve the value of a class field of the instance. - *class-ref field-name primitive-value*: to store primitive-value in a static field. - *class-ref field-name instance-ref value*: to store value in a class field of the instance. - *class-ref field-name nil value*: to store value in a static field (when *value* may be confused with an instance-ref). - *field-name instance*: to retrieve the value of a field of the instance. The class is derived from the instance. - *field-name instance value*: to store value in a field of the instance. The class is derived from the instance. See jlinker.htm<http://www.franz.com/support/documentation/current/doc/jlinker.htm>for more information. . On Tue, Feb 9, 2010 at 7:15 PM, Blake McBride <blake@mcbride.name> wrote:
Greetings,
I know how to gain access to and execute Java methods via jmethod and jcall, however, I don't know how to get and set instance and static fields (or variables) within a Java class. Any help would be greatly appreciated.
BTW, I've now got a Lisp macro that maps all the methods in a Java class into a corresponding CLOS class.
Thanks.
Blake McBride
_______________________________________________ armedbear-devel mailing list armedbear-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/armedbear-devel

I didn't realize ABCL uses Allegro's Java interface API. Is ABCL's version complete (according to Allegro's docs)? Thanks. Blake McBride On Tue, Feb 9, 2010 at 10:02 PM, dmiles@users.sourceforge.net < logicmoo@gmail.com> wrote:
#'jfield
*Arguments: **class-ref-or-field field-or-instance *&optional *instance value*
This function retrieves or modifies a field in a Java class or instance.
The valid argument patterns for this operation are:
- *class-ref field-name*: to retrieve the value of a static field. - *class-ref field-name instance-ref*: to retrieve the value of a class field of the instance. - *class-ref field-name primitive-value*: to store primitive-value in a static field. - *class-ref field-name instance-ref value*: to store value in a class field of the instance. - *class-ref field-name nil value*: to store value in a static field (when *value* may be confused with an instance-ref). - *field-name instance*: to retrieve the value of a field of the instance. The class is derived from the instance. - *field-name instance value*: to store value in a field of the instance. The class is derived from the instance.
See jlinker.htm<http://www.franz.com/support/documentation/current/doc/jlinker.htm>for more information. .
On Tue, Feb 9, 2010 at 7:15 PM, Blake McBride <blake@mcbride.name> wrote:
Greetings,
I know how to gain access to and execute Java methods via jmethod and jcall, however, I don't know how to get and set instance and static fields (or variables) within a Java class. Any help would be greatly appreciated.
BTW, I've now got a Lisp macro that maps all the methods in a Java class into a corresponding CLOS class.
Thanks.
Blake McBride
_______________________________________________ armedbear-devel mailing list armedbear-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/armedbear-devel

On Feb 10, 2010, at 12:22 PM, Blake McBride wrote:
I didn't realize ABCL uses Allegro's Java interface API. Is ABCL's version complete (according to Allegro's docs)?
I wouldn't take Allegro's documentation as authoritative, but haven't personally checked. I only noticed the correspondence between the two in the last month, so I don't the details of how faithfully the Allegro implementation was copied. -- "A screaming comes across the sky. It has happened before, but there is nothing to compare to it now."

On Wed, Feb 10, 2010 at 3:46 AM, Mark Evenson <evenson@panix.com> wrote:
On Feb 10, 2010, at 12:22 PM, Blake McBride wrote:
I didn't realize ABCL uses Allegro's Java interface API. Is ABCL's
version complete (according to Allegro's docs)?
I wouldn't take Allegro's documentation as authoritative, but haven't personally checked.
I only noticed the correspondence between the two in the last month, so I don't the details of how faithfully the Allegro implementation was copied.
-- "A screaming comes across the sky. It has happened before, but there is nothing to compare to it now."
_______________________________________________ armedbear-devel mailing list armedbear-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/armedbear-devel
Initially it was tested using Allergo as a reference point http://trac.common-lisp.net/armedbear/browser/trunk/j/src/org/armedbear/lisp...

On Feb 10, 2010, at 12:59 PM, dmiles@users.sourceforge.net wrote:
On Wed, Feb 10, 2010 at 3:46 AM, Mark Evenson <evenson@panix.com> wrote:
On Feb 10, 2010, at 12:22 PM, Blake McBride wrote:
I didn't realize ABCL uses Allegro's Java interface API. Is ABCL's version complete (according to Allegro's docs)?
[…]
I only noticed the correspondence between the two in the last month, so I don't the details of how faithfully the Allegro implementation was copied.
[…]
Initially it was tested using Allergo as a reference point http://trac.common-lisp.net/armedbear/browser/trunk/j/src/org/armedbear/lisp...
Ah, that makes sense now! Note that [this test code remains in trunk][1] as part of the ABCL-TEST-LISP ASDF definition. The tests cover a really small set of functionality, either for jlinker or ABCL, so they don't contribute that much information on the completeness of ABCL (not that dmiles claimed that they did.) [1]: http://trac.common-lisp.net/armedbear/browser/trunk/abcl/test/lisp/abcl/java... -- "A screaming comes across the sky. It has happened before, but there is nothing to compare to it now."

ABCL doesn't need to implement all of Allegro's API. For instance the marshalling (*make-dist-object*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/make-dist-object.htm> :/*discard-in-java*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/discard-in-java.htm>) and connection maintainence like *jlinker-init*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jlinker-init.htm>: from section 2.5 Some macros like *def-java-constructor*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/def-java-constructor.htm> , *def-java-method*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/def-java-method.htm> *def-java-class*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/def-java-class.htm>are not present in ABCL but should not be hard to create. Here is a quick list off top of head: *jdesc*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jdesc.htm>: *Function* (DESCRIBE-JAVA-OBJECT) *jarrayp*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jarrayp.htm>: *Function* (missing trivial) *jarray-ref*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jarray-ref.htm>: *Function*: *setf*<http://www.franz.com/support/documentation/current/ansicl/dictentr/setfpset.htm>can be used with this function to set values in a Java array. (complete) *jarray-set*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jarray-set.htm>: *Function*: use of this function is deprecated. Use *jarray-ref*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jarray-ref.htm>and *setf*<http://www.franz.com/support/documentation/current/ansicl/dictentr/setfpset.htm>instead. (complete) *jcall*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jcall.htm>: *Function* (complete) *jclass*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jclass.htm>: *Function* (complete) *jclass-name*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jclass-name.htm>: *Function* (complete) *jclass-of*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jclass-of.htm>: *Function* (complete) *jconstructor*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jconstructor.htm>: *Function* (complete) *jfield*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jfield.htm>: *Function* (complete) *jlinker-version*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jlinker-version.htm>: *Function* (un-needed) *jlinker-buffer-size*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jlinker-buffer-size.htm>: *Function* (un-needed) *jlookup*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jlookup.htm>: *Generic Function* (missing) *jmethod*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jmethod.htm>: *Function* (complete) *jnew*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jnew.htm>: *Function* (complete) *jnew-array*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jnew-array.htm>: *Function* (complete) *jstatic*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jstatic.htm>: *Function* (complete) *kcons*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/kcons.htm>: *Function* (missing trivial) *kmeth*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/kmeth.htm>: *Function* (missing trivial) *last-use*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/last-use.htm>: *Generic Function* (missing) *make-dist-object*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/make-dist-object.htm>: *Generic Function* (un-needed) *make-immediate-object*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/make-immediate-object.htm>: *Function* (complete) *jnotify-lisp*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jnotify-lisp.htm>(missing) *jregister-handler*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jregister-handler.htm>(complete) *jquery-handler*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/jquery-handler.htm> (missing) *def-java-to-lisp-wrapper*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/def-java-to-lisp-wrapper.htm>, *gen-output-lang*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/gen-output-lang.htm>, and *gen-java-stream*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/gen-java-stream.htm>. (missing) *def-java-class*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/def-java-class.htm>can be used to define a Lisp class which corresponds to a Java class. (missing) *def-java-constructor*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/def-java-constructor.htm>allows defining constructor functions to create instances of the classes defined with *def-java-class*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/def-java-class.htm>. (missing) The macro *def-java-method*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/def-java-method.htm>can be used to define methods.(missing) *def-java-static*<http://www.franz.com/support/documentation/current/doc/operators/jlinker/def-java-static.htm>defines static methods. (missing) Though also through other parts of ABCL some things are easier to put in than others. And ABCL when used with ASM.JAR can create new java classes which has unlimited possiblities On Wed, Feb 10, 2010 at 3:22 AM, Blake McBride <blake@mcbride.name> wrote:
I didn't realize ABCL uses Allegro's Java interface API. Is ABCL's version complete (according to Allegro's docs)?
Thanks.
Blake McBride
On Tue, Feb 9, 2010 at 10:02 PM, dmiles@users.sourceforge.net < logicmoo@gmail.com> wrote:
#'jfield
*Arguments: **class-ref-or-field field-or-instance *&optional *instance value*
This function retrieves or modifies a field in a Java class or instance.
The valid argument patterns for this operation are:
- *class-ref field-name*: to retrieve the value of a static field. - *class-ref field-name instance-ref*: to retrieve the value of a class field of the instance. - *class-ref field-name primitive-value*: to store primitive-value in a static field. - *class-ref field-name instance-ref value*: to store value in a class field of the instance. - *class-ref field-name nil value*: to store value in a static field (when *value* may be confused with an instance-ref). - *field-name instance*: to retrieve the value of a field of the instance. The class is derived from the instance. - *field-name instance value*: to store value in a field of the instance. The class is derived from the instance.
See jlinker.htm<http://www.franz.com/support/documentation/current/doc/jlinker.htm>for more information. .
On Tue, Feb 9, 2010 at 7:15 PM, Blake McBride <blake@mcbride.name>wrote:
Greetings,
I know how to gain access to and execute Java methods via jmethod and jcall, however, I don't know how to get and set instance and static fields (or variables) within a Java class. Any help would be greatly appreciated.
BTW, I've now got a Lisp macro that maps all the methods in a Java class into a corresponding CLOS class.
Thanks.
Blake McBride
_______________________________________________ armedbear-devel mailing list armedbear-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/armedbear-devel

Blake, On Tue, Feb 9, 2010 at 7:15 PM, Blake McBride <blake@mcbride.name> wrote:
BTW, I've now got a Lisp macro that maps all the methods in a Java class into a corresponding CLOS class.
This is pretty neat. Yes there is no reason that CLOS or at least very usefull form of a object system that reuses existing java class should not be defined by macros to make it smooth I used to imagine that the runtime-class.lisp was piso's original plan (generated java classes from lisp .. which these objects could be mixins subclasing pre-exisitng java classes) In my ABCL Clojure extension http://code.google.com/p/opensim4opencog/source/browse/trunk/bin/cl-cogbot.l..., (this file is simplistic becasue some code is i the non-lisp sources) but you get the gist. I preroll existing C#/.NET class into a set of existing methods gleaned from java's reflection using a name-mangling contract (as-needed). In cases I have multple possible methods per class (or interface).. i end up doing a (defun someclass-somemethod (self &rest args) (... guess the right jcall ....)) Static class fields, like String.CASE_INSENSITIVE_ORDER i make a symbol macro on %JAVA-LANG-STRING/CASE-INSENSITIVE-ORDER But my blindspot still is on how to please a more CLOSy clonsuming codebase so I am very interested in seeing how you set things up from your macros.
participants (3)
-
Blake McBride
-
dmiles@users.sourceforge.net
-
Mark Evenson