#clojure log - May 26 2008

The Joy of Clojure
Main Clojure site
Google Group
List of all logged dates

9:04 ozzilee: I've got a Java method I want to call that takes either an int or an Object, with different behavior for each. How can I pass it an int, rather than a java.lang.Integer?

9:05 rhickey_: (. x method (int arg))

9:07 ozzilee: Hmmm. Ok.

9:07 rhickey_: dpes that not work?

9:07 does

9:07 ozzilee: I'm not sure, I think I might have another problem.

9:09 Is there a way to list the methods an object supports?

9:10 rhickey_: (-> "fred" .getClass .getMethods seq)

9:11 asbjxrn: That is a keeper. That's one thing I've wished to do more than once.

9:14 ozzilee: (let [l (new java.util.ArrayList)] l (. l add "foo") (. l remove (int 0)) l) ;[foo]

9:15 Should that not remove "foo" at index 0?

9:15 (let [l (new java.util.ArrayList)] l (. l add 1) (. l remove (int 1)) l); []

9:15 Yeah, (int) doesn't do it.

9:17 rhickey_: ack - I see, nasty overloads - let me look into it

9:17 ozzilee: Yup, nasty overloads indeed. Thanks.

9:52 asbjxrn: is there a way of printing arguments/return values as well with that (-> "fred" .getClass .getMethods seq) call?

9:55 rhickey_: Those are instance of the class java.lang.reflect.Method and have all of its functionality:

9:56 (map #(vector (.getReturnType %) (seq (.getParameterTypes %))) (-> "fred" .getClass .getMethods seq))

10:00 asbjxrn: Thanks, looking closer at the output, it seems printing the results of .getMethods prints it's expected arguments, so no need for the getParameterTypes

10:01 rhickey_: it prints its returns too

10:01 * asbjxrn groans

10:01 asbjxrn: You're right, of course.

10:02 rhickey_: just pointing out you are not limited to text - the last thing I posted gives you a data structure with class objects in it

10:04 asbjxrn: Understand. I was thinking of using it as a online javadoc thing, instead of using a browser, just list the functions. I have a feeling it's another case of reinventing the weel...

10:07 (I have to search web docs a lot... Kinda unfamiliar with the java libraries.)

10:09 rhickey_: but the web docs are nice - it would be nice to have a REPL command that launched the JavaDoc for a class - (javadoc (class x))

10:13 asbjxrn: Should be possible, shouldn't it? I'

10:14 rhickey_: of all things, IIRC launching the browser portably under JDK 5 is somehow difficult

10:14 asbjxrn: I would guess on OSX and Windows it's a matter of doing an open on the URI?

10:17 Linux/other_unix_varieties is a problem of course. Which may mean that it may be difficult to do it portably.

10:23 cgrand: for displaying javadocs the swing HTML component may suffice (or provide a fallback method if not JDK6)

10:25 rhickey_: cgrand: yes, probably fine for javadocs

10:25 jteo: isn't that why IDEs exist?

10:26 rhickey_: yes, IDEs exist so you can wait for them to add features :)

10:26 jteo: ;)

10:26 hehe

10:26 rhickey_: But I imagine the 20 lines or so of Clojure this would take would be useful everywhere there is a Clojure REPL

10:27 * rhickey_ is busy writing Clojure and not volunteering :)

10:31 jteo: you're biased. ;)

10:35 asbjxrn: For a more clojure related question, I have a variable that is a function, when I call it it does what it is supposed to do but I get a nullpointerexception. The return value is not used anywhere, I call it like this : (if run-once-routines (run-once-routines))

10:37 I don't really understand where the nullpointerexeption happens. Even if the function just returns true, I get an exeption, and the return value is not used anywhere.

10:38 rhickey_: what are you doing with the value of the if expression itself?

10:38 asbjxrn: nothing, it's just a series of statements.

10:39 rhickey_: you'll have to look at the stack trace...

10:40 asbjxrn: The stack trace is nullpointerexeption -> fn__.... -> function that contains the if

10:41 But if the fn just does a true, that doesn't make a lot of sense to me... I'll try to get a small case into lisppaste.

10:46 lisppaste8: asbjxrn pasted "mysterious (to me) nullPointerException" at http://paste.lisp.org/display/61358

10:46 asbjxrn: Not the best error report, but...

10:47 Uhm...

10:48 I think I see the problem... It's my macro... should insert a do in to my list of statements.

10:51 Or rather merge the list into the fn... Yup, that works.

10:52 rhickey_: I'll be speaking in NYC next Thursday: http://www.nycjava.net/JSPWiki/

10:56 Chouser: ooh, door prizes!

10:56 I'm not too interested in Clojure, but if there are door prizes...

10:56 rhickey_: heh

10:57 I used to speak at this SIG in the 90's on advanced C++

10:57 Chouser: huh!

10:57 rhickey_: (door prizes then too)

10:58 * ozzilee saw "door prizes" pop up in Growl and had to switch windows to check it out :-)

10:58 rhickey_: I'll also be speaking at the Dynamic Languages Symposium at ECOOP 08

11:14 asbjxrn: The previous version of clojure did a cd to the directory when I did a (load-file ...)?

11:15 But not anymore? (svn clojure)

11:18 in my start.clj I just do a (load-file "extras.clj") which was a file in the same dir, that fails now. What is the proper way of doing that? (It's outside the classpath, should I add it to the classpath?)

11:20 CL has *load-truename*/*load-pathname*, anything similar in clojure?

11:21 Or should I look at the lib stuff in contrib?

11:22 rhickey_: never did a cd

11:22 asbjxrn: Hmm. That's funny. It used to work. Maybe aquamacs did it?

11:25 rhickey_: ozzilee: you are good to go now:

11:25 user=> (let [l (new java.util.ArrayList)] l (. l add "foo") (. l remove (int 0)) l)

11:25 []

11:25 ozzilee: rhickey_: Awesome, thanks.

11:27 lisppaste8: cgrand pasted "javadoc (or how to waste a coffee break)" at http://paste.lisp.org/display/61362

11:29 rhickey_: cgrand: cool!

11:30 thanks

12:54 I've renamed some things in primmath.clj - feedback welcome

13:02 drewr: You've got a typo in the definition of EMPTY in boot.clj.

13:09 rhickey_: ok

14:09 ozzilee: rhickey_: Was there every any thought put into making multimethods dispatch on subclasses?

14:13 rhickey_: ozzilee: of course

14:14 type-hierarchy dispatch is a subset of predicate dispatch

14:15 I had a predicate dispatch system in my early prototypes

14:15 requires a mini-prolog engine

14:15 I hope to add both back into Clojure

14:26 ozzilee: rhickey_: Ok, cool. Just curious.

14:27 rhickey_: it's likely to be slower than the current multimethods, more logic to is-implied-by than equals

14:28 ozzilee: Yeah, fair enough.

14:30 While I'm thinking of it, I was looking at writing some general performance tests for Clojure. If you have any code lying around that you use for speed tests I'd like to integrate it.

14:30 (that goes for anyone else as well, I suppose)

14:33 rhickey_: I'm surprised no one's done the shootout stuff yet. The latest stuff I've added should let Clojure do well vs other dynamic langs

14:40 ozzilee: That would be cool. I'm thinking about doing a graph of Clojure performance over history. Shootout performance would be neat to see.

16:08 rhickey_: since they'll usually be namespace-prefixed, I'm thinking about shortening the namespace names for the new math primitives, i.e. double/+ is a bit much to type - one option int/lng/flt/dbl, e.g. dbl/+

16:10 i l f d ?

16:17 drewr: haha

16:21 * ozzilee votes to keep them long

16:29 drewr: I think they should all be the same letter. Easier to remember. :-)

16:37 Chouser: Is there a java function that would cause any watching debuggers to breakpoint?

16:38 There are OS-specific ways to do that in native code -- asm you can embed in C code or whatever. Does Java have something similar?

20:35 njbartlett: Hi, is there any downloadable documentation for Clojure?

20:43 Also is there any documentation on how to call Clojure from Java?

21:16 dudleyf: njbartlett: If you check out Clojure from SVN, there's a clojure.markdown in the root directory

21:17 njbartlett: dudleyf: Aha, thanks

21:17 dudleyf: I'm not sure if the website is generated from that or vice-versa, but it's the same info

21:19 You might look at the source for clojure.lang.Repl for calling Clojure from Java

21:21 njbartlett: dudleyf: Yeah I found that now thanks. Hmm I'm looking at whether I can use Clojure for scripting inside OSGi applications... and the answer appears to be no

21:22 dudleyf: It's not really a scripting language

21:22 njbartlett: Well okay, scripting was the wrong word

21:22 A better language for dealing with the dynamics and concurrency that you get with OSGi

21:22 dudleyf: No, it's the right word, I think

21:23 I don't know much about OSGi

21:27 njbartlett: dudleyf: OSGi is a module system, and it would be nice to be able to isolate Clojure code within each module, but the problem is Clojure seems to be implemented as a gigantic singleton :-(

21:27 Now I might be able to instantiate a classloader for each module just to get an isolated instance of Clojure...

21:28 dudleyf: I think you would need a separate classloader for each "instance" of Clojure you wanted

21:30 njbartlett: Exactly. Which makes me worry if there needs to be any communication between the two modules of Clojure classes. You would get ClassCastExceptions assigning Foo to Foo

21:31 dudleyf: Well, it's the same problem with Java, isn't it?

21:32 njbartlett: How do you mean?

21:34 dudleyf: There's a single, global "environment" in which all classes live

21:36 ClassLoaders are the mechanism for isolating pieces of that environment

21:36 I'm asking, not telling, BTW

21:38 I thought that was one of the problems that OSGi was intended to solve

21:39 njbartlett: Right, but there's also delegation, so only one classloader needs to define java.util.HashMap. All the other classloaders get it from him.

21:39 blackdog: njbartlett, http://groups.google.com/group/clojure/browse_thread/thread/d98cedb860f16a34#

21:40 njbartlett: But if I have to use classloaders to get multiple instances of Clojure, it means multiple classloaders calling defineClass() on the same bytes

21:41 And multiple classloaders defining the same classes means lots of copies of the same class, but the JVM thinks they're different classes

21:41 blackdog: Thanks

21:42 blackdog: yw

21:49 njbartlett: blackdog: Hmm very interesting, but will take some time to digest. Anyway it's certainly not going to be as simple as sticking a bunch of OSGi metadata into clojure.jar :-)

21:55 One last quick question... what version of JVM is required by Clojure?

21:56 rhickey: Java 1.5+

21:57 njbartlett: rhickey: Great, thanks.

Logging service provided by n01se.net