#clojure logs

2008-09-20

13:00ChouserI think because JS is already dynamic, I can make calling clojurescript from java and vice-versa even more transparent.
13:01ChouserJS 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:51rhickeyclojurescript from javascript?
13:54Chousersure, 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:58Chouseroh! yes, sorry, clojurescript from javaSCRIPT.
13:59ChouserI don't think I can write the Collections in cljs without corrupting clojure first. I need access to JS's "this" reserved word.
15:08mhincheyI'm having a problem with metadata. In the repl, (meta first) returns nil. Is that right?
15:10rhickeymhinchey: the metadata is on the var, not the function value, so (meta (var first)) will work
15:10rhickey(meta #'first) is a shorthand
15:10mhincheygot it, thanks
15:29joubertHello
15:29Chouserjoubert: hi
15:29Chousermhinchey: or ^#'first for extra-short-hand
15:29ChouserI miss perl. *sniff*
15:30rhickeyChouser: now, now
15:30joubertI 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:31jouberte.g.
15:31joubert(let [meth 'blahblahmeth] (. myObj meth "miau"))
15:32joubert(this code is only to illustrate the intentional use; it does not actually run)
15:33leafwjoubert: you could solve it with reflection, but I am curious to hear what options clojure offers as well.
15:33Chouser(clojure.lang.Reflector/invokeInstanceMethod "foo" "replace" (to-array ["o" "x"]))
15:34joubertoooh uuuugly
15:34joubert:-)
15:34Chouserhmph.
15:34leafwjoubert: make a macro for it.
15:34Chouseror design your code so you don't need it.
15:34hoeck`joubert: try using a closure: (let [m #(.blablameth % "miau")] (m myObj))
15:34hoeck`
15:35jouberthoeck: that is similar to (memfn) isn't it?
15:36hoeck`joubert: yes, forgot that
15:37jouberthoeck: that means I need to pass in #(.blahblahmeth % "miau") as the param to my function, instead of just "blahblahmeth" or 'blahblahmeth
15:37Chouser#(.method obj arg1)
15:38Chouseryou're putting % in the obj position, not allowing it to call a different method
15:38joubertReflector/invokeInstanceMethod - kosher to call it from apps? Seems like an API that is not intended for use by programs?
15:39lisppaste8rhickey pasted "jcall jfn" at http://paste.lisp.org/display/67182
15:40leafwwhat does the '#' do to the (apply jcall ...) ?
15:40leafwnew to me.
15:41Chouser#(+ 5 %) === (fn [i] (+ 5 i))
15:41leafwshorthand for a lambda?
15:41Chouser#(+ 5 %1 %2) === (fn [i j] (+ 5 i j))
15:41Chouserleafw: exactly
15:41leafwok
15:41leafwthanks.
15:42rhickey#(apply jcall %1 name %&) => (fn [x & etc] (apply jcall x name etc))
15:43leafwbut # is also used for defining a key in a hash set/table, right?
15:43Chouserlooks like memfn might do it too, but I've never used it and am failing to get it to work for me
15:44leafw(if (some #{text} table) ...
15:44Chouserleafw: # is used for several things, all documented here: http://clojure.org/reader
15:44leafwthanks
15:44joubertmemfn doesn't work for this instance, because you cannot pass a symbol to the Clojure syntax for Java member calling
15:46Chouseroh, I see -- memfn's a macro.
15:46Chouserok, that make sense. It's been pretty much superceded by the #() syntax.
15:48leafwwoah, this syntax with %1 %2 ... is really nice. Like using regex for function declarations.
15:49joubertWhat is the performance difference between Reflector/invokeInstanceMethod and just going (. meth obj var) ?
15:50Chouserjoubert: I think the . syntax uses invokeInstanceMethod if it doesn't have sufficient type hints to produce a direct call.
15:51joubertchouser: OK.
15:53joubertIt seems to me a nicety might be to "respect" bindings in invoking methods on objects, or no?
15:54joubert(when resolving the method names)
15:55rhickeyjoubert: no, it's not a dynamic name system, not duck naming. Clojure supports compiled name resolution.
15:56joubertrhickey: does that mean that the . syntax has performance characteristics different from Reflector/invokeInstanceMethod?
15:56rhickey. tries to make a direct call, if names were just values it couldn't
15:56rhickeymuch much faster if it can avoid reflection
15:57joubertOK. I know how to design my solution then. Thanks.
15:57rhickeythe jcall/jfn I posted is dynamic calling
15:58joubertright. I'm not going to go with than.
15:58joubertthat.
16:00Chouserjoubert: that's good to hear. :-)
16:06leafwwhat is the equivalent of 'range' in python? Is there such function in clojure?
16:06Chouseryou might try range
16:07Chouser:-)
16:07leafwxD
16:07leafwwhy do I ask.
16:07Chouser(doc range), if that helps
16:09leafwthanks.
16:12joubertchouser, rhickey, leafw: (defmacro runSetter [setterSym target value] `(. ~target ~setterSym ~value))
16:13joubertand then you can (runSetter methodName myObj val)
16:15joubertbut still cannot pass a symbol, because its name cannot be resolved in the context.
16:15joubertanyway, just wanted to add this dimension to my initial Q.
16:20leafwhow 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:20leafwthat'd be useful.
16:22ChouserHow would it know which class's method you're talking about?
16:23rhickeydidn't someone do a javadoc that loaded the right page in the browser?
16:24ChouserI use this: http://paste.lisp.org/display/67122#1
16:25leafwChouser: (show ij.IJ/log) fails ... fails for a static method
16:27Chouserstart with the class (or an instance) to list all methods and fields.
16:27Chouser(show ij.IJ)
16:27Chouserthen pick the method you want out of the list: (show ij.IJ 9)
16:28leafwgot it.
16:28leafwwill edit it to take the string and search it. Thanks for sharing.
16:30leafwa jdoc builtin function, or evne just doc with some magic on it, would be great. Just a suggestion.
16:31rhickeysomeone did it in a paste somewhere...
16:31rhickeyhttp://clj-me.blogspot.com/2008/05/jumping-to-javadocs-from-repl.html
16:33Chouserwow
16:37rhickeyyeah, cgrand rocks, I miss him
16:40rhickeyif only Sun would cough up JWebPane...
16:40rhickeysaw it at JavaOne, totally awesome Java wrapper on WebKit
16:41Chouserah, interesting.
16:41rhickeythen we could run ClojureScript in a Java hosted browser window :)
16:42ChouserOr perhaps run the ClojureScript as Clojure instead, and make V8 look like molasses
16:43Chouser<script type="test/clojurescript">...
16:43Chouserer, text
16:43rhickeyyes, the access to the DOM etc from Java was great - they seemed to have all the right ideas
17:56mhincheyI'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:05rhickeymhinchey: I don't know, the CLs I've used have pushed the * evals too
18:12mhincheyrhickey: alright, I'll post to the group, see what others think
19:46abrooks:w
19:47abrookser... hm. Not so much Vim.
20:28Chouserrhickey: do you have a CA from Erik Soehnel? I want to use his multimethod print.
20:29rhickeyyes, I'm hoping to get that print into Clojure proper soon
20:34Chouseroh, well that would be even easier. :-)
21:15alecIs 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:15alec(using openjdk-6)
21:16Chouseralec: 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:18alecI don't see anything on the website about precompiling the Clojure source to bytecode; is that possible?
21:19Chouserno, not presently.
21:19Chouseryou're using the release from this month?
21:19alecsvn from the other day
21:19rhickeyalec: what OS? anything on the classpath?
21:20dudleyfIt's about 4 seconds on my MBP
21:20alecrunning Debian amd64
21:20alecnothing else in the classpath, but Debian's openjdk may load other things in, let me see if I can disable that
21:22alecno, setting $CLASSPATH to only the Clojure jar file didn't speed things up
21:23abrooksrhickey: By Cliff Click's megaboxen you mean Azul Systems Vega 3?
21:23rhickeythere is a (non-Clojure) issue with JDK6 and ever increasing classloading times, which seems to impact Clojure on Linux/Windows
21:24rhickeyabrooks: dunno the model
21:25abrooksWow. The Vega 3 is spiffy: 864 processor cores and 768 GB of memory in a flat SMP configuration.
21:27rhickeyHe'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:31abrooksrhickey: Cool. I'd be interested to hear how that goes.
21:32abrooksrhickey: How did you get access to one of these?
21:32rhickeyHe's got one, not me :)
21:33abrooksOh, this is directly via Cliff Click?
21:33rhickeyyes
21:34akingSee Cliff's blog about it: http://blogs.azulsystems.com/cliff/
21:34abrooksCool. Do you know Cliff well?
21:34rhickeynope. We're both speaking at the JVM languages summit next week. We've only spoken on the group and his blog
21:37abrooksOh, frick. I didn't realize cliffc was Cliff Click.
21:37abrooksHeh.
21:38abrooksrhickey: Sounds like he's skeptical about the scaling benefits of STMs.
21:39abrooks... hence your inerest in running a large scale Clojure app on his systems...
21:39abrooks^inerest^interest
21:43rhickeyhe'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:45rhickeymy ACO broke out of a local minimum after 10 minutes - woo hoo!
21:47abrooksrhickey: How big is the universe? (4-way connected?)
21:48abrooksCongrats, BTW. :)
21:48Chouserboot.js loads now
21:49rhickeyabrooks: it's a 280 node (2-D) tour
22:14abrooksThe 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:15abrooksWe = my employer, in this case.
22:15rhickeyhave you got Clojure running on that?
22:17abrooksNo. 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:19abrooksIt would be interesting to see how the JVM runs with slow cores with fast memory.