2008-12-28
| 00:07 | kabny | i see |
| 00:12 | kabny | what doe sit mean to write (. hmm some) as opposed to (.some hmm)? |
| 00:16 | dreish | The latter turns into the former at macro expansion time. They're equivalent. |
| 00:36 | kabny | what would be best suitable for a GUI, agents or refs? |
| 00:52 | kabny | what would be best suitable for a GUI, agents or refs? |
| 01:00 | kabny | anyone using contrib.sql? |
| 01:02 | kabny | how do you refer to a database since with-connection returns nil? |
| 01:22 | chrisdone | clojurebot: help |
| 01:22 | clojurebot | macro help is http://clojure-log.n01se.net/macro.html |
| 01:22 | chrisdone | clojurebot: source |
| 01:22 | clojurebot | Titim gan �ir� ort. |
| 01:22 | chrisdone | mmkay |
| 01:22 | chrisdone | clojurebot: commands |
| 01:22 | clojurebot | It's greek to me. |
| 01:29 | chrisdone | clojurebot: eval (+ 1 1) |
| 01:29 | clojurebot | Gabh mo leithsc�al? |
| 01:37 | eric-at-home | ,(+ 1 1) |
| 01:37 | clojurebot | 2 |
| 01:37 | eric-at-home | kabny: I am using contrib.sql. |
| 01:38 | eric-at-home | oh, kabny already left :-( |
| 09:50 | Lau_of_DK | Zzzzz |
| 09:51 | Raynes | zzzzZ |
| 11:34 | vseguip | hi all |
| 11:35 | danlarkin | vseguip: howdy |
| 11:35 | vseguip | I'm new to clojure |
| 11:35 | vseguip | I've been plating with it for some univerity assignment |
| 11:36 | vseguip | I've been trying to optimize my algorithims with some hints as per http://clojure.org/java_interop |
| 11:36 | vseguip | however I'm getting very different timings |
| 11:36 | vseguip | from those in the page |
| 11:37 | vseguip | for intance |
| 11:37 | vseguip | de foo2 function |
| 11:38 | mibu | how much different is it? |
| 11:38 | vseguip | an order of magnitude |
| 11:38 | vseguip | (time (foo2 100000)) |
| 11:38 | vseguip | "Elapsed time: 0.908077 msecs" |
| 11:38 | vseguip | 100000 |
| 11:38 | danlarkin | well you've got a different computer from the one on which this computer was compiled |
| 11:39 | vseguip | I have a string ina Java array |
| 11:39 | mibu | that's well under a msec. doesn't mean anything. |
| 11:39 | vseguip | yep |
| 11:39 | vseguip | but for instance |
| 11:39 | vseguip | I would have thought that this would be faster |
| 11:40 | vseguip | (time (clojure.core/amap *dicc* i ret (aget ret i))) |
| 11:40 | mibu | different computer, different java version, background programs all can affect the speed. |
| 11:40 | vseguip | "Elapsed time: 18.029456 msecs" |
| 11:41 | vseguip | (count *dicc*) |
| 11:41 | vseguip | 13189 |
| 11:41 | vseguip | I realize that |
| 11:41 | vseguip | but 20 ms to traverse a Java array seems weird |
| 11:42 | vseguip | with only 13189 positions |
| 11:42 | vseguip | would that be normal? |
| 11:43 | mibu | vseguip: it could |
| 11:44 | vseguip | (fairly new machine Intel(R) Core(TM)2 Duo CPU T7250 @ 2.00GHz with 4gb ram, java 6, ubuntu) |
| 11:44 | vseguip | (clojure-svn rev 1162) |
| 11:49 | danlarkin | vseguip: whip up a reproducible test and I'll tell you how fast it is on my machine |
| 11:50 | vseguip | (def *arry* (into-array (range 10000))) |
| 11:50 | vseguip | (time (clojure.core/amap *arry* i ret (aget ret i))) |
| 11:51 | vseguip | I'm doing it in 2 steps |
| 11:51 | vseguip | so as to only time |
| 11:51 | vseguip | amap |
| 11:51 | vseguip | not the array conversion |
| 11:51 | danlarkin | 10ms for me |
| 11:52 | vogelrn | 3ms here |
| 11:52 | vseguip | 13ms |
| 11:52 | vseguip | for me |
| 11:53 | vseguip | vogelrn: what is your setup? |
| 11:54 | vogelrn | uhhh core 2 duo E6600, 2gb ram, java 6, ubuntu |
| 11:57 | vseguip | simiilar to mine |
| 11:57 | vseguip | wht clojure version? |
| 12:01 | vogelrn | whoops, I forgot, I haven't updated in a while, been on my laptop recently, let me update and see if it gets slower (I'm on 1147) |
| 12:04 | vogelrn | nope, still the same speed |
| 12:04 | vogelrn | well, updating to latest that is |
| 12:07 | arbscht_ | 3.5ms - core2 duo E6750, 2G, openjdk 1.6.0, debian, clojure rv 1185 |
| 12:10 | vseguip | mm |
| 12:10 | vseguip | I'm using sun6-java |
| 12:10 | vogelrn | so am I |
| 12:11 | Raynes | Downloading the JDK on dialup is no fun :| |
| 12:11 | danlarkin | Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284) |
| 12:11 | Lau_of_DK | Just wanted to make sure that everyones aware that clojure-mode has been forked and it now being worked upon from http://github.com/technomancy/clojure-mode/tree/master |
| 12:12 | arbscht_ | Lau_of_DK: fantastic |
| 12:12 | vseguip | vogelrn: using server jvm? |
| 12:12 | vogelrn | the default is client, no? I haven't added the flag myself |
| 12:13 | vseguip | yep |
| 12:13 | vseguip | defualt is clinet |
| 12:13 | vseguip | using it from emacs/command line/repl? |
| 12:13 | vogelrn | emacs |
| 12:14 | vseguip | me too |
| 12:15 | vseguip | clojure trunk I guess? |
| 12:16 | mibu | anyone knows if there is a splice or flatten function in the contrib? |
| 12:16 | vseguip | flatten |
| 12:16 | vseguip | is there |
| 12:17 | mibu | where? |
| 12:17 | vseguip | in clojure.contrib.seq-utils |
| 12:17 | mibu | thanks |
| 12:18 | vogelrn | I mean, you might try updating to the latest revision, it's slightly possible that it got worse in 1162 and then better again afterwards, if unlikely :P |
| 12:19 | vseguip | according to svn up |
| 12:19 | vseguip | latest revision in 1162 |
| 12:20 | vseguip | :-| |
| 12:20 | vogelrn | it got changed |
| 12:20 | vogelrn | http://clojure.googlecode.com/svn/trunk clojure |
| 12:21 | vseguip | :-o |
| 12:22 | vseguip | OTOH is there a way to "realize" a lazy seq recurisively other then printing it? |
| 12:23 | mibu | vseguip: dorun or doall |
| 12:24 | vseguip | it doesn't seem to do it recursively |
| 12:24 | mibu | vseguip: what do you mean recursively? |
| 12:25 | vseguip | let's suppose you have a lazy seqs of lazy seqs |
| 12:25 | vseguip | I would like it to realize the top level lazy seq |
| 12:25 | vseguip | and then the inner lazy seqs |
| 12:25 | vseguip | etc |
| 12:26 | vseguip | I think I will do a simple func to do this |
| 12:26 | mibu | again, you can use doall or dorun. just map them (map doall some-seq) |
| 12:27 | vseguip | mibu: yup but it would be nice to have a recurive function to do this |
| 12:27 | vseguip | will try and ree |
| 12:27 | vseguip | and reachback |
| 12:36 | vseguip | (defn realize [xs] |
| 12:36 | vseguip | (if (seq? xs) |
| 12:36 | vseguip | (doall (map realize xs)) |
| 12:36 | vseguip | xs)) |
| 12:36 | vseguip | seems to work |
| 12:40 | mibu | vseguip: do you happen to know if there is also splice somewhere? |
| 12:44 | vseguip | what does splice do? |
| 12:45 | vseguip | are you operating on strings, seqs, vecs ? |
| 12:46 | kotarak | For vecs there is subvec. |
| 12:46 | kotarak | For seq: (take n (drop m s)) |
| 12:50 | vseguip | same speed |
| 12:51 | vseguip | :( |
| 12:54 | chrisn | what is the most efficient way to go from a sequence to a typed array? |
| 12:56 | vseguip | chrisn: not sure but (into-array) |
| 12:56 | vseguip | seems the way |
| 12:56 | chrisn | thanks, I will check that out. |
| 12:56 | chrisn | Looking into the api more, I need it to go into java.nio Buffer of some sort |
| 12:58 | chrisn | Is there a typeof operator? |
| 12:59 | kotarak | chrisn: (class ...) |
| 12:59 | kotarak | Or better: (instance? TheClass the-thing) |
| 13:00 | chrisn | awesome |
| 13:00 | danlarkin | also isa? |
| 13:01 | kotarak | danlarkin: I think isa? is more for the hierarchy stuff. |
| 13:01 | danlarkin | (doc isa?) |
| 13:01 | clojurebot | Returns true if (= child parent), or child is directly or indirectly derived from parent, either via a Java type inheritance relationship or a relationship established via derive. h must be a hierarchy obtained from make-hierarchy, if not supplied defaults to the global hierarchy; arglists ([child parent] [h child parent]) |
| 13:02 | kotarak | (isa? TheClass (class the-thing)). instance? is shorter. |
| 13:02 | danlarkin | instance? checks only direct inheritance, isa? does full inheritance trees |
| 13:03 | kotarak | ? What is a full inheritance tree? |
| 13:05 | danlarkin | say C inherits from B which inherits from A |
| 13:05 | danlarkin | and a is an instance of A |
| 13:06 | danlarkin | (instance? C c) is true, (isa? c C) is true, (instance? A c) is false, (isa? c A) is true |
| 13:06 | danlarkin | right? |
| 13:07 | kotarak | Obviously not: |
| 13:07 | kotarak | 1:1 user=> (isa? "string" String) |
| 13:07 | kotarak | false |
| 13:07 | kotarak | 1:2 user=> (isa? (class "string") String) |
| 13:07 | kotarak | true |
| 13:07 | kotarak | 1:3 user=> (instance? Object "string") |
| 13:07 | kotarak | true |
| 13:07 | kotarak | 1:4 user=> (instance? String "string") |
| 13:07 | kotarak | true |
| 13:08 | danlarkin | Hm, guess I was mistaken... not the first time! |
| 13:10 | mibu | I have this unexplained error when I use a macro. Everything works just fine as long as I don't you the macro in a function. |
| 13:11 | mibu | ; permutations without repetitions (r choices from n) |
| 13:11 | mibu | (defmacro permutations [n r] |
| 13:11 | mibu | (let [locals (take r (repeatedly gensym)) |
| 13:11 | mibu | for-range (apply concat (for [i (range r)] [(nth locals i) `(range ~n)]))] |
| 13:11 | mibu | `(for [~@for-range :when (= ~r (count (distinct [~@locals])))] [~@locals]))) |
| 13:11 | mibu | ; permutate a vector without repetitions (r choices from vector v) |
| 13:11 | mibu | (defn permutate [v r] |
| 13:11 | mibu | (let [perms (permutations (count v) r) |
| 13:11 | mibu | map-perm (fn [perm] (map #(nth v %) perm))] |
| 13:11 | mibu | (map map-perm perms))) |
| 13:11 | mibu | (lisppaste don't work) |
| 13:12 | mibu | (permutate [10 20 30 40 50] 3)) spits java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to java.lang.Number (NO_SOURCE_FILE:229) |
| 13:13 | mibu | anyone has any idea what's going on? |
| 13:13 | arbscht_ | mibu: use paste.lisp.org please |
| 13:13 | mibu | arbscht_: it doesn't work. |
| 13:14 | mibu | arbscht_: some kind of netsplit. lisppaste8 isn't in the channel (at least over here) |
| 13:14 | arbscht_ | you can paste it and broadcast the url manually :) |
| 13:15 | mibu | arbscht_: how do I get the url? |
| 13:16 | chrisn | how do I use a static function as a first class function? |
| 13:16 | arbscht_ | mibu: when you make a paste, it will create a page at some url, which you will be redirected to |
| 13:17 | mibu | chrisn: #(.lowercase %) |
| 13:17 | chrisn | static, not member |
| 13:18 | chrisn | But that would work. I was trying to avoid wrapping in another function |
| 13:18 | chrisn | seems pointless |
| 13:18 | Chousuke | you have to wrap java methods. |
| 13:18 | chrisn | even static functions? |
| 13:18 | Chousuke | since they're not first class functions. |
| 13:18 | Chousuke | even them. |
| 13:18 | mibu | arbscht_: nope, it sent me to a blank with the same url of the submit |
| 13:19 | arbscht_ | mibu: fine, use some other paste service then. it makes code much easier to read and copy :) |
| 13:21 | mibu | http://pastebin.com/md89a240 |
| 13:22 | mibu | anyone with a suggestion? I'm busting my head with this for hours now. |
| 13:23 | Chousuke | gah I hate that pastebin |
| 13:23 | Chousuke | the colour scheme is horrible |
| 13:23 | Raynes | www.codepad.org |
| 13:24 | Raynes | Has a Scheme setting. |
| 13:24 | mibu | http://codepad.org/jbDEzu1x |
| 13:24 | Chousuke | why is your permutations a macro? |
| 13:25 | mibu | chousuke: how would you have written it? |
| 13:25 | Chousuke | as a function? |
| 13:25 | Chousuke | is there a reason that it is a macro? |
| 13:25 | mibu | chousuke: yeah, how? I'm using a variable number of locals in the for range. |
| 13:26 | mibu | (for [x1 (range 6) x2 (range 6) x3 (range 6)] ...) for [6 3] ; (for [x1 (range 6) x2 (range 6)] ..) for [6 2] |
| 13:27 | Chousuke | hmm. |
| 13:27 | mibu | btw: if you guys know of a better permutations implementation, I'm all ears. |
| 13:29 | mibu | outside of a function, it just works. I don't understand why when I call it, it spits this error. I tried tracing it to the Java code, but to no avail. |
| 13:33 | chrisn | (permutations (count [1 2 3]) 4) |
| 13:33 | chrisn | nil |
| 13:33 | chrisn | (I think you are double evaluating something |
| 13:34 | mibu | if I don't call it from inside the function, it works. If I fix r, it works. If I expand it by hand and eval it, it works. |
| 13:34 | mibu | chrisn: (permutations [1 2 3 4] 3). what you called is not a vector and has too small of an r. |
| 13:35 | mibu | chrisn: I meant an r that is too large - r should be <= (count v) |
| 13:36 | chrisn | yeah, I just tried with a valid r and it was fine |
| 13:36 | chrisn | Trying to check out the macroexpand code |
| 13:36 | mibu | chrisn: you managed to run it without an error from a function? |
| 13:36 | chrisn | hell no |
| 13:36 | chrisn | just typing it into my repl |
| 13:36 | mibu | oh :-( |
| 13:38 | chrisn | user> (def v [1 2 3]) |
| 13:38 | chrisn | #'user/v |
| 13:38 | chrisn | user> (def r 2) |
| 13:38 | chrisn | #'user/r |
| 13:38 | chrisn | user> (permutations (count v) r) |
| 13:38 | chrisn | That doesn't work |
| 13:38 | chrisn | So you can break it just by using symbols in any sense, not just in a function |
| 13:39 | chrisn | breaks macroexpand, too |
| 13:39 | chrisn | weird |
| 13:39 | Chousuke | mibu: I think the problem is with your n |
| 13:39 | mibu | I figured it has something to do with r. Use a fix r, and it works. |
| 13:39 | Chousuke | instead of the evaled value of (count v), an actual "(count v)" is passed |
| 13:40 | kotarak | macros cannot depend on runtime information. |
| 13:40 | kotarak | (count v) is runtime info |
| 13:40 | kotarak | Chousuke is right. The macro sees the form (count v) and not the value. |
| 13:40 | mibu | chousuke: doesn't ~n eval it? |
| 13:41 | Chousuke | no, ~n expands to (count v) |
| 13:41 | chrisn | The error is in r |
| 13:42 | mibu | ha... |
| 13:42 | chrisn | nope |
| 13:42 | chrisn | wrong |
| 13:42 | mibu | that's one hell of a gotcha. |
| 13:42 | chrisn | hmm... |
| 13:42 | chrisn | whoa |
| 13:43 | mibu | kotarak: you said it's runtime info, how so? |
| 13:43 | mibu | chousuke: wouldn't a (count v) still eval correctly in the context of the father function? |
| 13:43 | kotarak | mibu: ok, the argument applies, but to the other parameter. |
| 13:44 | chrisn | only if the arguments were known at compile time. |
| 13:44 | chrisn | In your function, they are symbols, not compile time constants |
| 13:44 | Chousuke | hm, no wait |
| 13:44 | kotarak | mibu: you get r as a function parameter, but use it in your macro. |
| 13:44 | kotarak | but the macro sees r and not the parameter value |
| 13:44 | chrisn | right. The compiler would have to generate infinitely many functions for this to work. |
| 13:44 | mibu | kotarak: wait wait, I'm not following. r is not bound to what permutate sets it to be? |
| 13:45 | kotarak | Yup. |
| 13:45 | kotarak | The compiler doesn't know that at compile time. |
| 13:45 | mibu | kotarak: I fail to see how it's a problem |
| 13:46 | kotarak | (let [r 5] (permutations (count v) r)) The macro sees the symbol r, not the value 5. |
| 13:46 | mibu | oh, I get it. It's not the evaluated r. How do I bypass this? |
| 13:47 | kotarak | You can't, I presume. |
| 13:47 | chrisn | Either your arguments are known at compile time *or* you write a function as Chousuke suggested. |
| 13:47 | mibu | kotarak: is there something more elegant than (eval r)? |
| 13:47 | mibu | chrisn: it wouldn't be easy to write a function like that. |
| 13:47 | Chousuke | mibu: add (println r) to the top of your macro to see the problem |
| 13:48 | Chousuke | mibu: when called directly, you get "3" printed, but when you call from a function, it prints "r" |
| 13:48 | chrisn | I didn't say anything about easy or hard. You don't have other options, mibu. |
| 13:48 | kotarak | mibu: (eval r) also doesn't work. |
| 13:48 | mibu | chousuke: I got the problem now. Now, I'm trying to understand what is the proper way to fix it, and how to properly write macros in the future. |
| 13:49 | kotarak | mibu: macros may only depend on information known at compile time. A function parameter is not known at compile time. |
| 13:49 | kotarak | mibu: you have to find a different algorithm, which doesn't use for. |
| 13:50 | chrisn | mibu, you are missing the point. Macros are compile time code. They can't work if they can only be expanded at run time. Your macro is fine. Its the use case. |
| 13:50 | mibu | kotarak: you're right. |
| 13:50 | mibu | kotarak: but it was such a nice idea. ;-) |
| 13:50 | kotarak | mibu: there are a lot of nice ideas. ;) Have lots of those myself. ;) |
| 13:51 | mibu | well, this mistake was well worth the lesson it taught me about macros. |
| 13:56 | mibu | anyway, thanks for your help guys. |
| 13:59 | kabny | I think people overuse macros in lisp |
| 14:00 | danlarkin | kabny: I agree |
| 14:00 | kabny | so often I see examples of macros where a function would d an be much cleaner and simpler |
| 14:00 | kotarak | If you don't need to control evaluation, you don't need a macro. |
| 14:00 | Chousuke | I wonder what's wrong with my aquamacs |
| 14:01 | Chousuke | it always opens two windows at startup |
| 14:01 | Chousuke | it's annoying |
| 14:01 | danlarkin | Chousuke: *scratch*? |
| 14:02 | Chousuke | yes. twice. |
| 14:02 | danlarkin | gotta delete that sheeeaaaat |
| 14:02 | danlarkin | haven't figured out how to make it not open aside from deleting it |
| 14:02 | Chousuke | whoops |
| 14:03 | Chousuke | wiped my config |
| 14:03 | Chousuke | good thing it's backed up in git :P |
| 14:04 | Chousuke | danlarkin: and I don't mind it opening *scratch* but why does it open it twice? |
| 14:04 | Chousuke | and in different windows. |
| 14:04 | Chousuke | if I wipe my config it works normally :/ |
| 14:04 | danlarkin | well I've figured it out then, a problem with your config! |
| 14:05 | Chousuke | yes, but WHAT. |
| 14:06 | mibu | emacs is a conspiracy to keep programmers occupied with their config files. ;-) |
| 14:08 | ivan | indeed |
| 14:09 | ivan | anyone have basic clojure syntax highlighting for IDEA 8? |
| 14:10 | mibu | ivan, if you want something really basic you can use highlighting of other lisp formats. |
| 14:11 | danlarkin | ivan: there's an IDEA plugin... somewhere |
| 14:11 | ivan | the generic syntax highlighter that doesn't really work? |
| 14:12 | danlarkin | can't say, I haven't tried it |
| 14:12 | kabny | when doing GUIs what is most appropriate, agents or refs? |
| 14:14 | mibu | kabny: it really depends, but if you must have a general answer then agents. GUI is mostly asynchronous. |
| 14:17 | Chousuke | ah, hm |
| 14:18 | chrisn | mibu: http://pastebin.com/m10ecab20 |
| 14:19 | mibu | chrisn: thanks! |
| 14:20 | chrisn | I forgot contains_dups |
| 14:20 | chrisn | But it is stupid |
| 14:20 | chrisn | (defn contains_dups [seq] |
| 14:20 | chrisn | (< (count (distinct seq)) (count seq))) |
| 14:23 | chrisn | It would be way more efficient to catch duplicates in the for statement |
| 14:24 | chrisn | And my order is different than yours |
| 14:24 | chrisn | But the result is the same |
| 14:24 | chrisn | Also, if I knew recur that would be a better solution |
| 14:24 | Chousuke | for some reason, (setq 'viper-mode t) is causing it |
| 14:25 | mibu | chousuke: the double *scratch*? |
| 14:25 | Chousuke | yeah |
| 14:26 | mibu | chrisn: what I like about my version is that with a simple for that *declares* what needs to be the result, you finish the task. |
| 14:26 | chrisn | your version is definitely ideal. |
| 14:27 | chrisn | but in reality for expands into a bunch of recur statements, so I am damn close to the implementation |
| 14:27 | mibu | I started solving problems in projecteuler yesterday with clojure and discovered how powerful for is. it's almost like cheating. |
| 14:27 | chrisn | I had a buddy working through that in factor |
| 14:27 | kotarak | mibu: there is also clojure-euler.wikispaces.com |
| 14:27 | chrisn | Have you taken a look at the haskell solutions? |
| 14:28 | mibu | kotarak: it's really bad you told me about this. now I might look there ;-) |
| 14:28 | kotarak | mibu: share your solutions. :) |
| 14:29 | kotarak | mibu: but be warned! SPOILER! |
| 14:29 | mibu | kotarak: I will |
| 14:31 | vogelrn | heh, what do you think, is using primes from clojure.contrib.lazy-seqs cheating? :P |
| 14:31 | mibu | vogelrn: there is primes in contrib? |
| 14:31 | vogelrn | yeah, and fib |
| 14:32 | vogelrn | considering one of the problems is |
| 14:32 | vogelrn | get the 10001st prime or something |
| 14:32 | mibu | crap, I did not know that. |
| 14:32 | mibu | I consider whatever comes with the standard language is fair game. contrib is pretty much standard, isn't it? |
| 14:32 | mibu | but writing primes or fib is not hard and even fun. |
| 14:33 | vogelrn | yeah I mean I was half-joking, both prime and fib are pretty easy to write |
| 14:33 | vogelrn | it's just that the whole point of certain problems is to write fib and primes, heh |
| 14:33 | danlarkin | there's a nice example of fib using a memoize function and atoms |
| 14:34 | danlarkin | here it is, http://clojure.org/atoms |
| 14:35 | mibu | memoize is part of the core now, right? |
| 14:40 | vogelrn | looks like it |
| 14:43 | kabny | I'm doing a GUI app that will play mp3s and sometimes at the same time update a database or take input in a textfield from the user. should I use agents then? since it is asynchronous. |
| 14:44 | kabny | why is fib and prime in seq-utils or lazy-seqs and not in math? |
| 14:45 | kabny | isnt there some java lib like numerical java that has fib and prime anyway? |
| 14:45 | vogelrn | possibly, but not lazily |
| 14:47 | vogelrn | and I don't think there's one built into java, it might be 3rd party (could be wrong though) |
| 15:16 | eldok | the more clojure I code the more I like it. |
| 15:16 | kotarak | :) |
| 15:17 | chrisn | mibu: did you check out lazy-seq permutations? |
| 15:17 | chrisn | It isn't exactly what you want, but I would start from there. |
| 15:18 | chrisn | much better than what I wrote. |
| 15:29 | kabny | is an undergraduate 4 years, then waht is graduate? how long have you actually been to uni when you have a PhD? 10years!!!!!!!!!!!!??????????? |
| 15:30 | Hun | depends. |
| 15:33 | kabny | anyone use contrib/sql? how do I create a db? (sql/with-connection db) ? |
| 15:33 | kabny | after havin done: |
| 15:33 | kabny | (require '[clojure.contrib.sql :as sql]) |
| 15:33 | kabny | (def db {:classname "org.apache.derby.jdbc.EmbeddedDriver" |
| 15:33 | kabny | :subprotocol "derby" |
| 15:33 | kabny | :subname "C:/clojure/progs/pod/podcasts.db" |
| 15:33 | kabny | :create true}) |
| 15:33 | kabny | then the with-connection call returns nil. ok so how do I refer to it later? |
| 15:36 | Chousuke | kabny: with-connection doesn't make a connection; it creates a context. You're supposed to put your code inside the with-connection call. |
| 15:39 | Chousuke | kabny: according to the docs, your database will be accessible in the *db* var within the with-connection call |
| 15:41 | kabny | where are the docs? |
| 15:41 | Chousuke | er, source :) |
| 15:42 | kabny | ah because lisp code is its own documentation :) |
| 15:43 | Chousuke | (doc with-connection) may be useful |
| 15:43 | clojurebot | Excuse me? |
| 15:45 | Chousuke | kabny: apparently though you're not supposed to care about the existence of *db* |
| 15:46 | kabny | but what does that mean within the with-connection call? |
| 15:46 | kabny | so I should do (with-connection db-spec action) ? where action could be the create-table function? |
| 15:46 | Chousuke | yeah |
| 15:47 | Chousuke | like with-open |
| 15:48 | Chousuke | (with-open [file (open-file)] (do-something file) (do-something-else file)) |
| 15:48 | Chousuke | with- is a naming convention for macros like that. |
| 15:50 | kabny | ok thanks |
| 16:08 | kabny | :subname "/tmp/clojure.contrib.sql.test.db" |
| 16:08 | kabny | is that where the db will be stored? |
| 16:08 | kabny | and how do I specify a name for the db? |
| 16:09 | kabny | scgilardi, is he the same name here? |
| 16:09 | kabny | did tom hickey maintain JScheme before after Norvig? |
| 16:14 | rhickey | kabny: no, Tim Hickey, not related |
| 16:15 | kabny | ok |
| 16:31 | kabny | god I just keep loving clojure more and more |
| 16:32 | kabny | the contrib sql is so easy to use once i got it(which didnt take to long)! so small yet so more pleasant than working directly with jdbc. |
| 16:39 | kabny | is there any plans for a html-parsing-library? basically I need to extract some stuff from a big amount of html-pages, I resort to Java then? any wish for a clojure-html-parsing-lib? |
| 16:39 | kotarak | kabny: there is some xml stuff in clojure and contrib. Maybe this helps? |
| 16:50 | chrisn | An interesting problem would be an API that is more difficult that jdbc |
| 16:50 | chrisn | odbc I guess |
| 17:08 | kabny | how do you host a webapp? I know Google appengine lets you host for free but then you have to use Python(which is fine btw). Is it good? What are the alternatives? are their good ones that let you pay a monthly fee? or is the normal thing to have your own server? |
| 17:10 | lauri | kabny:you can read about one possibility here: http://ericlavigne.wordpress.com/2008/12/18/compojure-on-a-slicehost-vps/ |
| 17:15 | danlarkin | javascript snowflakes |
| 17:15 | danlarkin | what year is it? |
| 17:16 | ericlavigne | danlarkin: They'll be gone in a few days. Just celebrating Christmas :-) |
| 17:16 | danlarkin | they are distracting my eyes :( |
| 17:17 | ericlavigne | Okay, I'll turn off the snowflakes. |
| 17:17 | danlarkin | huzzah! |
| 17:17 | kotarak | ericlavigne: maybe they can be restricted to the area without text? |
| 17:19 | ericlavigne | kotarak: That would be a huge improvement, but I didn't create the theme. |
| 17:19 | ericlavigne | There's also a new article on setting up PostgreSQL for use with Clojure. |
| 17:20 | ericlavigne | http://ericlavigne.wordpress.com/2008/12/28/using-postgresql-with-compojure/ |
| 17:27 | kabny | thanks eric, very cool |
| 17:28 | darkdescendant | Got a question on Java UI: How can I clear out all my Java UI within clojure without taking down clojure itself? I.e. if I create a JFrame and show it, how do I destroy it cleanly? |
| 17:29 | ericlavigne | kabny: You're welcome. I wanted to write a Compojure application anyway, and seeing that others are enjoying the articles really helps my motivation. |
| 17:30 | darkdescendant | Is it as simple as (def <my frame> nil)? |
| 17:31 | ericlavigne | darkdescendant: There is a "dispose" method on JFrame. |
| 17:33 | ericlavigne | You can also setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE) so it will dispose itself when a user hits the close button or the X. |
| 17:33 | darkdescendant | Thanx! |
| 17:35 | darkdescendant | (My Java/Swin exp is poor at best) |
| 17:35 | ericlavigne | darkdescendant: I would prefer to have less Java/Swing experience. I program Java by day and escape to Lisp at night. |
| 17:36 | kotarak | ericlavigne: sneak in a clojure.jar. ;) |
| 17:37 | ericlavigne | kotarak: The thought has crossed my mind, but my boss wants the code to be all Java because Java programmers are easier to hire. |
| 17:38 | ericlavigne | He apparently hasn't noticed how often you end up with Lisp and Haskell programmers when you look for Java programmers. |
| 17:38 | darkdescendant | I program C/C++ by day. :-) |
| 17:38 | ericlavigne | darkdescendant: Now I feel better :-P |
| 17:38 | kotarak | I "program" Excel. At least it's functional... |
| 17:39 | darkdescendant | Hey, at least basing it on Java means I can create an x-plat UI for my app. It also means I can pick my OS platform (to an extent). I have a Macbook and I run Linux and Windows under VMWare. I can easily do clojure an any of those (and in fact I setup my Linux box with it). |
| 17:39 | darkdescendant | kotarak: I feel your pain. -) |
| 17:42 | kotarak | darkdescendant: Oh. Not necessary painful. Excel is actually quite powerful. And it simply awesome for exploratory data analysis, eg. with pivot tables. But maintaining a spreadsheet with some calculations.... *ugh* |
| 17:42 | Chousuke | there was one guy who did a 3d cube in excel |
| 17:43 | Chousuke | I though that was the epitome of pointlessness. |
| 17:43 | Chousuke | thought* |
| 17:43 | darkdescendant | Space Invaders in Excel. |
| 17:43 | darkdescendant | I heard someone make the point that as soon as you can write a game on something, it ceases being an app and becomes an OS. |
| 17:44 | Chousuke | :p |
| 17:57 | chrisn | there is/was a weird flight simulator in excel |
| 17:57 | chrisn | It was written in c though |
| 18:10 | chrisn | given a sequence like ((1 2) (1 3) (1 4)) how do I lazily create (1 2 1 3 1 4)? |
| 18:10 | chrisn | (apply concat seq) isn't very lazy |
| 18:10 | chrisn | I don't think |
| 18:10 | ericlavigne | chrisn: I think there's a function called flatten. |
| 18:10 | ericlavigne | ,(flatten '((1 2) (1 3) (1 4))) |
| 18:10 | clojurebot | java.lang.Exception: Unable to resolve symbol: flatten in this context (NO_SOURCE_FILE:0) |
| 18:11 | kotarak | (interpose (ffirst s) (map second s)) |
| 18:11 | ericlavigne | maybe flatten is in clojure-contrib |
| 18:12 | danlarkin | it is, in seq-utils I believe |
| 18:13 | chrisn | found it, thanks |
| 18:14 | chrisn | It appears to do a complete flatten using tree-seq, but only return items that aren't sequences |
| 18:18 | Chousuke | hm |
| 18:18 | kabny | javadoc in contrib, is it for auto-generating documentation of clojure-files? |
| 18:18 | Chousuke | I'm experimenting with my own clojurebot |
| 18:18 | kabny | we need such a program... |
| 18:18 | Chousuke | and it's not letting me run any code... |
| 18:18 | Chousuke | I wonder what's wrong. |
| 18:19 | Chousuke | it keeps complaining about classloaders |
| 18:19 | Chousuke | ,(System/getProperty "java.home") |
| 18:19 | clojurebot | java.security.AccessControlException: access denied (java.util.PropertyPermission java.home read) (NO_SOURCE_FILE:0) |
| 18:19 | Chousuke | hmm |
| 18:20 | Chousuke | so it *should* allow some stuff. |
| 18:22 | Chousuke | ... my policy file is somehow screwed up I guess |
| 18:23 | Chousuke | it's a simple grant-all file though |
| 18:34 | kabny | anyone use tagsoup? i cant find the documentation: http://home.ccil.org/~cowan/XML/tagsoup/#warning |
| 18:34 | kabny | is htmlparser good? |
| 18:45 | kabny | htmlparser seems good |
| 18:46 | ericlavigne | kabny: what are you working on? |
| 18:47 | kabny | recommender/aggregator thingie |
| 18:47 | kabny | webapp/cellphone app |
| 18:47 | kabny | gonna do for android in Java and the webapp in Clojure+compojure |
| 19:22 | kabny | what does protected constructor mean? god some Java-libs are so deeply nested(but better too much documentation that none at all I guess). |
| 19:24 | gnuvince_ | What's a good intro book on Java without the usual "a variable is a memory cell where you can put a value" newbie stuff? |
| 19:25 | drewr | gnuvince_: I thought "Thinking In Java" was OK, but it does have its share of newbie-friendly stuff. |
| 19:27 | emacsen | So the DC Clojure study group is still looking for project ideas if anyone has any. Something generally useful but not full time projects |
| 19:30 | kabny | if: (URL. site) works then why doesnt: (HttpURLConnection. (URL. site)) |
| 19:30 | kabny | java.lang.IllegalArgumentException: No matching ctor found |
| 19:30 | kabny | when |
| 19:30 | kabny | protected HttpURLConnection(URL u) |
| 19:30 | kabny | Constructor for the HttpURLConnection. |
| 19:30 | kabny | http://java.sun.com/j2se/1.4.2/docs/api/java/net/HttpURLConnection.html |
| 19:31 | rhickey | kabny: it's protected |
| 19:32 | danlarkin | kabny: there's an openConnection method on URL I think? |
| 20:37 | kabny | <i><a href="http://media.libsyn.com/media/seradio/seradio-episode119-DSLsInPracticeWithJPTolvanen.mp3" rel="nofollow">Download MP3</a></i> |
| 20:37 | kabny | what does nofollow mean? dont link? |
| 20:38 | kabny | or wait it is for googles spider |
| 20:40 | Chouser | kabny: it's meant for google and other spiders to indicate no enorsement of the quality of the link |
| 20:52 | kabny | why doesnt (doc multimethods return the args passed)? |
| 20:58 | Chouser | kabny: by default defmulti doesn't add arglist or doc metadata |
| 20:58 | Chouser | but you can provide either or both: |
| 20:58 | Chouser | (defmulti #^{:doc "does foo stuff" :arglists '([bar & more])} foo class) |
| 20:59 | kabny | how can I convert a string to a regexp? |
| 21:00 | kabny | "mp3" to #"mp3" |
| 21:00 | Chouser | (doc re-pattern) |
| 21:00 | clojurebot | Returns an instance of java.util.regex.Pattern, for use, e.g. in re-matcher.; arglists ([s]) |
| 21:09 | eldok | i added the metadata but it still doesnt show up when doing (doc f) |
| 21:09 | eldok | whats the char I have to add when asking for metadata nyway? |
| 21:12 | eldok | (defn scanl |
| 21:12 | eldok | #^{:doc |
| 21:12 | eldok | that is the correct place for meta right? |
| 21:13 | Chouser | eldok: not like that. you can put a plain string there instead #^{...} and it'll work. |
| 21:14 | alphazero | gnuvince_: http://www.mindview.net/Books/TIJ/ |
| 21:14 | Chouser | eldok: or just leave off the #^ prefix |
| 21:15 | Chouser | eldok: those are features of 'defn'. To use the more general #^{...} format, put that before the name of the var you're defining. |
| 21:16 | Chouser | kabny, eldok: http://paste.lisp.org/display/72759 |
| 22:39 | achim_p | hi all! is anybody aware of a bytecode inspection/disassembly tool that doesn't choke on clojure bytecode? |
| 22:40 | achim_p | i just tried to package a clj hello world for android, which gave me a bytecode related error |
| 22:42 | achim_p | http://pastie.org/348098 - now i'd like to see what's happening at bytecode offset 0000003a ... |
| 22:48 | eldok | achim_p: sorry I can't help you but really cool you try to get Clojure going n Android. I'm writing a webapp/Android app using Clojure/Java. Would really like to write everything in Clojure. |
| 22:49 | eldok | achim_p: since you are doing such stuff I suppose you are aware that Android use its own VM, the Dalvik VM. could that be related to the error? |
| 22:51 | achim_p | eldok: it doesn't even get that far, it fails while building. the "dexer" doesn't seem to like ns_public's bytecode |
| 22:54 | eldok | dexer? |
| 22:55 | eldok | are you running it on a real phone or on the emulator? |
| 23:02 | achim_p | eldok: dx, the tool that generates dex files. i'm on an emulator, but i don't think that's emulator-specific ... i don't know much about android though |
| 23:02 | achim_p | http://code.google.com/intl/de-DE/android/reference/othertools.html |
| 23:08 | eldok | so you use Clojure's compile then dx to convert to Android bytecode? |
| 23:09 | achim_p | yep |
| 23:11 | eldok | so probably it is the clojure-generated code that is incompatible with Dalvik bytecode? |
| 23:11 | achim_p | so it seems |
| 23:11 | eldok | rhickey: where is compile? |
| 23:13 | danlarkin | IIRC there is a vestigial class loader related issue with the android VM |
| 23:13 | eldok | vestigial? |
| 23:13 | danlarkin | that may have been dealt with by now, though |
| 23:14 | danlarkin | I'm often wrong about these things I pull from the back of my brain |
| 23:14 | eldok | A rudimentary or degenerate, usually nonfunctioning, structure that is the remnant of an organ or part that was fully developed or functioning in a preceding generation or an earlier stage of development. |
| 23:15 | achim_p | that's the error message: local variable type mismatch: attempt to set or access a value of type java.lang.Object using a local variable of type boolean. This is symptomatic of .class transformation tools that ignore local variable information. |
| 23:15 | achim_p | doesn't look classloader-related |
| 23:16 | danlarkin | I was going for the, "having become functionless in the course of evolution" |
| 23:17 | rhickey | I saw this when I first tried dx from the Android SDK - looking at it now. It is a bytecode thing, not related to classloaders - the dx verifier chokes on something the Java verifier doesn't |
| 23:17 | danlarkin | wrong again! my record continues |
| 23:21 | gnuvince | I asked a question earlier today, but I've been having problems with my Internet connection all day since then, so I haven't caught an answer (if there were one): what book would you suggest to somebody who wants to quickly get up to speed on Java? |
| 23:22 | zakwilson | http://per.bothner.com/blog/2008/AndroidHelloScheme/ <-- somebody just got Kawa working on Android. |
| 23:22 | eldok | (defn hash |
| 23:22 | eldok | "Returns the hash code of its argument" |
| 23:22 | eldok | [x] (. clojure.lang.Util (hash x))) |
| 23:23 | eldok | can someone explain that to me? |
| 23:23 | eldok | rhickey: where is compile in the src of Clojure? |
| 23:23 | gnuvince | eldok: this calls the .hash() method of clojure.lang.Util with an argument x. |
| 23:24 | rhickey | eldok: clojure.lang.Compiler |
| 23:26 | eldok | ah so it refers to another method hash |
| 23:29 | eldok | hmm so it is not the compile.java but the: |
| 23:29 | eldok | public static Object compile(Reader rdr, String sourcePath, String sourceName) throws Exception{ |
| 23:29 | eldok | in Compiler.java ? |