#clojure logs

2008-09-29

08:18pjb3rhickey: Are we going to be seeing tonight's presentation as the next episode on Clojure TV? :)
10:42Chouser(gen-and-load-class 'Foo)
10:42ChouserIs there any value in that, when no package name is given?
10:43ChouserI can't refer to Foo from within Clojure, apparently. Is that a weakness of Clojure, or is it just completely broken to gen a class with no package?
10:44abrooksChouser: Ah, that happens with gen-class as well as gen-interface?
10:45Chouserit appears to.
11:31StartsWithKwhat is a real difference between `(args..) and '(args...)?
11:32ozzileeStartsWithK: One is sugar for (quasiquote args), the other is sugar for (quote args). Except Clojure doesn't seem to actually have quote and quasiquote macros...
11:33StartsWithKi created some macros up to now, but they were very simple and i copied parts of them from what i found on the net
11:34StartsWithKnow i would like to create one complex macro and im stuck with this kind of basics
11:34StartsWithKwhat should quasiquote do?
11:34ozzileeStartsWithK: Ah, gotcha. The difference is, ` allows you to use ~ to unquote parts of forms.
11:34ozzileeFor example, if I say (def foo "foo"), '(foo bar) gives me a list of two symbols, foo and bar.
11:35ozzileeHowever, `(~foo bar) gives me the string "foo" and the symbol bar.
11:35ozzileeA macro returns a list of the symbols that should be inserted into the code. With `, you can insert the arguments to the macro using ~.
11:36ozzilee(defmacro macro-println [arg] `(println ~arg))
11:36ozzilee(macro-println "foo") will insert (println "foo") into your code.
11:37StartsWithKwhat if i have [& args] and would like to kreate separate println for each arg, but using loop construct?
11:37danlarkinozzilee: so "," in common lisp becomes ~ in clojure?
11:38ozzileedanlarkin: Yup. "," is treated as whitespace.
11:38Chouser(quote foo) works in clojure
11:38ozzileeChouser: Oh, you're right. quote by itself didn't evaluate, my mistake.
11:39ChouserStartsWithK: it's all about building the data structure that you want clojure to eval.
11:39danlarkinozzilee: do you know why ~ was chosen instead of ,? To ease the transition from lists separated with commas?
11:39ozzileedanlarkin: Exactly that, I beliebe.
11:40ozzilee*believe.
11:40ChouserStartsWithK: it helps if you start by writing out an example call to your macro, and the exact code you want your macro to produce in that case.
11:40Chouserthen start working on your macro, using (macroexpand ...) to check that you're producing what you want.
11:41StartsWithKChouser: yes, i tried to create smaller part, i have some macros that demonstrate different parts of it, but i cant make them work as a one
11:41StartsWithKhttp://pastebin.com/d21addbfb
11:41StartsWithKthis is what i tried for generating code with loop, it fails
11:42Chouseryeah, the m# syntax is likely to be insufficient for you
11:42Chouserthat works ok for simple macros, but in more complicated ones it often just makes things harder. You can only use it in a single level of `()
11:43Chouserinstead, try (let [m (gensym) parts (gensym)] ...)
11:44wwmorganin the sample you pasted, the m# forms aren't inside a macro quote
11:44StartsWithKhmm, how will that work for loop? (loop [m (gensym)]).. but where do i assoc
11:45StartsWithKwwmorgan: i tried it as described at http://www.greenwave-solutions.com/blog/files/20-Days-of-Clojure-Day-19.html
11:46wwmorganStartsWithK: you're right. that does work
11:46ChouserI think you're getting confused as to which bits of code are working to build your resulting data, and which bits of code are *in* your resulting data. This is a very common problem when writing macros.
11:47StartsWithKyour right, it is confusing, at least now when im just starting
11:49StartsWithKi looked how (clojure/doto) and (clojure/proxy) macros work, and i'm lost
11:49wwmorganStartsWithK: I think this will do what you're trying to do http://pastebin.com/m4f337152
11:50StartsWithKwwmorgan: that could work i think
11:51StartsWithKhttp://pastebin.com/d65f1b7dd
11:52StartsWithKoriginal clojure/doto creates duplicate (let), one outside syntax quotes and then again one inside them
11:53StartsWithKthis way it can evaluate x form before entering macro body?
11:54ChouserStartsWithK: It needs two because the outer one is to define a local xs which is only used when the macro is running (at compile time) *not* in the code that gets produced.
11:54ChouserThe second let will actually show up in the output
11:54ChouserThat second let is the one you see if you do: (macroexpand-1 '(doto foo bar))
11:55StartsWithKcompile time = macro expansion time?
12:44danlarkinis there a clojure equivalent for the common lisp #' ?
12:44danlarkinie to get a function literal
12:46wwmorgandanlarkin: Clojure is a lisp-1. Functions belong to the same namespace as non-functions
12:46danlarkinah ha
12:47danlarkinwwmorgan: thanks
13:05ozzileeHas anyone tried running Clojure on the Jam VM?
13:08achim_phi!
13:11achim_prhickey: i uploaded my first attempt at implementing jmap along with some examples to the group's file area
13:11achim_phttp://groups.google.com/group/clojure/web/jmap.diff
13:11achim_phttp://groups.google.com/group/clojure/web/jmap-examples.clj
13:11achim_pin case you consider including it: the CA is on its way. let me know if it needs some more work.
13:12leafwcan all symbols declared in an interface be imported into the current namespace, with a namespace command?
13:13leafwsomething like (import-all ij.measure.Measurements current-namespace)
13:15achim_pleafw: you'd like all methods of Measurements to become functions in current-namespace? i don't think that's possible out of the box, but probably not much work (via memfn and reflection)
13:16leafwwell, actually all fields. The interface only has fields.
13:16leafwyes I could do a macro ... just wondering whether it existed.
14:32leafwneed rescue from loop-oriented mindset ...
14:33leafwI have two arrays of equal length, of ints, which I have to compare: make the log10 of both values; when both values are identical, set a 0, when different, set a 1 or a -1 (depending on which one is larger)
14:34leafwcan one 'reduce' over two lists?
14:35danlarkinyou can zip! At least it's zip in python... let me see what clojure calls it again...
14:38wwmorganleafw: you might try this (map compare (map log10 as) (map log10 bs))
14:38leafwinteresting
14:39leafwthank you wwmorgan
14:39leafwreally neat
14:39leafw(doc compare), didn't know about this one
14:46leafwcan't map Math/log10, always fails. (memfn Math/log10) also fails.
14:49leafwalso: weird bug: this works: (into-array '(1.01 2.0 3.0)) .. but this does NOT work: (into-array '(1.01 2 3.0)) --- note the '2' instead of '2.0'
14:50abrooksleafw: (map #(.log10 Math %) [1 2 3])
14:50abrooksOr, if you prefer #(. Math log10 %)
14:51leafwabrooks: it's a bit overkill to make a function to wrap log10 .. can't a java method be mapped as if it was a function?
14:51abrooksI don't know if menfn would work with ".".
14:51abrooksI think . is builtin syntax.
14:52danlarkinah ha! found it... interleave is the function I was trying to remember
14:52leafwthe dot should work
14:52leafwbut it's not desired anymore for static fields and methods
15:02Chouseror #(Math/log10 %) -- something like that is indeed necessary to get a clojure function from a java method.
15:03danlarkinwhat is the % doing in this context? is it part of the java math library? or some syntax
15:03leafwdanlarkin: argument placement
15:03leafwyo ucn use %1 %2 %3 ...
15:04Chouser#( ) with a % in it is just a shortcut for (fn [...] ...)
15:04Chouseras leafw is describing. :-)
15:04leafw(map #(/ (+ %2 10) %1)) '(1 2 3 4))
15:04leafwsorry
15:04leafwthat took two args, needed a reduce
15:04leafwxD
15:04leafwnot a map.
15:04danlarkinI see
15:06danlarkinthanks
15:06leafw(reduce #(/ (+ %2 10) %1) '(1 2 3 4))
15:06leafwsure.
15:07danlarkinI simplified it to help me understand :-D: (def a #(/ %1 %2)) (a 4 5)
15:07leafwI love these regex-args functions
15:08leafwall cruft is gone, just write what you mean.
17:13danlarkinI have a question about identity... http://paste.lisp.org/display/67632
17:14danlarkinwhy does the last form return false?
17:16leafwnot the same type?
17:16leafwbut then the 3rd should be false too
17:16danlarkinright
17:16leafwan ordering problem?
17:17leafw(seq l) may have reverted the order of the elements
17:17wwmorganthey don't refer to the same object
17:17wwmorganidentical? is akin to java =
17:17leafwyou mean java ==
17:17wwmorganyes
17:17leafwwwmorgan: but then the 3rd identity should fail as well
17:18Chouserthis is really subtle, but I think I have it.
17:18leafwsorry 3rd line
17:18ozzileeleafw: My guess is because (seq l) just returns l unaltered
17:18ChouserPersistentList implements ISeq, so when you do (seq l), it just returned itself
17:19leafwozzilee: yoru guess is, according, to Chouser, right.
17:19leafwbrb
17:19Chouserso your first "identical?" is comparing your original list with itself -- true.
17:19ozzilee(identical? l '(a b c)) is illuminating
17:20leafwindeed.
17:20danlarkinozzilee: as is (identical? '(a b c) '(a b c))
17:20ozzileedanlarkin: Indeed.
17:20Chouserin your second "identical?" you create two different PersistentList objects -- false
17:20danlarkinthat answers my question, thanks everyone
17:20Chouseryou almost never want to use "identical?", you want "="
17:26StartsWithKlisppaste8: help
17:26lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
17:28lisppaste8StartsWithK pasted "Extended doto" at http://paste.lisp.org/display/67633
17:29stuarthallowayI have posted a spike for ClojureCheck on the mailing list. If anybody here would like to discuss in real time I'd love feedback.
17:50danlarkineek... the series of invoke definitions at the bottom of src/jvm/clojure/lang/Ref.java is an interesting way to do things
18:54wwmorganI wrote a script in clojure that takes a clojure source file as input and uses the functions pr and read to copy the code to a new file. Somehow, the resulting output code is 10 times slower than the input on our tests. Any ideas before I go chasing this one?
21:10metasyntaxhi, I just happened to find Clojure and it looks interesting
21:10metasyntaxand perhaps I just missed it on the site but
21:10metasyntaxis there a way to load Clojure code and call Clojure-defined functions from Java?
21:23danlarkinmetasyntax: you can use some of the data structures but not the code, I don't believe
21:49metasyntaxdanlarkin: http://en.wikibooks.org/wiki/Clojure_Programming#Invoking_Clojure_from_Java
21:50metasyntaxdanlarkin: seems like it is possible; at least this example works, cool
21:50danlarkinmetasyntax: yeah I guess you're right, very cool!
22:14danlarkin(defn [] (first (foo)))
22:14danlarkinit surprises me that that form throws an exception
22:14danlarkinoh
22:14danlarkinwait
22:14Chouser:-)
22:14Chouserthere it is.
22:15danlarkin(defn bam [] (first (foo)))
22:15danlarkinthere we go.. that's what surprises me
22:15danlarkinwhy does foo need to be defined for me to define bam
22:15Chouserbecause it gets resolved and compiled into bytecode
22:16Chouserit's faster to resolve at compile time and let the runtime be a direct java method call.
22:16danlarkin:-/ dtable lookups aren't that slow
22:18Chousercompared to an inline-able java call?
22:19danlarkinprofiling objc shows a fraction of time spent in method lookup
22:20danlarkincan I define a function but delay compilation until I try to use it?
22:20Chouseryou can def the var and re-def (or use thread binding) to change the value later.
22:23danlarkinhard to get used to knowing lisp, scheme and python
22:25ChouserI've done quite a bit of python and haven't had too much trouble in real programs with this
22:26Chouseryou'll find that (after startup cost) clojure runs quite a bit faster than python.
22:26albinothe startup time is the problem though
22:26albinofor one off scripts
22:27Chouseryeah, it's something to work on. I've heard of a couple possible solutions knocking around. Nothing concrete yet, afaik.
22:27waltersit won't be that way forever; there are some not too hard things to fix in openjdk to improve startup time
22:27albinowalters: like what?
22:28waltersalbino: using an mmap cache for system installed classfiles instead of unzipping and reverifying every jar would help...
22:29albinoanyone tried to run clojure on top of nailgun? http://www.martiansoftware.com/nailgun/
22:41albinoI think my struggle with immutability is harming my motivation for learning factor
22:41albinoany advice on how to overcome that?
22:41albinoerr clojure
22:41albinosorry, I did mean clojure
22:42arohnerwhat kinds of struggles are you having?
22:42ChouserI'd recommend starting with small problems and work up. I enjoyed projecteuler.net
22:43danlarkinI have another newbie question... I see all the clojure source in clojure-contrib using named imports ie (import '(java.util.logging Logger Level)) -- And I see java source using iport java.util.logging.* -- can I do the latter in clojure? Is there a reason (other than namespace) that I wouldn't want to?
22:44danlarkin /s/iport/import
22:44arohnerI don't believe there is an import * in clojure
22:46arohnerhttp://groups.google.com/group/clojure/msg/ddca7ec56ea8b51f
22:47danlarkinarohner: perfect answer, thanks :D
22:49Chouseralbino: don't give up. Even if you end up ditching clojure, learning to work with immutable data structures will help you write better code in any language.
22:49ChouserIMHO. :-)
22:55blackdogi haven't tried this, but it made a big diff to jruby starup time
22:55blackdogHere's another from me, which I've posted about previously:
22:55blackdog-XX:bootclasspath and friends. JRuby is a Ruby implementation, which
22:55blackdogmeans it needs to perform reasonably well as a command-line tool.
22:56blackdogTypical JVM startup precludes fast command-line startup, but it turns
22:56blackdogout a large portion of that time is spent verifying bytecode.
22:56blackdogbootclasspath allows JRuby and its dependencies to skip verification,
22:56blackdogwhich in our case improved startup time almost 3X, putting it
22:56blackdogcomfortably under 0.5s on OS X. That was a *huge* find, akin to a silver
22:56blackdogbullet for startup speed.
22:56blackdogthat's from Charles Nutter to the jvm list
22:57Chouserinteresting!
23:02blackdogactually the thread has a lot of good info http://groups.google.com/group/jvm-languages/browse_thread/thread/6e12cf1dd09ae40e/34feca136e728807?lnk=gst&q=startup+performance#34feca136e728807
23:06ChouserUnrecognized VM option 'bootclasspath'
23:06blackdogjava -X
23:10ChouserHm, I'll have to mess with it tomorrow. G'night folks.
23:11blackdogciao