#clojure logs

2008-05-28

09:04ozzileeI'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?
09:05rhickey_(. x method (int arg))
09:07ozzileeHmmm. Ok.
09:07rhickey_dpes that not work?
09:07rhickey_does
09:07ozzileeI'm not sure, I think I might have another problem.
09:09ozzileeIs there a way to list the methods an object supports?
09:10rhickey_(-> "fred" .getClass .getMethods seq)
09:11asbjxrnThat is a keeper. That's one thing I've wished to do more than once.
09:14ozzilee(let [l (new java.util.ArrayList)] l (. l add "foo") (. l remove (int 0)) l) ;[foo]
09:15ozzileeShould that not remove "foo" at index 0?
09:15ozzilee(let [l (new java.util.ArrayList)] l (. l add 1) (. l remove (int 1)) l); []
09:15ozzileeYeah, (int) doesn't do it.
09:17rhickey_ack - I see, nasty overloads - let me look into it
09:17ozzileeYup, nasty overloads indeed. Thanks.
09:52asbjxrnis there a way of printing arguments/return values as well with that (-> "fred" .getClass .getMethods seq) call?
09:55rhickey_Those are instance of the class java.lang.reflect.Method and have all of its functionality:
09:56rhickey_(map #(vector (.getReturnType %) (seq (.getParameterTypes %))) (-> "fred" .getClass .getMethods seq))
10:00asbjxrnThanks, looking closer at the output, it seems printing the results of .getMethods prints it's expected arguments, so no need for the getParameterTypes
10:01rhickey_it prints its returns too
10:01asbjxrnYou're right, of course.
10:02rhickey_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:04asbjxrnUnderstand. 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:07asbjxrn(I have to search web docs a lot... Kinda unfamiliar with the java libraries.)
10:09rhickey_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:13asbjxrnShould be possible, shouldn't it? I'
10:14rhickey_of all things, IIRC launching the browser portably under JDK 5 is somehow difficult
10:14asbjxrnI would guess on OSX and Windows it's a matter of doing an open on the URI?
10:17asbjxrnLinux/other_unix_varieties is a problem of course. Which may mean that it may be difficult to do it portably.
10:23cgrandfor displaying javadocs the swing HTML component may suffice (or provide a fallback method if not JDK6)
10:25rhickey_cgrand: yes, probably fine for javadocs
10:25jteoisn't that why IDEs exist?
10:26rhickey_yes, IDEs exist so you can wait for them to add features :)
10:26jteo;)
10:26jteohehe
10:26rhickey_But I imagine the 20 lines or so of Clojure this would take would be useful everywhere there is a Clojure REPL
10:31jteoyou're biased. ;)
10:35asbjxrnFor 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:37asbjxrnI 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:38rhickey_what are you doing with the value of the if expression itself?
10:38asbjxrnnothing, it's just a series of statements.
10:39rhickey_you'll have to look at the stack trace...
10:40asbjxrnThe stack trace is nullpointerexeption -> fn__.... -> function that contains the if
10:41asbjxrnBut 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:46lisppaste8asbjxrn pasted "mysterious (to me) nullPointerException" at http://paste.lisp.org/display/61358
10:46asbjxrnNot the best error report, but...
10:47asbjxrnUhm...
10:48asbjxrnI think I see the problem... It's my macro... should insert a do in to my list of statements.
10:51asbjxrnOr rather merge the list into the fn... Yup, that works.
10:52rhickey_I'll be speaking in NYC next Thursday: http://www.nycjava.net/JSPWiki/
10:56Chouserooh, door prizes!
10:56ChouserI'm not too interested in Clojure, but if there are door prizes...
10:56rhickey_heh
10:57rhickey_I used to speak at this SIG in the 90's on advanced C++
10:57Chouserhuh!
10:57rhickey_(door prizes then too)
10:58rhickey_I'll also be speaking at the Dynamic Languages Symposium at ECOOP 08
11:14asbjxrnThe previous version of clojure did a cd to the directory when I did a (load-file ...)?
11:15asbjxrnBut not anymore? (svn clojure)
11:18asbjxrnin 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:20asbjxrnCL has *load-truename*/*load-pathname*, anything similar in clojure?
11:21asbjxrnOr should I look at the lib stuff in contrib?
11:22rhickey_never did a cd
11:22asbjxrnHmm. That's funny. It used to work. Maybe aquamacs did it?
11:25rhickey_ozzilee: you are good to go now:
11:25rhickey_user=> (let [l (new java.util.ArrayList)] l (. l add "foo") (. l remove (int 0)) l)
11:25rhickey_[]
11:25ozzileerhickey_: Awesome, thanks.
11:27lisppaste8cgrand pasted "javadoc (or how to waste a coffee break)" at http://paste.lisp.org/display/61362
11:29rhickey_cgrand: cool!
11:30rhickey_thanks
12:54rhickey_I've renamed some things in primmath.clj - feedback welcome
13:02drewrYou've got a typo in the definition of EMPTY in boot.clj.
13:09rhickey_ok
14:09ozzileerhickey_: Was there every any thought put into making multimethods dispatch on subclasses?
14:13rhickey_ozzilee: of course
14:14rhickey_type-hierarchy dispatch is a subset of predicate dispatch
14:15rhickey_I had a predicate dispatch system in my early prototypes
14:15rhickey_requires a mini-prolog engine
14:15rhickey_I hope to add both back into Clojure
14:26ozzileerhickey_: Ok, cool. Just curious.
14:27rhickey_it's likely to be slower than the current multimethods, more logic to is-implied-by than equals
14:28ozzileeYeah, fair enough.
14:30ozzileeWhile 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:30ozzilee(that goes for anyone else as well, I suppose)
14:33rhickey_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:40ozzileeThat would be cool. I'm thinking about doing a graph of Clojure performance over history. Shootout performance would be neat to see.
16:08rhickey_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:10rhickey_i l f d ?
16:17drewrhaha
16:29drewrI think they should all be the same letter. Easier to remember. :-)
16:37ChouserIs there a java function that would cause any watching debuggers to breakpoint?
16:38ChouserThere 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:35njbartlettHi, is there any downloadable documentation for Clojure?
20:43njbartlettAlso is there any documentation on how to call Clojure from Java?
21:16dudleyfnjbartlett: If you check out Clojure from SVN, there's a clojure.markdown in the root directory
21:17njbartlettdudleyf: Aha, thanks
21:17dudleyfI'm not sure if the website is generated from that or vice-versa, but it's the same info
21:19dudleyfYou might look at the source for clojure.lang.Repl for calling Clojure from Java
21:21njbartlettdudleyf: 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:22dudleyfIt's not really a scripting language
21:22njbartlettWell okay, scripting was the wrong word
21:22njbartlettA better language for dealing with the dynamics and concurrency that you get with OSGi
21:22dudleyfNo, it's the right word, I think
21:23dudleyfI don't know much about OSGi
21:27njbartlettdudleyf: 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:27njbartlettNow I might be able to instantiate a classloader for each module just to get an isolated instance of Clojure...
21:28dudleyfI think you would need a separate classloader for each "instance" of Clojure you wanted
21:30njbartlettExactly. 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:31dudleyfWell, it's the same problem with Java, isn't it?
21:32njbartlettHow do you mean?
21:34dudleyfThere's a single, global "environment" in which all classes live
21:36dudleyfClassLoaders are the mechanism for isolating pieces of that environment
21:36dudleyfI'm asking, not telling, BTW
21:38dudleyfI thought that was one of the problems that OSGi was intended to solve
21:39njbartlettRight, but there's also delegation, so only one classloader needs to define java.util.HashMap. All the other classloaders get it from him.
21:39blackdognjbartlett, http://groups.google.com/group/clojure/browse_thread/thread/d98cedb860f16a34#
21:40njbartlettBut if I have to use classloaders to get multiple instances of Clojure, it means multiple classloaders calling defineClass() on the same bytes
21:41njbartlettAnd multiple classloaders defining the same classes means lots of copies of the same class, but the JVM thinks they're different classes
21:41njbartlettblackdog: Thanks
21:42blackdogyw
21:49njbartlettblackdog: 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:55njbartlettOne last quick question... what version of JVM is required by Clojure?
21:56rhickeyJava 1.5+
21:57njbartlettrhickey: Great, thanks.