#clojure log - Sep 20 2008

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

13:00 Chouser: I think because JS is already dynamic, I can make calling clojurescript from java and vice-versa even more transparent.

13:01 JS already unifies "package" and "class", as they're all just Objects, and sincs clojure namespaces will also just be an Object, they're all already unified.

13:51 rhickey: clojurescript from javascript?

13:54 Chouser: sure, probably most common will be to define a function in clojurescript and hand it off to the DOM to be called on an event.

13:58 oh! yes, sorry, clojurescript from javaSCRIPT.

13:59 I don't think I can write the Collections in cljs without corrupting clojure first. I need access to JS's "this" reserved word.

15:08 mhinchey: I'm having a problem with metadata. In the repl, (meta first) returns nil. Is that right?

15:10 rhickey: mhinchey: the metadata is on the var, not the function value, so (meta (var first)) will work

15:10 (meta #'first) is a shorthand

15:10 mhinchey: got it, thanks

15:29 joubert: Hello

15:29 Chouser: joubert: hi

15:29 mhinchey: or ^#'first for extra-short-hand

15:29 I miss perl. *sniff*

15:30 rhickey: Chouser: now, now

15:30 joubert: I would like to call a method on a Java object. However, the method name is unknown to the caller code, and must be passed to it in a variable.

15:31 e.g.

15:31 (let [meth 'blahblahmeth] (. myObj meth "miau"))

15:32 (this code is only to illustrate the intentional use; it does not actually run)

15:33 leafw: joubert: you could solve it with reflection, but I am curious to hear what options clojure offers as well.

15:33 Chouser: (clojure.lang.Reflector/invokeInstanceMethod "foo" "replace" (to-array ["o" "x"]))

15:34 joubert: oooh uuuugly

15:34 :-)

15:34 Chouser: hmph.

15:34 leafw: joubert: make a macro for it.

15:34 Chouser: or design your code so you don't need it.

15:34 hoeck`: joubert: try using a closure: (let [m #(.blablameth % "miau")] (m myObj))

15:34

15:35 joubert: hoeck: that is similar to (memfn) isn't it?

15:36 hoeck`: joubert: yes, forgot that

15:37 joubert: hoeck: that means I need to pass in #(.blahblahmeth % "miau") as the param to my function, instead of just "blahblahmeth" or 'blahblahmeth

15:37 Chouser: #(.method obj arg1)

15:38 you're putting % in the obj position, not allowing it to call a different method

15:38 joubert: Reflector/invokeInstanceMethod - kosher to call it from apps? Seems like an API that is not intended for use by programs?

15:39 lisppaste8: rhickey pasted "jcall jfn" at http://paste.lisp.org/display/67182

15:40 leafw: what does the '#' do to the (apply jcall ...) ?

15:40 new to me.

15:41 Chouser: #(+ 5 %) === (fn [i] (+ 5 i))

15:41 leafw: shorthand for a lambda?

15:41 Chouser: #(+ 5 %1 %2) === (fn [i j] (+ 5 i j))

15:41 leafw: exactly

15:41 leafw: ok

15:41 thanks.

15:42 rhickey: #(apply jcall %1 name %&) => (fn [x & etc] (apply jcall x name etc))

15:43 leafw: but # is also used for defining a key in a hash set/table, right?

15:43 Chouser: looks like memfn might do it too, but I've never used it and am failing to get it to work for me

15:44 leafw: (if (some #{text} table) ...

15:44 Chouser: leafw: # is used for several things, all documented here: http://clojure.org/reader

15:44 leafw: thanks

15:44 joubert: memfn doesn't work for this instance, because you cannot pass a symbol to the Clojure syntax for Java member calling

15:46 Chouser: oh, I see -- memfn's a macro.

15:46 ok, that make sense. It's been pretty much superceded by the #() syntax.

15:48 leafw: woah, this syntax with %1 %2 ... is really nice. Like using regex for function declarations.

15:49 joubert: What is the performance difference between Reflector/invokeInstanceMethod and just going (. meth obj var) ?

15:50 Chouser: joubert: I think the . syntax uses invokeInstanceMethod if it doesn't have sufficient type hints to produce a direct call.

15:51 joubert: chouser: OK.

15:53 It seems to me a nicety might be to "respect" bindings in invoking methods on objects, or no?

15:54 (when resolving the method names)

15:55 rhickey: joubert: no, it's not a dynamic name system, not duck naming. Clojure supports compiled name resolution.

15:56 joubert: rhickey: does that mean that the . syntax has performance characteristics different from Reflector/invokeInstanceMethod?

15:56 rhickey: . tries to make a direct call, if names were just values it couldn't

15:56 much much faster if it can avoid reflection

15:57 joubert: OK. I know how to design my solution then. Thanks.

15:57 rhickey: the jcall/jfn I posted is dynamic calling

15:58 joubert: right. I'm not going to go with than.

15:58 that.

16:00 Chouser: joubert: that's good to hear. :-)

16:06 leafw: what is the equivalent of 'range' in python? Is there such function in clojure?

16:06 Chouser: you might try range

16:07 :-)

16:07 leafw: xD

16:07 why do I ask.

16:07 Chouser: (doc range), if that helps

16:09 leafw: thanks.

16:12 joubert: chouser, rhickey, leafw: (defmacro runSetter [setterSym target value] `(. ~target ~setterSym ~value))

16:13 and then you can (runSetter methodName myObj val)

16:15 but still cannot pass a symbol, because its name cannot be resolved in the context.

16:15 anyway, just wanted to add this dimension to my initial Q.

16:20 leafw: how come doc throws an Exception for java methods? Why not just print nothing, or at least the signature of its arguments and return type?

16:20 that'd be useful.

16:22 Chouser: How would it know which class's method you're talking about?

16:23 rhickey: didn't someone do a javadoc that loaded the right page in the browser?

16:24 Chouser: I use this: http://paste.lisp.org/display/67122#1

16:25 * Chouser slogs away implmenting EmptyList in JavaScript -- so dull

16:25 leafw: Chouser: (show ij.IJ/log) fails ... fails for a static method

16:27 Chouser: start with the class (or an instance) to list all methods and fields.

16:27 (show ij.IJ)

16:27 then pick the method you want out of the list: (show ij.IJ 9)

16:28 leafw: got it.

16:28 will edit it to take the string and search it. Thanks for sharing.

16:30 a jdoc builtin function, or evne just doc with some magic on it, would be great. Just a suggestion.

16:31 rhickey: someone did it in a paste somewhere...

16:31 http://clj-me.blogspot.com/2008/05/jumping-to-javadocs-from-repl.html

16:33 Chouser: wow

16:37 rhickey: yeah, cgrand rocks, I miss him

16:40 if only Sun would cough up JWebPane...

16:40 saw it at JavaOne, totally awesome Java wrapper on WebKit

16:41 Chouser: ah, interesting.

16:41 rhickey: then we could run ClojureScript in a Java hosted browser window :)

16:42 Chouser: Or perhaps run the ClojureScript as Clojure instead, and make V8 look like molasses

16:43 <script type="test/clojurescript">...

16:43 er, text

16:43 rhickey: yes, the access to the DOM etc from Java was great - they seemed to have all the right ideas

17:56 mhinchey: I'm working on adding the *1 vars to swank-clojure, which has its own repl. I think it would be helpful if evaluating *1 *2 or *3 doesn't reset those vars. That way, if you don't loose the values by simply checking one of them. Does that make sense?

18:05 rhickey: mhinchey: I don't know, the CLs I've used have pushed the * evals too

18:12 mhinchey: rhickey: alright, I'll post to the group, see what others think

19:46 abrooks: :w

19:47 er... hm. Not so much Vim.

20:28 Chouser: rhickey: do you have a CA from Erik Soehnel? I want to use his multimethod print.

20:29 rhickey: yes, I'm hoping to get that print into Clojure proper soon

20:34 Chouser: oh, well that would be even easier. :-)

20:36 * rhickey is writing an ant colony optimizer for the TSP to run on Cliff Click's megaboxen

21:15 alec: Is it expected for Clojure to take a long time starting up? I installed from svn using maven, and when I run 'java clojure.lang.Script <empty file>', it takes 6 seconds to finish

21:15 (using openjdk-6)

21:16 Chouser: alec: I've heard reports approaching that. I don't know if my faster startup time is just due to a fast machine or something else.

21:18 alec: I don't see anything on the website about precompiling the Clojure source to bytecode; is that possible?

21:19 Chouser: no, not presently.

21:19 you're using the release from this month?

21:19 alec: svn from the other day

21:19 rhickey: alec: what OS? anything on the classpath?

21:20 dudleyf: It's about 4 seconds on my MBP

21:20 alec: running Debian amd64

21:20 nothing else in the classpath, but Debian's openjdk may load other things in, let me see if I can disable that

21:22 no, setting $CLASSPATH to only the Clojure jar file didn't speed things up

21:23 abrooks: rhickey: By Cliff Click's megaboxen you mean Azul Systems Vega 3?

21:23 rhickey: there is a (non-Clojure) issue with JDK6 and ever increasing classloading times, which seems to impact Clojure on Linux/Windows

21:24 abrooks: dunno the model

21:25 abrooks: Wow. The Vega 3 is spiffy: 864 processor cores and 768 GB of memory in a flat SMP configuration.

21:27 rhickey: He's asked for some non-Java programs, so I've got a parallel ant colony optimization of the traveling salesman problem - < 100 lines of Clojure, looking to see how it scales

21:31 abrooks: rhickey: Cool. I'd be interested to hear how that goes.

21:32 rhickey: How did you get access to one of these?

21:32 rhickey: He's got one, not me :)

21:33 abrooks: Oh, this is directly via Cliff Click?

21:33 rhickey: yes

21:34 aking: See Cliff's blog about it: http://blogs.azulsystems.com/cliff/

21:34 abrooks: Cool. Do you know Cliff well?

21:34 rhickey: nope. We're both speaking at the JVM languages summit next week. We've only spoken on the group and his blog

21:37 abrooks: Oh, frick. I didn't realize cliffc was Cliff Click.

21:37 Heh.

21:38 rhickey: Sounds like he's skeptical about the scaling benefits of STMs.

21:39 ... hence your inerest in running a large scale Clojure app on his systems...

21:39 ^inerest^interest

21:43 rhickey: he's still in a pretty rarefied domain. No matter how many cores we get, most apps will have trouble thinking of more than a few dozen things to do at once. Using every core becomes the job of the next layer - VM/OS/whatever is running the multiple apps. I'm pretty sure STM will work where most apps are using locks, with greater ease and more robustness

21:45 my ACO broke out of a local minimum after 10 minutes - woo hoo!

21:47 abrooks: rhickey: How big is the universe? (4-way connected?)

21:48 Congrats, BTW. :)

21:48 Chouser: boot.js loads now

21:49 rhickey: abrooks: it's a 280 node (2-D) tour

22:14 abrooks: The Vega 3 looks quite interesting. We get 1458 (vs 864) cores and 1944GB (vs 768) in roughly the same rack space (a bit more with fans and power) but ours is across 243 (6 core) nodes. 864 cores seeing 768GB in flat SMP is impressive (and sadly useless for most applications).

22:15 We = my employer, in this case.

22:15 rhickey: have you got Clojure running on that?

22:17 abrooks: No. We currently have a JVM half ported (running interpreted, non-JIT). Not enough serious HPC customers are out there. No one has asked for Java yet.

22:19 It would be interesting to see how the JVM runs with slow cores with fast memory.

Logging service provided by n01se.net