2008-06-18
| 01:36 | jcrites | when 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:36 | jcrites | do I execute Java on the clojure jar with a different class? |
| 01:36 | jcrites | how do I run a clojure "program" normally? (i.e., non-repl) |
| 01:39 | abrooks | jcrites: The Clojure wiki provides script wrappers to call java with your .clj files. |
| 01:40 | abrooks | jcrites: The wiki is here, BTW: http://en.wikibooks.org/wiki/Clojure_Programming |
| 01:40 | jcrites | wikibooks eh? |
| 01:41 | jcrites | thanks for the reference |
| 01:41 | jcrites | now I can start using Clojure in production at my work ;-) |
| 01:41 | abrooks | Not so much of a book at this point... :) |
| 01:41 | jcrites | is there any way to turn Clojure into a jar? |
| 01:41 | jcrites | it would be really nice to have a jar I can just pass around in the usual places |
| 01:42 | jcrites | perhaps the jar just runs clj files stored inside of it, but it would still be convenient |
| 01:42 | abrooks | I think there was some discussion of that in the Clojure Google Group and possibly here. |
| 01:42 | jcrites | hmmm, maybe I should make it? |
| 01:42 | abrooks | You can place .clj files into the jar, I know. |
| 01:42 | abrooks | Compiling .clj to class files in the .jar, I |
| 01:43 | jcrites | I just meant to say that I recognize it doesn't necessarily need to be "compiled", just packaged up for execution |
| 01:43 | abrooks | Compiling .clj to class files in the .jar, I'm not so sure. |
| 01:43 | jcrites | yeah :) |
| 01:43 | abrooks | I suspect it's possible. |
| 01:43 | abrooks | I suspect also that I should be in bed -- goodnight! |
| 01:44 | jcrites | good night |
| 11:40 | jteo | hmm? |
| 11:41 | Chouser | On google group, creating a namespace the same as a class name. Redefining Math/PI to 3.14 |
| 13:58 | abrooks | Chouser: Hehe. |
| 13:59 | abrooks | Chouser: Shouldn't PI be defined as 3 in compliance with the state of Indiana? :) |
| 14:00 | Lau_of_DK | haha, state of India? |
| 14:01 | abrooks | Ah, no this is semi-apocryphal: http://en.wikipedia.org/wiki/Indiana_Pi_Bill |
| 14:01 | Lau_of_DK | wow, thats really messed up |
| 14:01 | abrooks | Lau_of_DK: Heh. No, Indiana, USA, in the midwest. |
| 14:12 | Chouser | But yes, messed up. |
| 14:19 | Lau_of_DK | Evening Chouser |
| 14:24 | Lau_of_DK | Gents, 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:35 | Lau_of_DK | Yes I am |
| 15:05 | Chouser | Lau_of_DK: hello! |
| 15:08 | Lau_of_DK | :) |
| 15:09 | Chouser | sorry, a little slow today. |
| 15:11 | Lau_of_DK | its fine - I dont know your circumstances, but I usually only hit IRC after a looong days work :) |
| 15:11 | Lau_of_DK | (so - I default to slow) |
| 15:58 | Lau_of_DK | Where is (exp base power) hidden in Clojure? |
| 15:59 | Chouser | Probably not in Clojure at all. try java.lang.Math? |
| 15:59 | Lau_of_DK | seems odd to leave it out imo |
| 16:00 | Chouser | Clojure has only a few Math primitives, since the Math class is right there. |
| 16:00 | Lau_of_DK | I'm still at the ewww Java stage though :) |
| 16:01 | Chouser | (Math/pow 2 10) => 1024.0 |
| 16:04 | Chouser | Anyone 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:04 | Leafw | Chouser : what kind of code |
| 16:05 | Leafw | Lau_of_DK : try pow |
| 16:05 | Lau_of_DK | Yea thanks Leafw and Chouser , I got it |
| 16:05 | Chouser | I'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:05 | Leafw | Lau_of_DK : oops, confused ... pow is not there. |
| 16:06 | Leafw | Chouser : lists of primitives? |
| 16:06 | Chouser | in clojure, a foo where (foo [1 2 3] [4 5 6]) => [5 7 9] |
| 16:06 | Chouser | sure. |
| 16:06 | Chouser | ints |
| 16:06 | Lau_of_DK | (. Math pow 2 2) = 4.0 |
| 16:06 | Chouser | or Integers, whatever. |
| 16:06 | Leafw | it's not the same :) |
| 16:07 | Chouser | I know, but I'm not looking for perfect equivalence with Clojure, I just want code that won't make a Java programmer laugh |
| 16:07 | Leafw | I wrote some benchmarks |
| 16:07 | Chouser | I don't want them to say, "well sure your Clojure code looks better, but who would right Java like *that*?" |
| 16:07 | Leafw | that made Rich add all the primitive array support |
| 16:07 | Chouser | hm, yeah, I should look at those. |
| 16:09 | Leafw | I can post them ... http://git.pastebin.com/m8a0c849 |
| 16:10 | Leafw | it's a very simple sum. |
| 16:10 | Leafw | I am actually using Clojure for imae processing, doing haar transforms, gaussian filtering, and minor things |
| 16:10 | Leafw | some examples: http://pacific.mpi-cbg.de/wiki/index.php/Clojure_Scripting |
| 16:11 | Leafw | another: http://pacific.mpi-cbg.de/wiki/index.php/Scripting_comparisons |
| 16:11 | Chouser | i think I've looked at those pages before. :-) |
| 16:11 | Leafw | the last one compares code from java., jython, javascript, jruby and clojure (two versions: one mine, naive, one from Rich) |
| 16:11 | Leafw | :) |
| 16:11 | Chouser | I guess I'm looking more to compare expressiveness rather than performance. |
| 16:12 | Leafw | then do a real-world example |
| 16:12 | Leafw | like: 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:12 | Leafw | can this be done easier? |
| 16:13 | Leafw | the 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:14 | Leafw | ideally, with native performance ,and ideally, for all byte, short and float pixel arrays. |
| 16:14 | Leafw | in java this is a loop, but one needs a class declaration and all that noise. |
| 16:14 | Chouser | Maybe I'm not saying this right: I want some Java source code to do the task I described above. |
| 16:15 | Chouser | Maybe I'll just write something and post it for people to critisize and/or fix. |
| 16:15 | Leafw | xD |
| 16:15 | Leafw | I was trying to move you into my own example ... I'll write it for you |
| 16:16 | Leafw | same length, or unequqla length of the lists ? |
| 16:17 | Chouser | equal length |
| 16:18 | Chouser | are arrays the Right Thing to use in Java, or something else? |
| 16:18 | Leafw | http://git.pastebin.com/d75b6d2dd |
| 16:18 | Chouser | ok, perfect! |
| 16:18 | Chouser | thanks! |
| 16:18 | Leafw | that 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:19 | Chouser | ok, no, this is fine. |
| 16:19 | Leafw | well: in clojure, one does not need to rewrite the function, which is great. |
| 16:19 | Chouser | this demonstrates clumsy iteration, extra variables (i, len), and mutable data. |
| 16:20 | Chouser | and of course the clojure equivalent is (map + list1 list2) |
| 16:22 | Leafw | I knew that :) |
| 16:23 | Leafw | clojure finally lets one live in the JVM without the hassle of java. |
| 16:23 | Leafw | the clojure equivalent is (let [s (map + list1 list)] ... ) |
| 16:24 | Leafw | or list3 == s |
| 16:27 | rhickey_ | Chouser: prepping for your talk? |
| 16:28 | Chouser | rhickey_: yessir |
| 16:29 | Chouser | I'm going to try a somewhat different angle than your talk, even though I expect the audience to be pretty much the same. |
| 16:30 | rhickey_ | how much time do you have? |
| 16:30 | Chouser | But I only have 1 hour at most, and your talk is already out there if they want it. |
| 16:31 | Chouser | so I'm going to try less of a ground-up description of Lisp. Just some basics and then straight into comparisons and examples. |
| 16:32 | drewr | Chouser: To whom are you speaking? |
| 16:32 | Chouser | I 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:33 | Leafw | Chouser : "there" being where? |
| 16:33 | Chouser | some kind of lunchtime tech-talk group at my friend's workplace. Outside Chicago. |
| 16:33 | Leafw | ok |
| 16:35 | Chouser | rhickey_: I plan to send you my slides so you can critque them (if you want to -- no obligation!) |
| 16:36 | Chouser | the first few should be very familiar |
| 16:39 | rhickey_ | ok |
| 16:40 | drewr | Why does "\p{Space}+ |
| 16:40 | drewr | " give me "Unsupported escape character: \p" ? |
| 16:40 | drewr | When used as a java.util.regex.Pattern. |
| 16:41 | Chouser | #"\\p" |
| 16:41 | rsynnott | in general, the rule is to add more slashes until it works, with this sort of thing |
| 16:41 | Chouser | you have to escape your \ to get it past the string parser and into the regex parser |
| 16:41 | rsynnott | (I've seen up to four for regexes :) ) |
| 16:41 | Chouser | which is icky (and exactly like Java and elisp) |
| 16:41 | drewr | I guess I've been spoiled by Python's r'' syntax. |
| 16:42 | rhickey_ | I'm amenable to thinning out the \s but the regex wizards ran aground somewhere in trying to spec that |
| 16:43 | Chouser | A solution has been discussed. |
| 16:43 | Chouser | Somewhere in here: http://groups.google.com/group/clojure/browse_thread/thread/81b361a4e82602b7/234122dfe281744f |
| 16:45 | drewr | Does this [Ljava.lang.String;@51c2b4 mean that I got back an array of Strings? |
| 16:45 | rhickey_ | drewr: yup |
| 16:48 | drewr | Ah, SEQ and VEC work on it. |
| 16:50 | Chouser | aw, amap doesn't take multiple arrays. |
| 16:50 | Chouser | such a pity! |
| 16:50 | rhickey_ | does it need multiples? |
| 16:50 | rhickey_ | just needs the driving array |
| 16:50 | rhickey_ | expression can refer to others |
| 16:55 | Chouser | no, it certainly doesn't need it. |
| 16:59 | rhickey_ | so, it's ok or you still want multiple arrays? |
| 17:09 | Chouser | amap 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:10 | Chouser | oh. he's gone. |
| 17:11 | abrooks | Chouser: When's your Chicago Clojure talk? |
| 17:11 | Chouser | Friday |
| 17:11 | abrooks | How's it going? Is there anything for me to help with? |
| 17:12 | Chouser | It's going fine, I think. |
| 17:38 | drewr | What's the best way to mimic BOUNDP? |
| 17:38 | drewr | I want to see if a Var already exists. |
| 17:41 | Chouser | the logs say (.isBound #'rest) but that doesn't work for me |
| 17:42 | drewr | Me neither. |
| 17:44 | Chouser | I got that from: http://clojure-log.n01se.net/date/2008-05-27.html#07:54 |
| 17:44 | Chouser | (var 'foo) gives a strange error |
| 17:46 | Chouser | drewr: this is a namespaced global var? |
| 17:46 | drewr | Yes. |
| 17:46 | drewr | It's a jdbc connection, e.g., *conn*, that I want to memoize. |
| 17:46 | drewr | I only need one of them. |
| 17:47 | Chouser | (contains? (ns-map (find-ns 'user)) 'foo) |
| 17:48 | shizzy0 | hello |
| 17:48 | drewr | Chouser: Nice, that works. |
| 17:48 | Chouser | oh, drop the contains? ((ns-map (find-ns 'user)) 'foo) |
| 17:48 | Chouser | shizzy0: hi! |
| 17:48 | shizzy0 | I have a question. How is the :test and (test) function supposed to work? |
| 17:50 | shizzy0 | I'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:51 | Chouser | apparently, yes. I've not used it. |
| 17:53 | shizzy0 | [nods] cool. that's interesting, so in the :test you actually put a function. |
| 17:54 | Chouser | yes. I'm currently failing in my attempts to do so, but that's what the docs and code seem to do. |
| 17:55 | shizzy0 | I 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:00 | Chouser | huh, it looks like test will only call :test with no parameters |
| 18:00 | shizzy0 | Thanks, Chouser. Looks like this works: (defn #^{ :test (fn [] (assert (= 1 (test-test)))) } |
| 18:00 | shizzy0 | test-test [] |
| 18:00 | shizzy0 | 1) |
| 18:00 | shizzy0 | exercising it with: (test #'test-test) |
| 18:01 | shizzy0 | no parameters is kind of typical with unit testing. |
| 18:01 | Chouser | oh, ok. |
| 18:01 | Chouser | ah, assert is nice. |
| 18:02 | shizzy0 | [nods] yeah. It's great that you can get the actual expression that was tested. I love macros. |
| 18:02 | Chouser | you can also say: (defn test-test {:test #(assert (= 1 (test-test)))} [] 1) |
| 18:03 | shizzy0 | oh good. That's a nicer way of expressing it. |
| 18:04 | shizzy0 | Is 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:04 | Chouser | sure |
| 18:04 | shizzy0 | cool. I'm going to try that. |
| 18:05 | Chouser | I need to go, but you'll need to use with-meta |
| 18:05 | shizzy0 | [nods] awesome. I'll check it out. |
| 18:05 | shizzy0 | Good chatting with you, Chouser. |
| 18:05 | Chouser | and if deftest's first arg is meant to be unquoted like that, deftest will have to be a macro |
| 18:13 | shizzy0 | Hello 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:15 | rhickey | shizzy0: I don't have any coherent plan yet, only a preference that tests produce result data rather than print |
| 18:18 | drewr | Chouser: I just noticed that FIND-VAR does what I wanted. :-) |
| 18:18 | shizzy0 | rhickey: [nods] that's cool. Is that to encourage people to write tests rather than print, read, and interpret results? |
| 18:23 | shizzy0 | rhickey: I'm trying to define a deftest macro. Is it possible to define the function and the test separately, e.g. (deftest assoc [] ...)? |
| 18:30 | cgrand | shizzy0: look at the source for defmethod for a way to alter an existing function |
| 18:31 | rhickey | there'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:32 | shizzy0 | cgrand: thanks for the hint. :) |
| 18:34 | shizzy0 | rhickey: [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:13 | Chouser | drewr: ah, cool. |
| 20:14 | dudleyf | reload /style |
| 20:14 | Chouser | swing and a miss |
| 20:28 | slava | rhickey: is there a reference describing persistent vectors somewhere? |
| 20:29 | slava | rhickey: i find the code a bit hard to follow, with the 'Box' thing |
| 20:29 | slava | rhickey: i just noticed my implementation of pop was wrong, but i don't really undersatnd how its supposed to work :) |
| 20:31 | rhickey | yeah, the box is working around lack of multiple returns |
| 20:32 | slava | the part that confuses me is that the box is passed around during recursive calls to popTail(), and it gets mutated |
| 20:32 | slava | it would be more clear if there was a new box every time |
| 20:32 | rhickey | The persistent arrays are an persistent implementation of Bagwell's hash tries: http://lampwww.epfl.ch/papers/idealhashtrees.pdf |
| 20:33 | rhickey | yes, but new box each time would be slower |
| 21:08 | Chouser | rhickey: when someone says Clojure doesn't have cons cells, wouldn't argue that's essentially what PersistentList is? |
| 21:17 | rhickey | Chouser: yes |
| 21:18 | rhickey | even more so, clojure.lang.Cons |
| 21:18 | rhickey | what it doesn't have is cons cells as arbitrary pairs |
| 21:20 | Chouser | Heh, I didn't know about Cons |
| 21:20 | Chouser | Is (clojure.lang.Cons. 1 nil) the only way to make one? |
| 21:22 | rhickey | when you cons onto a seq, you get a Cons, except if that seq was a PersistentList already |
| 21:23 | rhickey | see ASeq.cons |
| 21:29 | Chouser | ah, ok |
| 23:25 | yrb | is there way to new up nested classes other than using the name of the actual class file eg. Ellipse2D$Float |
| 23:58 | dudleyf | reload /style |