#clojure logs

2009-08-07

00:01JAS415hmm?
00:01JAS415tdd?
00:02JAS415i delete all my code and start over all the time
00:02JAS415but most of the time i keep it around so i can rewrite it
00:02tomojI ended up with a huge nasty nasty mess
00:02JAS415rewrite/cannibalize
00:02JAS415yeah
00:02tomojdoing things like (first (first blah)) multiple times to deal with shitty functions I had written before
00:02JAS415haha yeah that's a problem
00:03tomojand really long chains of crap with multiple anonymous functions and duplication all over the place :(
00:03JAS415are you parsing xml or something?
00:03JAS415duplication is time for some function passing or a macro though :-)
00:04tomojparsing html
00:04tomojnasty, nasty html
00:05JAS415i avoid html when i can
00:05tomojI wish I could
00:05tomojif my university offered the course schedule in JSON I would love them
00:05JAS415haha yeah
00:05JAS415JSON is beautiful by comparison
00:06JAS415and it parses into clojure really nicely
00:06_mstif you're willing to delve into java land slightly, I've found htmlcleaner.sourceforge.net nice for parsing "in the wild" html
00:06JAS415i think there is a contrib library for xml
00:07JAS415if is regular html (i.e. isn't missing anything) it might work
00:08Deranderclearly clojure needs hpricot
00:08JAS415hpricot?
00:08Deranderruby library, makes html über easy
00:09JAS415how does it work?
00:09tomojwe have enlive
00:09DeranderJAS415: not familiar w/ the internals.
00:09tomojdoes css selectors nicely
00:09tomojand it's extensible
00:09Deranderah, spiffy.
00:10tomojlike, it can do more than css
02:12tomojhmm
02:13tomojto me it seems like I have to think backwards to write clojure
02:13tomojI mean, anticipate all the little functions I will need in the future
02:14tomojor write a whole lot of code without compiling, or figure out some trick to have the compiler ignore the high level method I'm working on while I'm coding the smaller ones
02:16tomoj...or just learn to use clojure-mode better :)
02:16mebaran151you could always just declare the functions
02:16mebaran151or mock them up
02:17mebaran151also #_ is your friend (it will comment out exactly one expression)
02:17hiredmanI tend to spend a lot of time in the repl
02:17mebaran151so #_(defn my-giant-fuction []) will get rid of that def all in one swoop
02:17tomojah nice
02:17tomojI think I can just compile each smaller defun individually as well
02:17tomojinstead of compiling the whole file
02:17mebaran151yep
02:17mebaran151but sometimes it's easier just to slurp the whole file
02:18hiredmanusing -> and adding stuff to the chain until I get the desired output
02:18mebaran151after quickly marking the fialures
02:18hiredmantomoj: what do you mean by "compile"?
02:18tomojpreviously I was doing slime-compile-and-load-file after every change
02:19tomojwhich means the whole file has to compile successfully (so either comment out code that calls nonexistant code or declare the nonexistant functions)
02:19hiredmanoh
02:19hiredman:/
02:19hiredmanI load a function or so at a time
02:20tomojclojure-mode binds lisp-eval-defun to "\e\C-x".. O_o
02:21alinphi
02:21alinphow does clojure handle list copying ?
02:22alinpI mean ... (conj [1 2 3] 4)
02:22alinpit will not mutate the current collection (we all know that)
02:23tomojintelligently
02:23alinpand as far as I remember, Rich said that the copying will not be expensive
02:23tomojhttp://blog.higher-order.net/2009/02/01/understanding-clojures-persistentvector-implementation/
02:23alinpok, thanks tomoj, I'll read about that
02:27alinphmmm
02:27alinpthere is also some System.arraycopy there
02:28tomojit's amortized
02:30tomojat least, I think so..
02:42fsmHello everyone.
02:42fsmIs there a good sample anywhere to she the best practise for reading/parsing binary files in Clojure?
02:43fsmsee*
03:19demasHi,all. I need your help. I just wanted to use partition-all. I use 'Clojure 1.1.0-alpha-SNAPSHOT'.
03:20demasBut when I write 'user=> (use 'clojure.contrib.seq-utils)'
03:20demasI have got next error message 'java.io.FileNotFoundException: Could not locate clojure/contrib/seq_utils__init.class or clojure/contrib/seq_utils.clj on classpath: (NO_SOURCE_FILE:0)'
03:20demasIs there any ideas how to fix this error ?
03:21hoeck1demas: adding clojure-contrib.jar to the classpath
03:22hoeck1demas: or adding the src folder of your clojure-contrib repository to the classpath
03:22demasHow can I find clojure-contrib.jar? Is it part of clojure?
03:23hiredman~google clojure contrib
03:23clojurebotFirst, out of 4800 results is:
03:23clojurebotclojure-contrib - Project Hosting on Google Code
03:23clojurebothttp://code.google.com/p/clojure-contrib/
03:23hiredmanugh
03:23demasthanks
03:23hiredmanthat is not right
03:23hiredman~google clojure contrib github
03:23clojurebotFirst, out of 1160 results is:
03:23clojurebotrichhickey's clojure-contrib at master - GitHub
03:23clojurebothttp://github.com/richhickey/clojure-contrib/tree/master
03:23hiredman
03:24demasok, thanks
03:24hiredmanclojurebot: contrib?
03:24clojurebotcontrib is http://code.google.com/p/clojure-contrib/
03:24hiredmanclojurebot: contrib is http://github.com/richhickey/clojure-contrib/tree/master
03:24clojurebot'Sea, mhuise.
03:24lpetitclojurebot: contrib?
03:24clojurebotcontrib is http://github.com/richhickey/clojure-contrib/tree/master
03:25lpetityour bot is really really cool :)
03:25lpetit~contrib
03:25clojurebotcontrib is http://github.com/richhickey/clojure-contrib/tree/master
03:25hiredman~botsnack
03:25clojurebotthanks; that was delicious. (nom nom nom)
03:26lpetit~google eclipse clojure plugin
03:26clojurebotFirst, out of 8920 results is:
03:26clojurebotclojure-dev - Project Hosting on Google Code
03:26clojurebothttp://code.google.com/p/clojure-dev/
03:26lpetitYes!
03:26lpetit:)
04:12Jomyootintellij needs better support
04:19vyShouldn't (let [[#^String x y & z] "abcdef"] [x y z]) supposed to throw an error since x is not a string?
04:28lpetithmm
04:29lpetit,(let [#^String x "a"] (prn x))
04:29clojurebot"a"
04:29lpetitno sorry !
04:29lpetit,(let [#^String x \a] (prn x))
04:29clojurebot\a
04:29hoeck1vy: I would say it throws an exception if you call a String only method on it
04:32lpetitindeed, it seems it's just for optimizing code for avoiding reflection, but not complaining if the type is not correct but not used for any reflection-avoiding code optimization
04:32lpetit,(let [#^String x "a"] (.length x))
04:32clojurebot1
04:33lpetit,(let [#^String x \a] (.length x))
04:33clojurebotjava.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.String
04:33lpetit,(let [x \a] (.length x))
04:33clojurebotjava.lang.IllegalArgumentException: No matching field found: length for class java.lang.Character
04:44lpetit(binding [*warn-on-reflection* true] (let [x "a"] (.length x)))
04:44lpetit,(binding [*warn-on-reflection* true] (let [x "a"] (.length x)))
04:44clojurebot1
05:19angermanhow can I do something like (assoc obj {:k1 1 :k2 2}) ...?
05:19angermanbasically I'd need to destruct the map in place
05:34Chousukeangerman: destruct? you mean you want to merge obj and the map?
05:37lpetitangerman : (merge obj {:k1 1 :k2 2})
05:42angermanChousuke: well, no I want it to be (assoc obj :k1 1 :k2 2)
05:43angermanbut yes I guess that's what merge does
05:43angermanhmm... I'm kinda stupid today I guess :)
06:32djpowellI'm currently using a big map to implement a sort of union-find datastructure, where key-value mappings represent edges in the tree. I guess building that might be sped up a bit by a transient hashmap?
06:37djpowelltbh though, most of the stuff I'm doing with clojure involves processing data from database queries, so I haven't had any kind of performance problems with clojure, that aren't be dwarfed by i/o
06:43angermanwhat is an easy way to turn [:x 1 :y 2] into {:x 1 :y 2}?
06:45jdz,(apply hash-map [:x 1 :y 2])
06:45clojurebot{:y 2, :x 1}
06:45angermanaye
07:46Chousukehmm
07:46Chousukesyntax-quote behaviour with maps is weird.
07:46Chousuke,`{~@(do [1 2]}
07:46clojurebotUnmatched delimiter: }
07:47Chousuke,`{~@(do [1 2])}
07:47clojurebot1
07:47Chousuke,`{1 ~@(do [1 2 3])}
07:47clojurebot{1 1, 2 3}
07:47ChousukeI think I know why that is, though.
08:12angermanis there a short hand to create a keyword from a symbol or do I have to go the (keyword (str x)) route?
08:12jdzi'd use name instead of str
08:13rhickey,(keyword 'foo)
08:13clojurebotjava.lang.ClassCastException: clojure.lang.Symbol cannot be cast to java.lang.String
08:14rhickeyworks in master
08:14angermanahh, ok :)
08:14angerman,(keyword (name 'foo))
08:14clojurebot:foo
08:15rhickey,(clojure.lang.Keyword/intern 'foo)
08:15clojurebotDENIED
08:15rhickeynice
08:15angerman,(try (keyword 'foo) (catch ClassCastException e (keyword (name 'foo)))
08:15clojurebotangerman: Titim gan éirí ort.
08:15angermanyes.
08:20angermanrhickey: what is better? using defmulti and multimethod or having a map with lambdas that get called?
08:22jdzit is actually not the same thing
08:22angerman(let [dispatch-map {:a (fn [...] ...) :b (fn [...] ...)}] ((dispatch-selector dispatch-map) arg0 arg1 arg2 ...))
08:23jdzthere's a benefit of using multimethods: you can pass around a single thing
08:23jdzon the other hand, you can wrap your dispatch map in a function
08:25angermanhmm i'll play with it a bit
08:26rsynnottwhy does clojurebot speak Irish?
08:26rhickeyangerman: better how? defmulti automate the map/call process
08:27angermanrhickey: so the implementation does pretty much the same?
08:28rhickeyangerman: multimethods use maps, they also do isa stuff and caching, why not use the most straightforward thing (multimethods)?
08:28jdzi'd also go the fewer-wheel-invention road
08:30angermanwell, using dispatch-maps was something i knew already, I'm just getting used to defmulti
08:31jdzafter thinking a bit, it appears to me that defmulti does just that, with some clever stuff mixed in
08:31jdzin your case, you even don't have to redefine dispatch-selector
08:32jdz(or so it seems to me)
08:47cgrandrhickey: (-> {} (assoc :a ()) (assoc :a [])) returns {:a []} but would it be ok to return {:a ()}? (no assoc when equality)
08:49rhickeycgrand: no, a list is not a vector
08:50cark,(= [] ())
08:50clojurebottrue
08:50rhickeyif someone were to start conjing on the val at that key they'd get different results
08:50carkhum
08:51cgrandok, the last assoc must win for values
08:51AWizzArd,(identical? [] ())
08:51clojurebotfalse
08:52cgrandBUT right now (-> {} (assoc () :a) (assoc [] :a)) returns {() :a} should it return {[] :a} instead
08:52cgrand?
08:53carkhey awizard !
08:53AWizzArd,(-> {} (assoc () :a) (assoc [] :a))
08:53cark,(identical? [1] '(1))
08:53clojurebot{() :a}
08:53clojurebotfalse
08:53cark,(identical? (list 1) (list 1))
08:53clojurebotfalse
08:53AWizzArdcark: = is more like equal in CL
08:54cemerickidentical? is reference identity, nothing to do with equality
08:54cemerick== in java, pointer comparison in C
08:54carkbut is it ok to have a list and a vector being = ?
08:54cemerickcark: absolutely; it's up to the callee of = to decide what equality means
08:54AWizzArd= traverses them
08:55carkhow about the conj argument from rhickey ?
08:55AWizzArdthere is an infinit set of meanings of what equality means. The most basic one is checked with identical?.
08:55rhickeycgrand: keys are based on equality, the values identity test is an optimization
08:56cemerickAWizzArd: identical? is *not* equality. It returns true only if two objects are *exactly the same* object.
08:56cgrandok, understood, thanks
08:56cemerickWhich, in general, is hardly ever what you want.
08:57cemerick,(identical? "foo" "foo")
08:57clojurebottrue
08:57cemerick,(identical? "foo" (str "foo" ""))
08:57clojurebotfalse
08:58cemerickeven better:
08:58cemerick,(identical? 500 500)
08:58clojurebotfalse
08:58rhickeycgrand: the values identity test is an optimization that should be preserved, code can depend on assoc of item already in collection => same collection
08:58jdzcemerick: this is why in CL there is eq and eql
08:59rhickey,(let [m {:a :b}] (identical? m (assoc m :a :b)))
08:59clojurebottrue
08:59jdz,(let [m {:a 500}] (identical? m (assoc m :a 500)))
08:59clojurebotfalse
08:59cemerickrhickey: that's cute
09:00cemerickjdz: I've thankfully forgotten all of the shades of equality in CL, but OK :-)
09:00jdzi expect many newbies to rave in agony upon finding this out
09:00carkactually i liked the precision of CL equality, though there is always more variations
09:00rhickeyjdz: that's the same value, not the same object
09:00jdzrhickey: yes, go tell that to the newbies ;)
09:01rhickeyjdz: newbies shouldn't be using identical
09:01cemerick(almost) no one should use identical, unless you're writing core data structures
09:01rhickeyif they have that expectation they don't understand equality yet
09:01rhickey,(let [m {:a 500}] (= m (assoc m :a 500))
09:01clojurebotEOF while reading
09:02rhickey,(let [m {:a 500}] (= m (assoc m :a 500)))
09:02clojurebottrue
09:02cemerickI think I've used it once or twice in ~14 months of clojure-ing, and I seem to remember it causing problems.
09:02angermancanI filter a map?
09:06jdzi was actually recently a bit surprised that rest on a vector returns different objects
09:06jdz,(let [s (seq [1 2 3])] (identical? (rest s) (rest s))
09:06clojurebotEOF while reading
09:07jdz,(let [s (seq [1 2 3])] (identical? (rest s) (rest s)))
09:07clojurebotfalse
09:07jdz,(let [s (seq '(1 2 3))] (identical? (rest s) (rest s)))
09:07clojurebottrue
09:07jdz(was writing a tree substitution thing which would not copy a branch if there were no substitutions made)
09:08rhickeyjdz: how could it efficiently do otherwise?
09:08rhickey(vectors not being a linked data structure)
09:11jdzwell, after thinking about it, it makes perfect sense
09:11jdzand i was not really *very* surprised, just a little bit
09:21Chousukehm
09:24Chousukeisn't (binding [foo bar] ...) supposed to establish a thread-local binding?
09:38gulagong_hi guys
09:38cgrandhi gulagong_
09:38gulagong_what happened to a java object which brings my thread to an infinite loop when i try to print it or return it ?
09:39gulagong_when printing it prints the classname and than hangs
09:39gulagong_while it is printable
09:40gulagong_difficult to describe for me but i nailed my problem down to this
09:43gulagong_it heats up one core and and my profiler crashes...
09:45jdzcalculating with infinities is not supported on modern hardware
09:46gulagong_jdz: is this an answer to me?
09:46Chousukeso what's wrong if I do, in a macro, (binding [*foo* {}] (macro-driver* form)) and then try to (set! *foo* (assoc *foo* :stuff :here)) within macro-driver*?
09:46ChousukeI get an error about not being able to change root bindings :/
09:46jdzgulagong_: kinda
09:47jdzgulagong_: and what do you mean by "it is printable" when apparently it enters infinite loop?
09:48gulagong_jdz: these objects can regulary be printed
09:48gulagong_jdz: just this one in this situation not
09:49jdzgulagong_:so then it's easy - just look for what's different in "this situation"
09:49gulagong_jdz: its a matrix from the colt library
09:50gulagong_jdz: that is my problem.... i don't find a difference
09:50gulagong_jdz: it seems to have disappeared and send my cpu for a search out...
09:51jdzgulagong_: what seems to have disappeared?
09:51gulagong_the contents of the array
09:52gulagong_jdz: it prints the classname and then hangs when trying to print the array-content
09:52jdzso the array-content is infinite then
09:52gulagong_nope
09:53gulagong_#<DenseDoubleMatrix2D
09:53gulagong_and then nothing
09:53jdztry printing it to a PrintStream with auto flushing
09:54gulagong_which would be?
09:55Chousukeah, I needed to use alter-var-root instead of set!...
09:55gulagong_jdz: it is a list of these matrices and all but the first element work... although i treat them all the same
09:56gulagong_jdz: and in the function returning this list i still have acces to the elements of this object
09:56jdzgulagong_: have you tried what i suggested?
09:57gulagong_jdz: i don't know which printstream has auto-flushing
09:57jdz*the* PrintStream
09:57gulagong_ok
09:58djpowellhmm - there is no sorted-set-by, to correspond to sorted-map-by (the constructor that takes a custom comparator)
09:59Chousukeuser> (syntax-quote (fn [foo#] (+ foo# ~x)))
09:59Chousuke(clojure.core/fn [foo__auto__26935] (clojure.core/+ foo__auto__26935 1))
09:59Chousuke\o/
10:03gulagong_jdz: like this? (with-out-str (prn OBJECT)) ?
10:05gulagong_jdz: i used this as return value an it hung up
10:06jdzgulagong_: no, like (binding [*out* (new java.lang.PrintWriter *out* true)] (prn OBJECT))
10:06gulagong_jdz: ok, thanks
10:06jdz(untested)
10:07jdzor you can use System/out or System/err instead of *out* when creating that stream
10:14Chousukehttp://gist.github.com/163921 hairy stuff... still needs some tweaking for special forms at least.
10:16gulagong_jdz: i tried and its the same problem
10:17jdzgulagong_: well then, since you don't have any output you'll have to work out where the cycle in your data structures is by yourself...
10:18gulagong_jdz: there is no cycle....
10:18jdzgulagong_: how do you know?
10:18b4taylorWell if it's a pure data structure you can't make a cycle.
10:19gulagong_jdz: cause i debug- printed this object before- then i return it and its contents brake the print?
10:19jdzb4taylor: as mentioned before it is something from external library
10:19gulagong_yap, a matrix
10:19b4taylorjdz: Sorry, just got here :p
10:20gulagong_but i'm not doing any concurrent stuff
10:20b4taylorAh, which one are you using? I tried out Jama.Matrix.
10:20gulagong_colt
10:21gulagong_and it's great :)
10:21gulagong_eccept that it dissapears ;)
10:21b4taylorDisappears in what way?
10:22jdzgulagong_: it does not disappear. clojure tries to print it, and it [as you say] enters infinite loop
10:22b4taylorOne problem I've been having is getting back lazy-seqs and having to force them with dorun.
10:22gulagong_no, nothing to do with that
10:22b4taylorAh.
10:22gulagong_i return it and after that clojure knows the classname but not the contents.... from what i can observe
10:23gulagong_but only in one case
10:23jdzgulagong_: i told you like 3 times that what you observe is not what really happens.
10:23gulagong_jdz: i know
10:24gulagong_jdz: so, maybe i should ask how to observe better
10:24gulagong_jdz: but my profiler crashes... thats why i'm here - i have no clue
10:25jdzgulagong_: you don't need profiler. you need debugger.
10:26gulagong_jdz: ok, i'll try to find one for osx
10:28b4taylorI'm having some trouble importing from files in my current project. Say I have the files foo/bar/a.clj and foo/bar/b.clj and appropriate (ns foo.bar.a (:import foo.bar.b)) as well as (ns foo.bar.b) lines in each file respectively, why would this fail? Should I add /pathtofoo to my CLASSPATH?
10:28jdzyou use import for Java packages
10:28jdzuse for clojure ones
10:28b4taylorOh of coarse.
10:29b4taylorDamn, thanks.
10:33leafwwhere are the docs for the xml functions?
10:33leafwsearch "xml" failed in the website.
10:40bstephensonwell, there is this rather sparse documentation: http://clojure.org/api#toc673
10:43bstephensonand clojure.contrib has clojure.contrib.lazy-xml, zip-filter.zml, and a bunch of other xml utility funcs
10:43bstephensons/zml/xml
10:43leafwthanks
10:45leafwbstephenson: by the way what is the fn to visualize an xml as a JTree in a JFrame? Haven't used this in a while
10:45bstephensondo (find-doc "xml") in your repl, and you will find all references to xml in the docs. if you have clojure.contrib library associated with your repl, you will get its funcs too
10:46bstephenson,(find-doc "xml)
10:46clojurebotEOF while reading string
10:46bstephenson,(find-doc "xml")
10:46clojurebot------------------------- clojure.core/xml-seq ([root]) A tree seq on the xml elements as per xml/parse ------------------------- clojure.zip/xml-zip ([root]) Returns a zipper for xml elements (as from xml/parse), given a root element ------------------------- hiredman.clojurebot.svn/summary ([tag-map]) takes output of clojure.xml/parse on svn's xml log, returns a vector of [rev-number commit-message] --------------------
10:47bstephensonleafw: I will talk to my java form guys here, try to get a quick answer
10:47leafwbstephenson: I use to knew it, that's the ugly part
10:47bstephensonclojure needs a function "find-old-code". I always need that one!
10:48leafwxD
10:51leafwbstephenson: I have it, it's clojure.inspector/inspect-tree
10:54WizardofWestmarcman after finding out what an idiot I am when it comes to transients now I wish I was set up on my work computer to build clojure from source so I could play with it here. Bah
10:55rhickeyWizardofWestmarc: no one's an idiot on transients, they are pretty unusual
10:56rhickeybut best to write it functionally first then add transient/persistent!
10:57WizardofWestmarcright. Already rewrote it and pretty sure it'll work now
10:57WizardofWestmarcwhat's funny is I actually DID write the original version functionally. But I didn't wrap my reduce in the persistant! so it screwed up.
10:57bstephensonleafw: looks good, should work well for you. we are dealing with xml slightly differently here, so could not find example of us using that in our clojure code.
10:57WizardofWestmarcI did it some other way that made it not quite functional.
10:59WizardofWestmarcgoes to show what happens when you get away from functional programming, you fall out of good habits too quick when things get tough
11:07WizardofWestmarcbtw Rich, any idea when fork/join will make it back up to master?
13:05Chousukehm
13:06Chousukewonder if it'd be worthwhile to reorganise core.clj a bit.
13:07ChousukeI'm trying to implement syntax-quote as a macro, and most of the functions I need to move "up" are small java wrappers.
13:13Chousukefor now, it seems my syntax-quote works though.
13:47LauJensenGood evening gents
13:48danlarkinLau why did you change from Lau_of_DK
13:49rsynnottpossibly there is now another Lau in Denmark :)
13:49carkor moved to Jensenia
13:50leafwany trivial way to read a file line-by-line using line-seq? I.e. how to create a reader from a file path string ?
13:50leafwand I don't mean the java way, I know that one ... there must be a clojure (read-file ...) or something
13:52leafwand slurp is not useful: not broken into lines
13:52cark(with-open [stream (BufferedReader. file-name)] (do-something (line-seq stream) ...
13:52carkor something like it
13:53rsynnottonly a small amount of unsightly java :)
13:53leafwcark: the problem is, with that, I have to deal with imports
13:54leafwand I'd rather not have imports for something as trivial as creating a reader from a file.
13:54carkmhhh there was something in contribs duck-streams ?
13:54LauJensendanlarkin: Lau_of_DK was something I picked up as a temporary thing, because 'lau' was already taken. So I figured I might as well grab something a little more descriptive
13:54leafwthe same way that regex functions hide all the ugliness of java.util.regex.Pattern and friends, so could clojure hide all the FileInputStream etc verbosity with (create-reader filename) or so.
13:55rsynnottleafw: well, you could always write a macro to do it
13:55danlarkinLauJensen: reasoning accepted :)
13:55rsynnott(something along the lines of the CL with-open-file macro, possibly)
13:55leafwrsynnott: the point is I'm trying to use clojure like I would use matlab. imports just get in the way, and fully qualified names are tedious.
13:56leafwand reading a file it's such an essential thing, one would think.
13:56leafwthere is slurp. But there isn't a reader-creation function.
13:56carkyou could fully qualify BufferedReader
13:56carkso no imports
13:56rsynnott(I always have to look up the appropriate commands in whatever I'm using)
13:57rsynnottESPECIALLY in CL; I doubt anyone knows those from memory :)
13:57carkor use clojure.contrib.duck-streams/reader
13:57LauJensendanlarkin: Hows Madison coming along ?
13:57rsynnott':supersede_if_exists' et al :)
13:58danlarkinLauJensen: haven't touched it in months :-o
13:58LauJensenoh, not good
13:58WizardofWestmarcyeah I gave up on Dan and started using Compojure ;-)
13:59WizardofWestmarcthough I am using your couchdb lib (haven't played with it much but it seems to work)
13:59leafwcark: clojure.contrib.duck-streams/reader is just as long. Why not a proper function in core clojure to create a reader? It's not a big deal, and it already has functions to deal with readers (hence it looks like an omision)
13:59carkit feels like library stuff to me
14:00LauJensenWizardofWestmarc: How are you interfacing with couchdb ?
14:00carkyou should stick something in that "utils" file you will use with almost every project =)
14:01leafwcark: as much lib stuff as "slurp" is. Same thing.
14:01WizardofWestmarcDan has a library on github
14:01carkleafw:true
14:01LauJensen~couchdb
14:01clojurebotI don't understand.
14:01LauJensen~clojureql
14:01clojurebotclojureql is a quite impressive piece of work
14:01LauJensen~clojureql
14:01clojurebotclojureql is http://github.com/Lau-of-DK/clojureql/tree/master
14:01WizardofWestmarchttp://github.com/danlarkin/clojure-couchdb/tree/master
14:02WizardofWestmarconly played with it minimally as I haven't had the time to work on my clojure/compojure/couchdb project, but the very limited testing worked.
14:02LauJensenOk - Was just wondering if this was something I should assimilate into ClojureQL
14:02WizardofWestmarcI wouldn't
14:02WizardofWestmarccouchdb and sql are too different to keep the libraries together IMO
14:02LauJensenNo it doesnt look like a candidate
14:03WizardofWestmarcdocument based db instead of an RDBMS
14:03LauJensenYep
14:03WizardofWestmarcwhich is pretty interesting so far.
14:03WizardofWestmarcviews using javascript, able to easily split up data, all kinda of neat features
14:03rsynnottwould anyone be interested in something like this: http://common-lisp.net/project/elephant/ on clojure?
14:04rsynnottI'm messing around with trying to write an analogue of it
14:04rsynnott(it's an object database)
14:04LauJensenrsynnott: That makes it alot like Coachdb
14:04rsynnottyep, but not quite the same
14:04LauJensenWhat are the major differences?
14:07carkLauJensen : about clojureql, does it support runtime query building or is this all macros ?
14:08LauJensenYou can do everything runtime
14:08carkcool
14:08LauJensenYea :)
14:08carkthere are some examples of this ?
14:09LauJensenhttp://lau-of-dk.github.com/clojureql/2009/07/13/query-syntax.html
14:10LauJensenI think this will give you the general idea
14:11carkright, but what if i want to dynamically generate the where clause, like suddenly the user decides to use one of my filter boxes
14:11LauJensen(query tab [x y z] (= ~user-selection ~threshhold)) , that'll evaluate the environment at runtime
14:13carki see
14:20LauJensencark: Yea. And I know of 2 industry systems now relying on ClojureQL, and its holding up perfectly
14:20carki would be using backend.clj for total control
14:21LauJensencark: the frontend is all the functions you need to worry about. They compile an sql statement to our own format (which is a hash-map basically), then that gets passed through the backend when you call execute-sql or compile-sql, which then form a sql statement fitted for your particular database.
14:21LauJensen(note, postgresql create-table is currently under review)
14:22carkyes, but the point is that the structure of my queries varies quite a lot in a single function
14:22carki quickly made something like your backend file, but yours is way cleaner
14:23LauJensenI dont quite follow
14:23LauJensen~clojureql is http://gitorious.org/clojureql/clojureql
14:23clojurebotc'est bon!
14:23carksay one query would be : select * from calls ... and the other select * from call where a=? and b=?
14:24carkand i need to programatically construct these
14:24LauJensenSo why wouldnt you just wrap that in a cond or condp, calling query as needed?
14:25carkbecause of combinatorial explosion
14:25LauJensenIf you like, you can Gist an example
14:25carki'd never see the end of it
14:25LauJensen(are everybody aware that Emacs integrates Gists very nicely? Push buffer to gist? Pull gist to buffer?)
14:26WizardofWestmarcno but I only use GIT/github at all because clojure and several of it's useful libraries are on it :P
14:26LauJensenSeriously? :D
14:27rsynnottWizardofWestmarc: is there any vcs particularly associated with windows?
14:27rsynnott(they got rid of sourcesafe, right? :) )
14:27ChousukeLauJensen: gist.el fails to consider clojure-mode in *scratch* though :(
14:27ChousukeLauJensen: even after I added it to the list of knonw modes
14:28LauJensenChousuke: Really? I hadn't noticed
14:28ChousukeLauJensen: you don't get syntax highlighting if the file isn't named foo.clj :/
14:28Chousukeso I made a scratch.clj :P
14:28LauJensenWell, I usually just mark a region and then gist it
14:28LauJensenhehe
14:29carkLauJensen: i'm not sure we're talking about the same thing, a good example are the html libraries in CL ... they all are macros ... but I prefer having lists that i can tear appart and mix together at run-time instead of compile-time. html libs are easier to me in clojure for that reason
14:29WizardofWestmarcrsynnott I prefer mercurial
14:29LauJensencark: I think we are. We use drivers for all our macros to force evaluation of all the items we need to evaluate.
14:29WizardofWestmarcit works on every platform easily
14:30WizardofWestmarcsince it's python based.
14:30LauJensenWizardofWestmarc: But seriously.. Windows? :)
14:30WizardofWestmarcthough to be fair the Github guys made a bridge between git and mercurial
14:30WizardofWestmarcLau: a) dayjob, and b) I still game sometimes :P
14:30WizardofWestmarcand I despise apple so Mac isn't an option.
14:30LauJensenI have a Macbook which runs Linux perfectly well
14:30WizardofWestmarcthough my current clojure project is on an ubuntu 9.04 server VM.
14:31carkLauJensen: well i'll look into it =) thanks for your time
14:31LauJensennp
14:31WizardofWestmarcagain, despise apple so no macbooks ;-)
14:31LauJensenok, sounds like a political thing
14:32WizardofWestmarcnot exactly. I don't like microsoft either honestly, but Wine doesn't cut it for some stuff sadly.
14:33WizardofWestmarcand my day job is windows dev so it's hard to jump off the deep end and just go pure linux.
15:18cddrwhat's the clojure equivalent of CLOS's `call-next-method'?
15:21hiredmancddr: I don't think there is one, but you can use parent and get-method
15:22hiredman,(parent String)
15:22clojurebotjava.lang.Exception: Unable to resolve symbol: parent in this context
15:22hiredman:/
15:22hiredman,(parents String)
15:22clojurebot#{java.lang.CharSequence java.lang.Object java.io.Serializable java.lang.Comparable}
15:23hiredman,(get-method print-method Object)
15:23clojurebot#<core$fn__6175 clojure.core$fn__6175@199de59>
15:23hiredman,((get-method print-method Object) "foo")
15:23clojurebotjava.lang.IllegalArgumentException: Wrong number of args passed to: core$fn
15:23hiredmanwhoops
15:23hiredman,(doc print-method)
15:23clojurebot"; "
15:23hiredmanclojurebot: worthless
15:23clojurebotPardon?
15:25cddrhiredman: thanks, I think I get it ((get-method (first (parents obj))) obj)
15:26hiredmansomething like that
15:27cemerickcddr: there was a very interesting thread on the group talking about clos, call-next-method, and how to do similar things in clojure, which led to Rich adding get-method (which is a superset of java's super, call-next-method, etc). Can't find it now, of course.
15:29cddryeah I was surprised a search of the groups archive didn't turn anything up
15:30cddrdoes it keep all the history?
15:30cemerickgoogle groups search *sucks*. hard.
15:30hiredman
15:30cemerickyou're actually better off querying on google.com with "site:groups.google.com clojure ....."
15:35WizardofWestmarcyeah, it's kinda funny how bad groups search sucks, when google's searching groups with the web engine is fine...
15:36cemerickwell, not fine by any stretch, but not totally useless
15:38LauJensen~brain-dump
15:38clojurebotbrain dump is http://clj.thelastcitadel.com/clojurebot
15:59LauJensen~forget clojureql
15:59clojurebotI forgot clojureql
15:59LauJensen~clojureql is http://gitorious.org/clojureql
15:59clojurebotYou don't have to tell me twice.
15:59LauJensenFor those of you who use ClojureQL, we'd moved primarily development to Gitorious (and added a bugtracker). We will still update Github somewhat regularily
16:08devinuscan anybody point me to a few good tutorials or free books for learning clojure? the clojure.org's few pages of introduction are too high-level for me
16:09LauJensendevinus: clojure.org is mostly for reference.
16:09LauJensenGoogle search for "clojure tutorial" yields about 44k results
16:10djwhittdevinus: this is a good tutorial: http://java.ociweb.com/mark/clojure/article.html
16:11WizardofWestmarcdjwhitt's link is an excellent start
16:12WizardofWestmarcif you want a ton of useful clojure links I've got a ton that are clojure or clojure useful java stuff on my delicious feed once you get past that: http://delicious.com/wizardofwestmarch/clojure
16:13WizardofWestmarcthis is a bit out of date now I believe, but also useful: http://www.youtube.com/view_play_list?p=AC43CFB134E85266
16:13WizardofWestmarc10 youtube videos about clojure
16:16angermanis there a (zip?
16:22angermansomething like this: (defn zip [a b] (concat [(first a) (first b)] (if (or (= (rest a) '()) (= (rest b) '())) '() (zip (rest a) (rest b)))))
16:22angermanbut that's quite ugly :/
16:23Chousukehm
16:24Chousuke,(map vector [1 2 3] [1 2 3]);?
16:24clojurebot([1 1] [2 2] [3 3])
16:26WizardofWestmarcthe one downside to map is if one list is longer and you want the rest of the longer list tacked on the end it won't do it.
16:32angerman,(concat (map vector [1 2 3] [3 2 1]))
16:32clojurebot([1 3] [2 2] [3 1])
16:32angerman,(apply concat (map vector [1 2 3] [3 2 1]))
16:32clojurebot(1 3 2 2 3 1)
17:03cemerickthis is worth watching out for, if you're passing values back to java:
17:03cemerick,(and nil)
17:03clojurebotnil
17:03cemerick,(and false)
17:04clojurebotfalse
17:05WizardofWestmarcoh nice, (and nil false) gives nil back, but (and false nil) gives false back. Interesting.
17:05WizardofWestmarcwasn't sure if using them together would work that way or not.
17:07cemerickit short-circuits, and in that case, returns the first logically false value it encountered.
17:19WizardofWestmarccemerick: right I understand it, but I wouldn't have thought of that.
17:19WizardofWestmarcgood thing I rarely pass stuff to java ;-)
17:20WizardofWestmarcalthough at some point I'll probably try scala and mess with interop there.
18:02fffejI'm trying to write the "Man or Boy Test" in Clojure (just to try and understand trampoling) but it seems to be failing in bizarre ways, could someone take a look at http://clojure.pastebin.com/d25088b3 and point me in the right direction?
18:03durka42what are the bizarre ways?
18:04fffejone of the arguments (x4) becomes a function that doesn't return a number (it returns a function instead). I can't see how that can happen
18:05ChousukeI have no idea what's happening there.
18:05Chousuke:P
18:06fffejyeah, it's pretty convuluted!
18:06durka42is b supposed to return a function?
18:07fffejwell, it's used with trampoline and I think that's what I'm supposed to do?
18:08durka42well, you return #(b)
18:08durka42but b in itself, from the letfn definition, returns a closure
18:08fffejyeah, that's the idea of the man or boy test I believe
18:09dreish#(b) == b more or less. Was that intentional?
18:10durka42so it works with values less than 4
18:10dreishDid you mean (fn [] b)?
18:10fffejdurka42: yes
18:10fffejdreish: (fn [] b) is the same as #(b) isn't it?
18:10dreishNo
18:10dreishSame as (fn [] (b))
18:11dreish,'#(x)
18:11clojurebot(fn* [] (x))
18:12fffejso it's plugging into trampoline and my reading of the docs is I should wrap a closure over the tail call rather than a direct call of b. Isn't that what #(b) does?
18:14hiredmanyes
18:14dreishCan't tell what you're trying to do, but in any case, you can just replace #(b) with b.
18:14dreishIt's already a function.
18:15fffejI see what you mean - I should get rid of the # in the letfn and just have it on the tail call
18:16dreishThat also seems like a good idea.
18:16fffejbut then I get a stackoverflow, presumably because the body of b is evaluated in the letfn? (and it calls a)
18:17dreish#(b) is syntactically a little absurd, by itself.
18:17fffejyup, I see that now :)
18:17hiredmanfffej: have you tried this yet without the trampoline?
18:17dreishIt says, "Give me a function that is the same as calling b."
18:18fffejhiredman: yeah, stack trace with x=4, correct values for x=0,1,2
18:18fffej(stack overflow)
18:22dreishI think your expectations that Clojure will behave like ALGOL60 are a little ... off.
18:23fffejI was adapting a Common Lisp version
18:23dreishWhere's that?
18:23fffejand the test is about recursion and closures, so it's not Algol 60 specific :)
18:23fffejhttp://rosettacode.org/wiki/Man_or_boy_test#Common_Lisp
18:25dreish"This creates a tree of B call frames that refer to each other and to the containing A call frames, each of which has its own copy of k that changes every time the associated B is called."
18:25dreishYou don't have anything mutable, so right away it can't be right.
18:26fffejhiredman: yup - it overflows the stack
18:26fffejdreish: so k should be an atom right?
18:27dreishMaybe.
18:27fffejok, I got it now
18:29fffejwell, by got it I mean I have something that doesn't crash; now it just produces the wrong results :) Thanks for pointing me in the right direction!
18:40duck11231What's the best way to pass the name of a function, execute that function, then modify the name of the function (to refer to a different function) and then execute that one? If I pass the function un-quoted, I can't get the ns and name of the original location, and if I quote it, it's not respecting the alias in place when it was declared
18:40duck11231I tried using keywords and converting them, but that resulted in a mess
18:40hiredman:(
18:41hiredmanthat sounds pretty horrible
18:41duck11231basically, in a different namespace, I wanted to be able to do (show-html (show args))
18:41hiredmanclear as mud
18:42Chousukeyou could use resolve
18:42hiredman,(resolve (symbol "+"))
18:42clojurebot#'clojure.core/+
18:42Chousuke,((resolve '-) 1 2)
18:42clojurebot-1
18:42hiredman,((resolve (symbol "+")) 1 2)
18:42clojurebot3
18:45duck11231I was trying to use ns-resolve, because the function wasn't refered to in the executing ns, but was having problems. I was trying to be able to return something like {:action :view/show, :format :html, :args [7]} and turn that into (unaliased.ns.for.view/show-html (unaliased.ns.for.view/show 7))
18:46duck11231but maybe I need to take a different approach
18:49hiredman,((ns-resolve (create-ns 'clojure.core) (symbol "+")) 1 2)
18:49clojurebot3
18:50duck11231hiredman: thanks, I should try using create-ns
18:51hiredman,(doc create-ns)
18:51clojurebot"([sym]); Create a new namespace named by the symbol if one doesn't already exist, returns it or the already-existing namespace of the same name."
18:53hiredmanI would take a moment to think about alternatives
18:54hiredmansymbol → string → string transformation → resolution to var → function call seems like a bad idea
18:55duck11231I agree, it sounded like a good idea when I first though of it, until I looked at what was actually involved
19:12duck11231the end result turned out to be not that ugly, but it still seems like it's overly "clever"
19:48alrex021I am finding it very difficult to follow the Stack traces in Clojure, am I missing something or is there a better way to view more informative exception stack trace in clojure?
19:51Chousukealrex021: I think contrib has some functions that can clean up the stack trace a bit.
19:53alrex021Chousuke: I see, there is a trace lib in contrib
20:35alrex021I'm looking at the clojure.contrib online docs and I can't seem to require or use clojure.contrib.stacktrace.. Are the docs old and lib is not there or am I missing something?
20:40alrex021I see it seems to have been moved to clojure as this now works (use 'clojure.stacktrace)
20:41rhickeycurrent docs: http://richhickey.github.com/clojure-contrib/
20:43alrex021rhickey: thanks, I got it bookmarked now
21:11cemerickrhickey: do you have any ideas off the top of your head on how to exercise arbitrary code, so as to prime the JIT? We have some UI code that is plenty fast after about 15 seconds worth of use, but it's dang slow (at least w.r.t. user-perceptible responsiveness) before then.
21:12cemerickNon-UI code is easy to optimize (just run some sample data through it in the background at app startup), but I don't see any obvious corollary for UI code.
21:13cemerickhrm, maybe record gestures with the Robot, serialize them, and use that as sample data on an off-screen UI component...
21:16hiredman:(