This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Java array class is not kawa Class?


Yaroslav Kavenchuk wrote:

2008/3/1, Jim White wrote:

> How to work with ArrayType? How get class of array element?
...

ArrayType.getComponentType() gets the Type of the elements.
...

If you're gonna dig around in such low-level stuff, it's probably a good
idea to look at the Kawa source for such details.

I do not find how get ArrayType from array :(

Me either.


AFAIK it is just used internally by the Kawa compiler to generate JVM bytecode.

If you want to do reflective stuff, then all I can suggest is using the the standard Java methods (java.lang.Class, java.reflect.*, etc.).

Per wrote some explanation of Kawa's inner workings a long while ago. They may be helpful to you.

http://www.gnu.org/software/kawa/index.html#Top

http://www.gnu.org/software/kawa/internals/index.html

http://per.bothner.com/papers/index.html

#|kawa:6|# (instance? (integer[] 1 2):class gnu.bytecode.ArrayType)
false

I was looking bad?

Your example makes me have to update my Kawa to SVN, but that's not such a bad thing...


So I fiddled around and suggest this:

#|kawa:9|# (java.lang.Class:isArray (integer[] 1 2):class)
true
#|kawa:10|# (java.lang.Class:getComponentType (integer[] 1 2):class)
class gnu.math.IntNum

Dealing with primitive types is a bit fussier:

#|kawa:24|# (instance? (java.lang.Class:getComponentType (int[] 1 2):class) <java.lang.Class>)
true
#|kawa:25|# (java.lang.Class:getComponentType (int[] 1 2):class)
int
#|kawa:26|# (instance? (java.lang.Class:getComponentType (int[] 1 2):class) <java.lang.Class>)
true
#|kawa:27|# (java.lang.Class:isPrimitive (java.lang.Class:getComponentType (int[] 1 2):class))
true
#|kawa:29|# (eq? (java.lang.Class:getComponentType (int[] 1 2):class) java.lang.Integer:TYPE)
#t


AFAIK, the only way to figure out which particular primitive type is used is to compare against the various java.lang.*:TYPE constants. Notice that those constants refer to the corresponding primitive for the boxed type.

I see that some methods return 'true' and some '#t'. I know that must have something to do with which type is actually returned by the methods, although I'm not sure why two Kawa methods ('eq?' and 'instance?') should have different results.

I've been lurking with interest on your efforts as I'm also working with
OpenOffice, but I decided to integrate Groovy rather than Kawa.
Although it's still pretty crude, you might want to check it out.

http://www.ifcx.org/

I saw your project, and tried to use it.

Did it work?


If have trouble and/or success please do let me know on the IFCX forum.

http://sourceforge.net/forum/forum.php?forum_id=708126

Why did you choose Groovy rather than Kawa or Clojure?

Groovy has very compact syntax for doing things with Java classes and collections and I think it is the best of the currently hot "scripting" languages (JRuby, Jython, and Groovy) for people who already know Java.


Groovy also has the "category" mechanism which enables adding API to existing classes which can be used to make the OpenOffice UNO API more palatable.

Since I've been a Lisper for about 30 years now I've come to accept that folks are never gonna get excited about a language with TMDRP (Too Many Damned Right Parenthesis). While resurrecting UCI MLISP or porting Dylan to Kawa are both interesting possibilities, I'm more interested in applications of such things these days.

My plans for IFCX Wings include supporting any programming language, starting with those that work on the JVM, and I have a hacked up version that shows both Groovy and Scheme (Kawa) in the same document.

Jim


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]