#clojure logs

2008-06-18

01:36jcriteswhen I get further along in my Clojure development and I would, in another language, keep a file rather than interactive in the REPL, how would I do this?
01:36jcritesdo I execute Java on the clojure jar with a different class?
01:36jcriteshow do I run a clojure "program" normally? (i.e., non-repl)
01:39abrooksjcrites: The Clojure wiki provides script wrappers to call java with your .clj files.
01:40abrooksjcrites: The wiki is here, BTW: http://en.wikibooks.org/wiki/Clojure_Programming
01:40jcriteswikibooks eh?
01:41jcritesthanks for the reference
01:41jcritesnow I can start using Clojure in production at my work ;-)
01:41abrooksNot so much of a book at this point... :)
01:41jcritesis there any way to turn Clojure into a jar?
01:41jcritesit would be really nice to have a jar I can just pass around in the usual places
01:42jcritesperhaps the jar just runs clj files stored inside of it, but it would still be convenient
01:42abrooksI think there was some discussion of that in the Clojure Google Group and possibly here.
01:42jcriteshmmm, maybe I should make it?
01:42abrooksYou can place .clj files into the jar, I know.
01:42abrooksCompiling .clj to class files in the .jar, I
01:43jcritesI just meant to say that I recognize it doesn't necessarily need to be "compiled", just packaged up for execution
01:43abrooksCompiling .clj to class files in the .jar, I'm not so sure.
01:43jcritesyeah :)
01:43abrooksI suspect it's possible.
01:43abrooksI suspect also that I should be in bed -- goodnight!
01:44jcritesgood night
11:40jteohmm?
11:41ChouserOn google group, creating a namespace the same as a class name. Redefining Math/PI to 3.14
13:58abrooksChouser: Hehe.
13:59abrooksChouser: Shouldn't PI be defined as 3 in compliance with the state of Indiana? :)
14:00Lau_of_DKhaha, state of India?
14:01abrooksAh, no this is semi-apocryphal: http://en.wikipedia.org/wiki/Indiana_Pi_Bill
14:01Lau_of_DKwow, thats really messed up
14:01abrooksLau_of_DK: Heh. No, Indiana, USA, in the midwest.
14:12ChouserBut yes, messed up.
14:19Lau_of_DKEvening Chouser
14:24Lau_of_DKGents, Am I wrong in expecting that adding a PropertyChangeListener to either my main panel or JFrame would fire an event when the window is resized?
14:35Lau_of_DKYes I am
15:05ChouserLau_of_DK: hello!
15:08Lau_of_DK:)
15:09Chousersorry, a little slow today.
15:11Lau_of_DKits fine - I dont know your circumstances, but I usually only hit IRC after a looong days work :)
15:11Lau_of_DK(so - I default to slow)
15:58Lau_of_DKWhere is (exp base power) hidden in Clojure?
15:59ChouserProbably not in Clojure at all. try java.lang.Math?
15:59Lau_of_DKseems odd to leave it out imo
16:00ChouserClojure has only a few Math primitives, since the Math class is right there.
16:00Lau_of_DKI'm still at the ewww Java stage though :)
16:01Chouser(Math/pow 2 10) => 1024.0
16:04ChouserAnyone here want to help me write some really high-quality Java code so that when I blow it away with equivalent Clojure it's not just a straw-man argument?
16:04LeafwChouser : what kind of code
16:05LeafwLau_of_DK : try pow
16:05Lau_of_DKYea thanks Leafw and Chouser , I got it
16:05ChouserI'm thinking maybe a function that takes two lists (or arrays or whatever) and produces a new one that is the sum of each pair.
16:05LeafwLau_of_DK : oops, confused ... pow is not there.
16:06LeafwChouser : lists of primitives?
16:06Chouserin clojure, a foo where (foo [1 2 3] [4 5 6]) => [5 7 9]
16:06Chousersure.
16:06Chouserints
16:06Lau_of_DK(. Math pow 2 2) = 4.0
16:06Chouseror Integers, whatever.
16:06Leafwit's not the same :)
16:07ChouserI know, but I'm not looking for perfect equivalence with Clojure, I just want code that won't make a Java programmer laugh
16:07LeafwI wrote some benchmarks
16:07ChouserI don't want them to say, "well sure your Clojure code looks better, but who would right Java like *that*?"
16:07Leafwthat made Rich add all the primitive array support
16:07Chouserhm, yeah, I should look at those.
16:09LeafwI can post them ... http://git.pastebin.com/m8a0c849
16:10Leafwit's a very simple sum.
16:10LeafwI am actually using Clojure for imae processing, doing haar transforms, gaussian filtering, and minor things
16:10Leafwsome examples: http://pacific.mpi-cbg.de/wiki/index.php/Clojure_Scripting
16:11Leafwanother: http://pacific.mpi-cbg.de/wiki/index.php/Scripting_comparisons
16:11Chouseri think I've looked at those pages before. :-)
16:11Leafwthe last one compares code from java., jython, javascript, jruby and clojure (two versions: one mine, naive, one from Rich)
16:11Leafw:)
16:11ChouserI guess I'm looking more to compare expressiveness rather than performance.
16:12Leafwthen do a real-world example
16:12Leafwlike: can you fix my example here: http://pacific.mpi-cbg.de/wiki/index.php/Clojure_Scripting#Fixing_overexposed_images:_setting_a_pixel_value_to_a_desirable_one_for_all_overexposed_pixels
16:12Leafwcan this be done easier?
16:13Leafwthe problem: some pixels have a value of zero, erroneously. They need to be set to a specific value. So "set all pixels with value zero to X"
16:14Leafwideally, with native performance ,and ideally, for all byte, short and float pixel arrays.
16:14Leafwin java this is a loop, but one needs a class declaration and all that noise.
16:14ChouserMaybe I'm not saying this right: I want some Java source code to do the task I described above.
16:15ChouserMaybe I'll just write something and post it for people to critisize and/or fix.
16:15LeafwxD
16:15LeafwI was trying to move you into my own example ... I'll write it for you
16:16Leafwsame length, or unequqla length of the lists ?
16:17Chouserequal length
16:18Chouserare arrays the Right Thing to use in Java, or something else?
16:18Leafwhttp://git.pastebin.com/d75b6d2dd
16:18Chouserok, perfect!
16:18Chouserthanks!
16:18Leafwthat depends on what you want to do (and that is the problem: one needs to rewrite the functin for int, short, long, float, double, byte ... or Object Integer, Float, Byte, etc.)
16:19Chouserok, no, this is fine.
16:19Leafwwell: in clojure, one does not need to rewrite the function, which is great.
16:19Chouserthis demonstrates clumsy iteration, extra variables (i, len), and mutable data.
16:20Chouserand of course the clojure equivalent is (map + list1 list2)
16:22LeafwI knew that :)
16:23Leafwclojure finally lets one live in the JVM without the hassle of java.
16:23Leafwthe clojure equivalent is (let [s (map + list1 list)] ... )
16:24Leafwor list3 == s
16:27rhickey_Chouser: prepping for your talk?
16:28Chouserrhickey_: yessir
16:29ChouserI'm going to try a somewhat different angle than your talk, even though I expect the audience to be pretty much the same.
16:30rhickey_how much time do you have?
16:30ChouserBut I only have 1 hour at most, and your talk is already out there if they want it.
16:31Chouserso I'm going to try less of a ground-up description of Lisp. Just some basics and then straight into comparisons and examples.
16:32drewrChouser: To whom are you speaking?
16:32ChouserI guess there's only going to be about 8 people there, so if I turn them off completely to Clojure it's still not too much damage.
16:33LeafwChouser : "there" being where?
16:33Chousersome kind of lunchtime tech-talk group at my friend's workplace. Outside Chicago.
16:33Leafwok
16:35Chouserrhickey_: I plan to send you my slides so you can critque them (if you want to -- no obligation!)
16:36Chouserthe first few should be very familiar
16:39rhickey_ok
16:40drewrWhy does "\p{Space}+
16:40drewr" give me "Unsupported escape character: \p" ?
16:40drewrWhen used as a java.util.regex.Pattern.
16:41Chouser#"\\p"
16:41rsynnottin general, the rule is to add more slashes until it works, with this sort of thing
16:41Chouseryou have to escape your \ to get it past the string parser and into the regex parser
16:41rsynnott(I've seen up to four for regexes :) )
16:41Chouserwhich is icky (and exactly like Java and elisp)
16:41drewrI guess I've been spoiled by Python's r'' syntax.
16:42rhickey_I'm amenable to thinning out the \s but the regex wizards ran aground somewhere in trying to spec that
16:43ChouserA solution has been discussed.
16:43ChouserSomewhere in here: http://groups.google.com/group/clojure/browse_thread/thread/81b361a4e82602b7/234122dfe281744f
16:45drewrDoes this [Ljava.lang.String;@51c2b4 mean that I got back an array of Strings?
16:45rhickey_drewr: yup
16:48drewrAh, SEQ and VEC work on it.
16:50Chouseraw, amap doesn't take multiple arrays.
16:50Chousersuch a pity!
16:50rhickey_does it need multiples?
16:50rhickey_just needs the driving array
16:50rhickey_expression can refer to others
16:55Chouserno, it certainly doesn't need it.
16:59rhickey_so, it's ok or you still want multiple arrays?
17:09Chouseramap doesn't do an aget on the primary array, right? So no, there's no benefit (that i can think of) for multiple arrays.
17:10Chouseroh. he's gone.
17:11abrooksChouser: When's your Chicago Clojure talk?
17:11ChouserFriday
17:11abrooksHow's it going? Is there anything for me to help with?
17:12ChouserIt's going fine, I think.
17:38drewrWhat's the best way to mimic BOUNDP?
17:38drewrI want to see if a Var already exists.
17:41Chouserthe logs say (.isBound #'rest) but that doesn't work for me
17:42drewrMe neither.
17:44ChouserI got that from: http://clojure-log.n01se.net/date/2008-05-27.html#07:54
17:44Chouser(var 'foo) gives a strange error
17:46Chouserdrewr: this is a namespaced global var?
17:46drewrYes.
17:46drewrIt's a jdbc connection, e.g., *conn*, that I want to memoize.
17:46drewrI only need one of them.
17:47Chouser(contains? (ns-map (find-ns 'user)) 'foo)
17:48shizzy0hello
17:48drewrChouser: Nice, that works.
17:48Chouseroh, drop the contains? ((ns-map (find-ns 'user)) 'foo)
17:48Chousershizzy0: hi!
17:48shizzy0I have a question. How is the :test and (test) function supposed to work?
17:50shizzy0I'm looking at the definition of (test [v]) in boot.clj, and am I right to think, that it's supposed to work like this: (test +) will run a test on the + function if it has a test. Is that how it's supposed to work?
17:51Chouserapparently, yes. I've not used it.
17:53shizzy0[nods] cool. that's interesting, so in the :test you actually put a function.
17:54Chouseryes. I'm currently failing in my attempts to do so, but that's what the docs and code seem to do.
17:55shizzy0I don't see it being exercised anywhere, but as I'm trying to get my head around how to work with clojure, it makes sense to do it in a unit-testy way. I guess, that's just how I do my discovery programming now.
18:00Chouserhuh, it looks like test will only call :test with no parameters
18:00shizzy0Thanks, Chouser. Looks like this works: (defn #^{ :test (fn [] (assert (= 1 (test-test)))) }
18:00shizzy0 test-test []
18:00shizzy0 1)
18:00shizzy0exercising it with: (test #'test-test)
18:01shizzy0no parameters is kind of typical with unit testing.
18:01Chouseroh, ok.
18:01Chouserah, assert is nice.
18:02shizzy0[nods] yeah. It's great that you can get the actual expression that was tested. I love macros.
18:02Chouseryou can also say: (defn test-test {:test #(assert (= 1 (test-test)))} [] 1)
18:03shizzy0oh good. That's a nicer way of expressing it.
18:04shizzy0Is there a way that one could do it so, I could do it like this (deftest my-function ...) that would add it to the meta of an already defined "my-function"?
18:04Chousersure
18:04shizzy0cool. I'm going to try that.
18:05ChouserI need to go, but you'll need to use with-meta
18:05shizzy0[nods] awesome. I'll check it out.
18:05shizzy0Good chatting with you, Chouser.
18:05Chouserand if deftest's first arg is meant to be unquoted like that, deftest will have to be a macro
18:13shizzy0Hello rhickey, I'm playing around with (test v) and :test. Do you have any ideas about it you'd like to me about it? It looks like it's currently a way to attach a parameterless unit test to any given function.
18:15rhickeyshizzy0: I don't have any coherent plan yet, only a preference that tests produce result data rather than print
18:18drewrChouser: I just noticed that FIND-VAR does what I wanted. :-)
18:18shizzy0rhickey: [nods] that's cool. Is that to encourage people to write tests rather than print, read, and interpret results?
18:23shizzy0rhickey: I'm trying to define a deftest macro. Is it possible to define the function and the test separately, e.g. (deftest assoc [] ...)?
18:30cgrandshizzy0: look at the source for defmethod for a way to alter an existing function
18:31rhickeythere's no rule that says the test must go on the var metadata, you could have a test suite in a map keyed by var, for instance
18:32shizzy0cgrand: thanks for the hint. :)
18:34shizzy0rhickey: [nods] I was thinking about just doing a simple general unit test suite. No frills, but something that would work. I really like the meta data, and how I can just grab all the functions I'm interested in (say those tagged with :unit-test) and run them.
20:13Chouserdrewr: ah, cool.
20:14dudleyfreload /style
20:14Chouserswing and a miss
20:28slavarhickey: is there a reference describing persistent vectors somewhere?
20:29slavarhickey: i find the code a bit hard to follow, with the 'Box' thing
20:29slavarhickey: i just noticed my implementation of pop was wrong, but i don't really undersatnd how its supposed to work :)
20:31rhickeyyeah, the box is working around lack of multiple returns
20:32slavathe part that confuses me is that the box is passed around during recursive calls to popTail(), and it gets mutated
20:32slavait would be more clear if there was a new box every time
20:32rhickeyThe persistent arrays are an persistent implementation of Bagwell's hash tries: http://lampwww.epfl.ch/papers/idealhashtrees.pdf
20:33rhickeyyes, but new box each time would be slower
21:08Chouserrhickey: when someone says Clojure doesn't have cons cells, wouldn't argue that's essentially what PersistentList is?
21:17rhickeyChouser: yes
21:18rhickeyeven more so, clojure.lang.Cons
21:18rhickeywhat it doesn't have is cons cells as arbitrary pairs
21:20ChouserHeh, I didn't know about Cons
21:20ChouserIs (clojure.lang.Cons. 1 nil) the only way to make one?
21:22rhickeywhen you cons onto a seq, you get a Cons, except if that seq was a PersistentList already
21:23rhickeysee ASeq.cons
21:29Chouserah, ok
23:25yrbis there way to new up nested classes other than using the name of the actual class file eg. Ellipse2D$Float
23:58dudleyfreload /style