#clojure logs

2010-07-18

00:31RaynesTimMc: Github is nice. Email works as well.
00:47BahmanHi all!
01:09TakeVSo, if I have a large list of data that my program is working on, and everything is kept inside that list, and multiple agents will be using it, then it would be best to use an atom, right?
01:47vishsinghIt depends. You could potentially get more concurrency in other ways if you have constraints on how the list will be modified.
01:47vishsinghe.g. if it is being used as a queue
01:50TakeVvishsingh: It's a list of hashes, each of which will probably be modified.
01:54vishsinghyou mean, each thread will modify almost every hash in its operation on the list? then, yes, it seems right to use one atom for the whole list.
01:59TakeVWell, one thread will. Everything else will just read from it.
02:09bobo_is there any simple way to make map/filter and so on use multiple cores?
02:09bobo_just out of curiosity
02:11TakeVbobo_: Isn't that was pmap does?
02:11TakeV(doc pmap)
02:11clojurebot"([f coll] [f coll & colls]); Like map, except f is applied in parallel. Semi-lazy in that the parallel computation stays ahead of the consumption, but doesn't realize the entire result unless required. Only useful for computationally intensive functions where the time of f dominates the coordination overhead."
02:11bobo_oh i did not know that
02:11bobo_awesome
02:14TakeVI don't know if there is a pfilter, though. Let's see...
02:14TakeV(doc pfilter)
02:14clojurebotPardon?
02:14TakeVYeah...
02:47holowayhi - if I have a function that I pull the arguments in to with &, and then I want to pass them directly to another function, how do I do that?
02:48holowayie: http://gist.github.com/480189
02:49vishsinghif I understand what you're asking correctly, you can use 'apply' to do that
02:49vishsingh(doc apply)
02:49clojurebot"([f args* argseq]); Applies fn f to the argument list formed by prepending args to argseq."
02:50vishsinghit basically lets you call a function with a list of parameters, rather than the parameters themselves
02:51holowaygotcha!
02:51holowaythat's exactly it
02:51holowaythank you
02:51vishsinghhappy to help
02:52holowayvishsingh: I imagine that's a fairly common idiom, if you wind up with a sequence and you want to turn it in to function arguments?
02:53vishsinghyes, that's the way you do it, in Clojure and in many other Lisps too
02:53holowaycool - I've written all of like 10 lines of clojure so far, and never touched a lisp, so I appreciate the super-newbie help :)
02:54vishsinghno prob :) clojure is a great way to get into lisp
03:36holowayhow do I set a public variable, for example the json-keyword-keys var on the clojure.contribjson.read lib?
03:38mikemholoway: you can probably wrap calls to functions which care about json-keyword-keys in a (binding ...)
03:38mikem,(doc binding)
03:38clojurebot"([bindings & body]); binding => var-symbol init-expr Creates new bindings for the (already-existing) vars, with the supplied initial values, executes the exprs in an implicit do, then re-establishes the bindings that existed before. The new bindings are made in parallel (unlike let); all init-exprs are evaluated before the vars are bound to their new values."
03:39holowaymikem: ahh, that makes sense
03:39holowayclever!
03:42holowaymikem: thank you
03:42mikemholoway: no problem :)
03:42holowayhow does anyone learn a new language without irc? :)
03:52greghtravel?
04:18mikemwhy does this happen?
04:18mikem,(do (def *tester* "test") (var-set *tester* "change"))
04:18clojurebotDENIED
04:18mikemeh...
04:18mikemat my REPL I get: CompilerException java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.Var
04:18mikemam I misunderstanding var-set?
04:19mikemif I initially have (def *tester* 14), the exception says java.lang.Integer cannot be cast
04:24hoeckmikem: var-set requires a var
04:24hoeckso either (var-set (var *tester*) 'foo) or (var-set #'tester 'foo)
04:25mikemhoeck: so should I do (var-set #'*tester* "new")
04:25mikemok
04:25mikemactually, I tried this, and got CompilerException java.lang.IllegalStateException: Can't change/establish root binding of: *tester* with set
04:25hoeckright, #'the-var returns the var-object instead of resolving the vars value
04:26hoeckmikem: yes, you can only use var-set if you rebound the var with (binding ...)
04:26hoeckto alter the root binding, use (alter-var-root #'*tester* (constantly 'foo))
04:26mikemhoeck: ah, that makes sense :)
04:27mikemgreat, alter-var-root is probably what I was looking for
07:10octewhen using slime-connect from emacs to connect to a seperate swank-process i will only get output from the main thread in the slime-repl, not the other ones
07:10octeanyone know how to get all output?
07:19msapplerhi
07:21raekmaybe one could set the root binding of *out* to swank thread's value
07:21raekhaven't tried this, though
07:21msapplerHow can I thread a form through a variable number of functions?
07:22msapplerapply -> does not work because -> is a macro
07:22raekmaybe reduce could be used
07:23raek(reduce #(apply %2 %1) val [fn1 fn2 fn3])
07:25raek,(reduce #(apply %2 [%1]) 1 [inc #(* % 2) even?])
07:25clojurebottrue
07:26msapplerhmm but my functions only have 1 argument
07:26msapplerso i need to re-write the apply somehow
07:26msapplerthe anonymous
07:27raekocte: this works: (alter-var-root #'*out* (constantly *out*))
07:27raek(future (println "hello world!"))
07:27raeknow prints in slime
07:28raekmsappler: in my second code example, the functions will always be applied with one argument
07:28raekhence the one-element vector
07:29msapplerah nice it works! thx
07:29msappleryou just wrote the '->' macro with reduce lol
07:30shachaf((reduce comp identity [f1 f2 f3]) val)
07:31raekwhoa, that was far more elegant
07:31msapplerand that will take me a few minutes to understand ;)
07:37somnium,(letfn [(p [x] (prn x) x)] ((reduce comp (interleave (repeat p) (take 10 (repeat inc)))) 42))
07:37clojurebot52
07:37clojurebot43 44 45 46 47 48 49 50 51 52
07:48shachaf,(letfn [(p [x] (prn x) x)] ((reduce comp (take 20 (cycle [p inc])) 42))
07:48clojurebotEOF while reading
07:48shachaf,(letfn [(p [x] (prn x) x)] ((reduce comp (take 20 (cycle [p inc]))) 42))
07:48clojurebot52
07:48clojurebot43 44 45 46 47 48 49 50 51 52
07:51somniumshachaf: haskell?
07:52shachafsomnium: Yep. :-)
07:53somniumshachaf: the `reduce comp ...' gave you away :)
07:54shachafsomnium: I guessed so. The #(apply %2) thing didn't even occur to me, what with being used to homogeneous lists and all.
07:57shachafsomnium: If `reduce comp ...' gave me away, what's the standard way of doing in Clojure? The #(apply ...) thing?
08:07somniumshachaf: hmm, probably #(apply ...). without currying comp seems to be used less often (?), but its common to structure fn args to work with -> and ->> threading macros for composition
08:11somnium,(letfn [(p [x] (prn x) x)] ((->> (cycle [p* inc]) (take 20) (apply comp)) 42))
08:11clojurebotjava.lang.Exception: Unable to resolve symbol: p* in this context
08:11somniumdoh
08:39BahmanHi all!
11:19bobo_is there a simple way to turn 12345 into [1 2 3 4 5]?
11:20SinDoc12345 being a number?
11:20bobo_yes
11:21SinDocyou could turn it into a string
11:23bobo_ah re-seq looks nice
11:24bobo_,(req-seq #"[1-5]" (str 12345))
11:24clojurebotjava.lang.Exception: Unable to resolve symbol: req-seq in this context
11:24bobo_,(re-seq #"[1-5]" (str 12345))
11:24clojurebot("1" "2" "3" "4" "5")
11:24Hodapptake the number modulo 10 for the last digit, then divide the number by 10 and repeat
11:28SinDocThe mod 10 solution works too but then you need a loop
11:29bobo_regexp feels faster. atleast to type
11:30mefesto,(map #(Integer/parseInt %) (map str "12345"))
11:30clojurebot(1 2 3 4 5)
11:31HodappSinDoc: well, it could be done recursively as well.
11:31bobo_oh yes, strings are seqs, didnt think of that
11:32Nikelandjelo,(map bigint (seq (str 12345)))
11:32clojurebotjava.lang.IllegalArgumentException: No matching ctor found for class java.math.BigInteger
11:33SinDoc(map #(- (int %) (int \0)) (seq (str 12345)))
11:34SinDoci came up with this
11:34SinDocHodapp: iteration is obviously better, and hey, mine ended up being iterative too
11:36SinDocthat of mefesto sounds nice too
12:15mfex,((fn [n] (map #(-> n (/ (Math/pow 10 %)) (Math/floor) (mod 10) (int)) (range (Math/floor (/ (Math/log n) (Math/log 10))) -1 -1))) 12345)
12:15clojurebot(1 2 3 4 5)
12:18eshirahi, i'm trying to use the clj-processing. I am new to the whole java classpaths business. basically, i need to: (:use [rosado.processing]), and I have a rosado.process.jar. how would i hook these two things up?
12:20mefestoeshira: what is your classpath set to?
12:20eshirain my bashrc, i wrote: export CLASSPATH=${CLASSPATH}:/Users/eshira/code/clj-processing/
12:20eshirathat folder contains the jars
12:21mefestoi think the java command needs to see *.jar in order to add the jars, otherwise it has no way to distinguish between a folder of class files and jar files
12:22mefestofor testing you could do: java -cp clojure.jar:rosado.process.jar file.clj
12:22raekjar files are treated the same as directories in the class path
12:22raeki.e. all of them have to be listed
12:23raekpotentially with an asterisk *
12:24eshirathanks, i will look into this
12:24mefestooops forgot clojure.main :)
12:24eshiraill add it
12:24mefestohttp://download-llnw.oracle.com/docs/cd/E17409_01/javase/6/docs/technotes/tools/windows/java.html
12:24mefestothe -cp flag describes what raek said
12:24eshirai should probably use something like leiningen rather than haphazardly modifyling CLASPATH
12:39slyrushrm... so I have a record, let's call it Foo, that uses a make-foo helper function and I want to call this from protocol methods. I can't have the make-foo defn before the record, and I can't have the defrecord first as its methods want to call make-foo. what am I missing?
12:40TimMcCircular dependency?
12:40opqdonut(declare make-foo)?
12:42slyrusthanks!
12:56rubydiamondHow is Programming Clojure peepcode video?
12:58eshiraso now i'm using lein, which is much better than having to mess w/ classpaths crap. but now, I want to run my app w/o having to do a "lein uberjar". In other words, I want to be able to "lein jar" and then "java -jar myapp.jar". But this means that I would need the clojure jars in my CLASSPATH, right?
12:58polypushow are protocols used from javaland?
12:58polypuseshira: yeah
12:59eshiracan i run my app w/o doing a "lein jar" then?
13:03polypuseshira: you can run it from the repl with 'lein repl', or through a swank connection, else you must have clojure on your classpath either in an uberjar or some other way.
13:08eshirainterestingly, 'lein repl' gives me: Exception in thread "main" java.lang.ClassNotFoundException: clojure.main. any ideas?
13:10rhudsonre jars and classpaths: in Java 6 you can do something like java -cp "~/.cljr/lib/*" clojure.main -- it includes all the jar files in the directory. Note that the -cp arg has to be in quotes (otherwise the shell would try to expand the *
13:11polypuseshira: you might be interested in my http://github.com/polypus74/cajual
13:11polypusor you could check out cljr on github
13:17eshirai've never gotten cljr to work. "cljr repl" produces the same error as above.
13:18eshirai probably have some other dependencies out there screwing w/ it
13:19eshirabut i think the problem could be jline, because i've alwaays had trouble w/ getting a REPL running w/ jline. I switched to a jline alternative and everythign works.
13:21rhudsoneshira: what OS? what JVM?
13:21eshiraok, fixed it w/ a super simple solution: $ rm /Library/Java/Extensions
13:22eshirai mean: rm /Library/Java/Extensions/jline.jar
13:22rhudsonah, that sounds a likely culprit
13:22eshirai am on OS X 10.6
13:23polypuseshira, cajual mentioned above keeps jline up to date with a simple lein deps
13:23slyruswhat is the properly idiomatic way to do (drop 1 [1 2 3]) and get [2 3] instead of (2 3)?
13:23polypusworks for me on 10.6
13:25slyrusor, put another way, why doesn't (rest [1 2 3]) return [2 3]?
13:26polypusslyrus: because it is a sequence function, not a vector manipulation function
13:27slyrusok... but why not return a sequence of the same type as what was passed in? why default to a list?
13:27slyruspresumably it's because things like dropping the first item of a vector are pretty expensive
13:28polypusslyrus: it's not a list
13:28polypus,(class (drop 1 [1 2 3]))
13:28clojurebotclojure.lang.LazySeq
13:30polypusif you want a vec you can (vec (drop ...)) or use subvec. sequnce functions deal with sequence abstractions, and you shouldn't care what the return type is. only that the return value behaves like a sequence
13:30slyrusfair enough
13:35eshirapolypus, thanks. i'l check it out
13:36polypuseshira: np
13:36raekvectors are not sequences
13:37raekvectors and lists are collections, and sequences are sequential views of collections
13:38polypusor even abstact sequence with no underlying collection (repeat :foo)
13:42raekalthough, when treated as collections (e.g. when using conj), sequences behave as if they were lists
13:43polypusand lists are sequences as ell as collections
13:43polypus,(seq? '(1 2 3))
13:43clojurebottrue
13:43polypuswell*
13:47raekI really like how clojure makes all these different data structures and the traditional cons cells work so beatifully together...
13:48polypusi have a java object f, which has an invoke method. if i write (.invoke f 5) it works. but if i write ((memfn invoke) f 5) i get a wrong number of args passed error. the invoke method is variable arity, could that be causing the error?
13:49raekhrm, I dont't know.... but I do know that #(.invoke %1 %2) is preferred now
13:49raek...voer memfn
13:49raek*over
13:49raekhrm, "voer" looks dutch :)
13:50SinDocraek: inderdaad ;)
13:50xcthulhuraek, I'm new to clojure but I've been hacking on haskell and clisp for a few years. Any gotchas I should watch out for when I'm doing stuff like (map vector (iterate inc 1) coll)?
13:52polypusraek: problem is i need to (apply (memfn invoke) args)
13:54raekpolypus: why not make the class inhertir from AFn and use it as a function?
13:55polypusraek: i don't have access to the class. in fact it's dynamically generated. it's a javafx anonymous function
13:56raekxcthulhu: that code looks fine if you want [index value] pairs
13:56raekit's identical to "indexed" in http://media.pragprog.com/titles/shcloj/flow.pdf
13:57Chousukexcthulhu: are you using 1.2?
13:57raekhrm
13:57raekpolypus: tricky
13:57Chousukexcthulhu: it has a map-indexed IIRC
13:58xcthulhu1.0
13:58xcthulhuI'm gonna be lame here, but is there something like Haskell's "zip" for clojure?
13:58xcthulhu(not zippers)
13:59polypuszipmap? i don't know haskell
13:59raekwhat does Haskell's zip do? I haven't gotten into Haskell yet...
13:59raek(I have a strong feeling that I will one day)
13:59rhudsonxcthulhu: (map vector a b) is Clojure's equivalent
14:00xcthulhu(zip [1 2 3] ["A" "B" "C]) would return ([1 "A"] [2 "B"] [3 "C"])
14:00xcthulhurhudson: awesome. Thanks
14:00raek(zipmap [:a :b :c] [1 2 3]) => {:a 1, :b 2, :c 3)
14:01polypuszipmap does same but returns a map
14:01polypusjinx
14:02raekzipmap is wonderful to have when implementing a lisp
14:02rhudsonxthulhu: As a rule of thumb, most things that produce a sequence produce a lazy sequence, and mostly nothing else is lazy
14:02raek(let [new-env (extend-env env (zipmap formal-params actual-params))] ...)
14:06LauJensenGood evening all
14:07xcthulhuraek, I'm trying to teach myself clojure by writing something that solves http://www.dourish.com/goodies/aptitude-test.html
14:08raekheh
14:08xcthulhuraek, The first question is about the index of the first question with "B" as an answer. zipmap would be nice but I really want to call "find-first" here
14:08raekpolypus: maybe you could to a macro that expands into (.invoke f foo bar ...)
14:09xcthulhuYou can't use find-first with a map, right?
14:09raekthat problem should be fairly straight forward to solve with the non-deterministic interpreter from SICP
14:10raekfind-first?
14:10xcthulhuraek, It's in clojure.contrib.seq
14:10raekyou could use "some"
14:10raekah
14:10raeka sequence would be made for the map
14:10raek,(seq {:a 1, :b 2, :c 3})
14:10clojurebot([:a 1] [:b 2] [:c 3])
14:11polypusraek: memfn is implemented like this `(fn [target# ~@args]
14:11polypus (. target# (~name ~@args))))
14:12polypusi don't think there is a way of doing it w/o dropping into javaland
14:12raekwhat error did you get again?
14:13polypuswrong number of args. i think it's because the invoke method of the javafx functions is variable arity
14:13xcthulhuraek, Thanks a bunch. I'll rewrite some of this...
14:13lpetit,(re-seq #"[0-9]*(?!\.)" "10")
14:13clojurebot("10" "")
14:13lpetit,(re-seq #"[0-9]*(?!\.)" "10.0")
14:13clojurebot("1" "" "0" "")
14:14raekis #"(?!foo)" some special re syntax?
14:14qbgYes
14:15lpetitHello, do you know a way, with regexps, to discard the "whole" match if we encounter a character (here the dot char) while matching. e.g. I want ,(re-seq #"[0-9]*(?!\.)" "10.0") to return ("0" "") and not > ("1" "" "0" "")
14:15lpetit(when I say ("0" "") I'm talking about the 2d "0", not the first
14:16lpetitraek: (?!f) means "negative lookahead for char \f"
14:16lpetitraek: zero-width negative lookahead, that is
14:17lpetitis there a possibility to have the desired behaviour via the use of greedy ... operators ?
14:18raekit matches the first 1 since it's not followed by a period
14:20raek(re-seq #"[0-9]*(?!\.|[0-9])" "10.0")
14:20raek,(re-seq #"[0-9]*(?!\.|[0-9])" "10.0")
14:20clojurebot("0" "")
14:20slyruswhat's the equivalent of CL's find? that is (cl-find item seq) returns item if it's in seq, nil otherwise? (some #(when (= % obj) %) seq) ?
14:20raekadded criterium: the matched digits should not have any following digits
14:20qbg,(some #{3} [1 2 3 4 5 6])
14:20clojurebot3
14:21slyrusok, thanks qbg
14:24raeklpetit: did #"[0-9]*(?!\.|[0-9])" solve the problem?
14:24lpetitwas gone
14:25lpetit,(re-seq #"[0-9]*(?!\.|[0-9])" "1000.0")
14:25clojurebot("0" "")
14:25lpetit,(re-seq #"[1-9](?!\.)[0-9]*(?!\.|[0-9])" "1110.0")
14:25clojurebotnil
14:26lpetit,(re-seq #"[0-9]*(?!\.|[0-9])" "110000")
14:26clojurebot("110000" "")
14:26lpetitraek: seems so
14:26lpetitthx
14:32raekbtw, does someone recommend any atricles/blog posts/books on Clojure program design/architecture?
14:33raekProgramming Clojure touches on this a bit when suggesting that one could divide the program into a purely functional part and one mutation part
14:34slyrushere's an improved version of my undirected graph implementation. now with bfs and dfs: http://gist.github.com/479786
14:34raekthese slides (from a different background) suggests something similar: http://www.st.cs.uni-sb.de/edu/seminare/2005/advanced-fp/docs/sweeny.pdf
14:35raeksome algorithms are better of being purely functional
14:35raekand the mutation part benefits from a STM
14:35slyrusis my use of lazy-seq correct in the {breadth,depth}-first-traversal functions?
14:38raeka lazy-seq often looks like something like this:
14:38raek(defn lazy-something []
14:38raek (if more-elements?
14:38raekno wait
14:39raekhttp://clojure.org/lazy
14:39raekthe second to last example is a pretty good example
14:41raekslyrus: here is an example I made for experementing with lazy sequences: http://gist.github.com/480608
14:42raekit can be useful for getting the feel for when items in the lazy sequence are realized
14:43slyrusok, I think I've got all that, but can/should I just drop a lazy-seq call in before recurring (not using recur, per se) as I did in the traversal routines?
14:43raek(lazy-seq (if there-is-more-elements (cons one element (call-to-make-rest ...))))
14:43slyrusis there a penalty for sprinkling in excess lazy-seq calls?
14:44raekIMHO, you shold not have to worry about the performance of making it lazy
14:44slyrusah, but perhaps I should move the lazy-seq call outside of the (if (seq queue)
14:45raekthe body of lazy-seq should result in a sequence
14:45raekof which a part most often is a call to make the rest
14:46raekslyrus: yes, then the check for whether is's empty or not is lazy too :)
14:47raekvery often, you can make a sequence making function lazy by just wrapping everything in a lazy-seq
14:47raek(and also changing (recur) forms into normal function calls)
14:50raekhrm, I don't think your function in it's current form is lazy at the moment
14:50raektry to add a prinln to trace when it's realized
14:50lpetit,(re-seq #"[0-9]*(?!\.|[0-9])" "12.3")
14:50clojurebot("3" "")
14:50lpetit,(re-seq #"[0-9]*(?!\.|[0-9])" "12.3")
14:50clojurebot("3" "")
14:51chouserdoes anyone know off the top of their head an enlive selector for matching a tag with a specific title attr?
14:52chouserI see examples for class and id attrs, but not title.
14:53raekslyrus: I would do it something like this: http://gist.github.com/480615
14:53raek(warning: not tested)
14:54LauJensenchouser: You just need to check if the title tag matches some predicate?
14:55chouserequal to a value, yes.
14:55raekslyrus: also, there is a clojure.lang.PersistentQueue class (which is fairly unknown)
14:55LauJensen(select node (has [[:title (pred #(= "something" (text %)))]]))
14:55LauJensenI think that should get you there
14:57raekslyrus: it supports conj, peek and pop
15:02slyrushmm... yeah, I wrote the equivalent of that for the original impls in common lisp. it would be nice if the queue class were exposed with clojure primitives
15:03raek,Q
15:03clojurebotjava.lang.Exception: Unable to resolve symbol: Q in this context
15:03raeknaw, where did the fish-queue-syntax go?
15:04raekwho did the fish-queue pprint fork? replaca?
15:05raekhttp://clojure-log.n01se.net/date/2010-05-12.html#12:55
15:05slyrusthanks raek, that's nicer
15:14slyrusraek: http://gist.github.com/479786 seems to be properly lazified now. thanks again!
15:15polypusraek: check it http://gist.github.com/480630
15:15slyrusgists are pretty nice, btw
15:15polypusagreed
15:16chouserLauJensen: isn't :title for a <titile> tag?
15:16chouserI want the title attribute, like <a title="indexme">...</a>
15:17LauJensenchouser: ah, (select node [[:a (has ...)]]) with the code above inserted
15:17chouser'has' is for attributes?
15:17LauJensenno wait, thats actually for nested tags Im thinking
15:17LauJensenlemme check the docs
15:18LauJensenchouser you need attr? or attr= depending on wether you are checking for existance or content
15:18chouser'attr?' is for the existence of an attribute but seems to ignore the contents
15:18chouseroh!
15:18LauJensenhttp://enlive.cgrand.net/syntax.html
15:18chouserah, attr= looks right. thanks!
15:23duck1123Does anyone know of any ring middleware that will force params such as ?foo[]=7 to always appear in a vector? (ie. {:params {"foo[]" ["7"]}} )
15:23duck1123or perhaps a better way to do what I'm doing?
15:28LauJensenduck1123: I dont know one off the top of my head, but it should be trivial to write your own
15:29duck1123I figured it would be, except it turns out the keys I was trying to modify aren't available where I was placing my middleware. Looking through compojure source now
15:30slyrusis there a zero-arg iterate like function?
15:30slyrussurely there's a better way than: (drop 1 (take 10 (iterate (fn [_] (rand-int 300)) nil)))
15:30LauJensenslyrus: repeatedly
15:31slyrusthanks LauJensen!
15:53bleakgadflyHey
15:55bleakgadflyI am trying to do a "lein jar" on clj-plaza (http://github.com/antoniogarrote/clj-plaza and get this: http://gist.github.com/480006
15:55bleakgadflyAs you can see in the link, if I do it in Compojure I get the jar file I want
15:55chouser have a lot of trouble understanding the enlive docs
15:55chouserI have
15:56bleakgadflyCould anyone tell me after reading the java output if the error is in Clojure, leiningen or in the library?
15:57chouserbleakgadfly: leiningen is passing a nil to Clojure's name fn, which then throws.
15:57chouser,(name nil)
15:57clojurebotjava.lang.NullPointerException
15:57bleakgadflyHmm
15:57chouserit's not clear to me where that nil is coming from -- perhaps the lein config file?
16:00bleakgadflyOkay
16:00bleakgadflyThanks
16:05technomancywho's ready for a Leiningen release?
16:07LauJensentechnomancy: adding more cenjureship? :)
16:07technomancyLauJensen: why, do you have a suggestion? =)
16:07LauJensen"Ver 1.2: Now forbidding all names that rhyme, all camelcased names, all names inspired from contemporary music"
16:07clojurebotamespaces are (more or less, Chouser) java packages. they look like foo.bar; and corresponde to a directory foo/ containg a file bar.clj in your classpath. the namespace declaration in bar.clj would like like (ns foo.bar). Do not try to use single segment namespaces. a single segment namespace is a namespace without a period in it
16:07chousera sugjesjion.
16:08technomancy"Now you must name all your projects using names from literature, so START READING, you philistines."
16:08LauJensenAwesome :)
16:09holowaytechnomancy: leiningen is very cool
16:09technomancyholoway: thanks.
16:09holowaytechnomancy: kind of delightful, honestly
16:09LauJensenYea dont get me wrong phil, its good stuff :)
16:11technomancyLauJensen: of course; all in good fun. =)
16:29slyrusso, parallel to the MyNiftyDatatype class and MyNiftyDatatypeI interface from javaland, what should one do when confronted with the urge to name both a protocol and a record the same thing?
16:35jneirahi people
16:36jneiraanother clojure novice looking for a better version of his poor implementation ;-)
16:37Chousukeslyrus: does the same name really describe a set of data AND a set of operations?
16:37jneirathis time for a function (in-range? [[0 0 0][0 0 0]] [0 2]) -> true
16:38jneira (in-range? [[0 0 0][0 0 0]] [1 3]) --> false
16:38slyrusChousuke: yeah, i dunno... i started off with protocol Edge and record UndirectedEdge. I don't think that's right.
16:38slyrusi'm needing new names as I think about protocols and records for things like directed graphs and edges.
16:38Chousukeslyrus: "Edge" doesn't sound like it's a protocol
16:39slyrusnext you're going to tell me that Graph doesn't either :)
16:39Chousukewell, hmm
16:39slyrusnot that you'll be wrong...
16:40Chousukewhat you want to name is the set of operations you can perform on graph-like things
16:40slyrusChousuke: http://gist.github.com/479786 is what I'm working on
16:40slyrusyeah, that's what I'm starting to realize
16:41Chousukeyou might call them GraphOps or something like that
16:41jneiramy take of in-range? http://gist.github.com/480694
16:49slyrusChousuke: well, it's maybe not quite there yet, but having NodeSet and EdgeSet protocols cleaned things up a bit. Now an UndirectedGraph implements (?) NodeSet and EdgeSet while UndirectedEdge only implements NodeSet.
16:50slyrusmakes it easier to see how, say, DirectedGraph and DirectedEdge can fit in.
16:53lpetitraek: seems like using a possessive quantifier also solves the problem:
16:53lpetit,(re-seq #"[0-9]*+(?!\.)" "10.0")
16:53clojurebot("0" "")
16:53lpetit,(re-seq #"[0-9]*+(?!\.)" "10")
16:53clojurebot("10" "")
17:02raeka typographical question about Joy of Clojure: Aren't the footnotes supposed to be at the bottom of the page?
17:02clojurebotyou mean clojure.main
17:04raekclojurebot: here, have some bot snack
17:04clojurebotbotfight is http://raek.se/botfight.html
17:04raekwhoa! luckily I deleted that page
17:05raekthe title contained an instruction for sexpbot
17:06raekno wait, sexpbot printed the title, which was a comman to clojurebot, which in turn outputed the url again
17:06raek=> infinite loop
17:08slyruswhy do folks seem to use one name space per file? seems that if I'm working on a bunch of files in a project they might just share one namespace (at least that's what I usually do with CL packages). the clojure convention seems a bit different.
17:08chouserraek: fluke of the MEAP/PDF tool. Presumably the footnotes will actually be at the foot of the page in the final book.
17:09chouserthough actually, most of the footnotes will be gone I suspect.
17:10chouserbrb
17:12raekchouser: also, in the section illustrating the character syntax: "\u30DE ; The unicode katakana character „Éû}"
17:12chouserhm. unfortunate.
17:13raeklooks like a double encoding issue to me
17:14technomancyslyrus: yes, one-namespace-per-file simplifies a lot of things in Clojure
17:15slyrustechnomancy: how so?
17:16technomancyslyrus: well, there's less jumping around needed; you can see everything right in front of you
17:18slyrusi suppose if you like big files, sure. the question isn't can everything in a namespace live in one file, it's why do people use multiple namespaces for related files instead of just sharing one namespace? there's no right/wrong answer here, just style conventions and the clojure way seems opposite from what I'm used to.
17:19chouserI guess it's not surprising that zip-filter/xml is more suited to my specific needs than enlive is.
17:19raekslyrus: you can still divide the code in multiple files
17:19raekthe user might only need to use one of the files/namespaces
17:20raekthe others can be for splitting up the implementation of the "main" namespace
17:20technomancyit forces you to think about the relationship between the functions
17:21technomancysince all sharing between namespaces is explicit
17:22chouserwhich is likely desirable between truly separate modules, and undesirable within things that are actually interdependent.
17:28lpetitmaybe the little "hidden" secret is that if one-namespace-per-file where the norm (one rule to rule them all :) ), then it would simplify tooling
17:28lpetits/where/were/g
17:28sexpbotlpetit: Format is sed [-<user name>] s/<regexp>/<replacement>/ Try $help sed
17:28lpetits/where/were/
17:28sexpbots/were/were/g
17:28lpetitgargl
17:31technomancylpetit: yes, I must confess that's part of what appeals to me. =)
17:31lpetittechnomancy: ahah, I was sure about that one :-)
17:32technomancybreaking one-namespace-per-file also forces you to use load-file instead of use/require, which is icky
17:35chouserso nobody else using enlive has needed something to extract all the textual content from a node?
17:41bortrebIf I make a mistake when uploading a jar to clojars, then is there any way to reverse it?
17:50lpetittechnomancy: congrats for Lein 1.2 !
17:57rhudsonThere's :syms too, but I've never used anything but :keys
17:59raekthe version of compojure I have been using (pre 0.4) passed http headers as maps with string keys
18:00raekI think the most common usage scenario would be when one gets map-like data from another data format
18:00raeke.g. Json
18:01xcthulhuIs there a prime? function for clojure?
18:06rhudsonxcthulhu: not to my knowledge. There's clojure.contrib.lazy-seqs/primes, which as you might guess is a lazy sequence of the primes.
18:09xcthulhurhudson, The SICP book presents Fermat's probabilistic algorithm but it's not in a library:
18:09xcthulhuhttp://sicpinclojure.com/?q=sicp/1-2-6-example-testing-primality
18:10rhudsonRight, you could use the 'primes seq as test divisors for up to (sqrt n)
18:11raekis autopromotion still in 1.2?
18:14rhudsonInteresting about the Fermat test; hadn't heard of that
18:17xcthulhurhudson, it's not perfect; there's lots of refinements
18:17xcthulhuFor instance: http://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test
19:04bortrebthis looks like a good implementation of various primality tests http://code.google.com/p/clj-primetest/
19:05bortrebthe clj stands for , of course, "command line java"
19:22RaynesWoot! Leiningen 1.2.0!
19:26xcthulhubortreb, Well... I ended up implementing the brute force algorithm myself.
19:27erikcw1Is there a function that will loop through a seqence and return the first non-False item it finds (without evaluating the rest of the items in the list)? I tried (first (filter ...)) but it evaluates each item in the seq before returning thing first true item. It is an expensive operation, so I wan to avoid that...
19:29xcthulhuTo be honest, I know that the numbers I am checking are bounded above by 20, so my efficiency concerns are a bit silly...
19:34xcthulhuAn issue with this library is that it restricts itself to machine precision, which I will admit is fine in practice, but the mathematician in me would prefer an algorithm that supports BigIntegers
19:43xcthulhuerikcw1, Sorry, I missed your post
19:44erikcw1np
19:44xcthulhufind-first in clojure.contrib.seq is what you want
19:44erikcw1Just found that
19:44xcthulhu:(
19:44erikcw1looks like chunking of lazy seqs is a problem though
19:44erikcw1I only have about 8 items in the seq
19:44Raynes-> (some identity [nil false 1 nil false])
19:44sexpbot=> 1
19:45erikcw1so they all get pulled
19:45konrGuys, I'm using clojure again, yet for some reason swank-clojure-project is failing to load (http://bf416618019831fa.paste.se/) - I have clojure-1.2, clojure-contrib-1.2 and swank-clojure-1.1 on my src/ lib: do I need anything else? Do you know what might be happening?
19:46Rayneserikcw1: (some identity ...) works.
19:48erikcw1Raynes: thanks -- not really sure how that works. I'll have to dig into the source. I haven't used identity before
19:49xcthulhu, (identity 5)
19:49clojurebot5
19:49xcthulhu, (identity "Hello")
19:49clojurebot"Hello"
19:50xcthulhuIn Haskell it's called id
19:50tomojkonr: are you not using leiningen?
19:50erikcw1xcthulhu: Where would I put my predicated in this example?
19:51konrtomoj: I am. Perhaps clojure-1.1 is required, let me see...
19:51tomoj clojure 1.1 is not required
19:51xcthulhu, (some odd? [2,4,6,8,7,9,9,10,11])
19:51clojurebottrue
19:51tomojkonr: paste you project.clj
19:53tomojdoes clojure play nice with gcj?
19:53chousergnu classpath doesn't implement all the classes clojure.core uses
19:53tomojkonr: that could be your problem?
19:54xcthulhuerikcw1, Hmm... I'm not sure.
19:54konrtomoj: not really, the error changed, but I still got an error, haha... let me paste the file
19:54xcthulhuerikcw1, this is kind of ugly, but what about:
19:55xcthulhu, (some identity (map #(and (even? %) %) [1,3,5,7,11,12,14,16])
19:55clojurebotEOF while reading
19:55xcthulhu, (some identity (map #(and (even? %) %) [1,3,5,7,11,12,14,16]))
19:55clojurebot12
19:56xcthulhuerikcw1, I think that has the semantics you want...
19:56xcthulhuthrow in pred for even? and coll for [1,3,...]
19:57erikcw1, (some identity (map #(do (print \.) (and (even? %) %)) [1,3,5,7,11,12,14,16]))
19:57clojurebot12
19:57clojurebot........
19:58erikcw1xcthulhu: seems like it looses its de-chunkified lazyiness
19:59xcthulhuhmm
20:01konrtomoj: http://884e867afd61073a.paste.se/ - apparently slime keeps polling and *inferior-lisp* contains http://c8096c7945723343.paste.se
20:01chousermap will do chunks on a vector
20:01chouser'some' will pull individual cons cells from that
20:03tomojkonr: http://94e90f3e196645be.paste.se/ try that
20:03tomojbut if what chouser says is true, I think you will need to get sun or openjdk and switch
20:04tomojkonr: and do `lein clean` and `lein deps` before trying `lein swank` again
20:07konrhmmm, lein couldn't find the files and suggested me to download them manually
20:07tomojerr
20:09tomojI screwed up
20:10tomojkonr: http://66a7040ca1ad624f.paste.se/
20:24konrtomoj: strange, now I got another kind of error: http://2dd5ecc0568d2d09.paste.se/
20:36tomojkonr: again, you need to switch to sun or openjdk
20:53thunkIt seems the new version of "lein repl" doesn't accept arguments. How do I replicate "lein repl src/project/core.clj" without loading the file manually??
21:07chouseryeah
21:08slyrusor maybe #[(last %) (count %)]
21:08slyrusnah, that's crazy talk
21:09slyrusyeah, bfs and dfs traversal with and without paths (--> lengths). i should be able to go back to representing molecules instead of arbitrary graphs now.
21:10konrtomoj: that was the problem in the end! Thanks! :)
21:35cais2002morning
21:46slyrusi want a take-while that includes the first failing item, or something like a (take-until ...) that takes items up to and including the first true item
21:51rhudsonslyrus: you can use split-with
21:58pdkcan regular clojure (a b c) type lists be serialized in a standardized way that preserves nested lists
22:01konrDo you know where I might find non-trivial examples of QT in Clojure? It seems that I'll have to use proxy on IFn to connect functions to the interfaces, and some examples of that would be nice
22:03slyrusmy graph library is no longer (or soon will not be) just for undirected graphs. I guess I can't use ugraph any more... darn. need a name then.
22:03pdkthe everyman's graph!
22:04slyrushuh?
22:04pdkit's a catchy name no
22:05slyrusno
22:50slyruswhen does the "WARNING: spit already refers to..." warning go away?
22:58slyrushow about shortcut for the name of my graph library?
23:01slyrusok, so now I've got two "projects", one my graph library, one my chemistry library. everything was all well and good when they were in one project. now how do I hack on both at the same time without having to do lein jar; lein install; cd ... ; lein deps ; lein swank ; (reload all my clojure stuff) ... every few minutes?
23:02Raynes-> (partition 2 [1 2 3 4 5])
23:02sexpbot=> ((1 2) (3 4))
23:02RaynesIs wish it would do something meaningful with the last odd numbered element. :\
23:12chouser-> (parition-all 2 [1 2 3 4 5])
23:12sexpbotjava.lang.Exception: Unable to resolve symbol: parition-all in this context
23:13chouser-> (parition 2 2 [1 2 3 4 5] [0 0])
23:13sexpbotjava.lang.Exception: Unable to resolve symbol: parition in this context
23:13chouser-> (partition 2 2 [1 2 3 4 5] [0 0])
23:13sexpbot=> ((0 0))
23:13chouser-> (partition 2 2 [0 0] [1 2 3 4 5])
23:13sexpbot=> ((1 2) (3 4) (5 0))
23:14chouser-> (partition-all 2 [1 2 3 4 5])
23:14sexpbot=> ((1 2) (3 4) (5))
23:14chouserthere you go. sorry for the noise.
23:14Rayneschouser: You're my hero.
23:22technomancyslyrus: you can use checkout dependencies for the situation youv'e described
23:23technomancyslyrus: put a symlink from the dependency into the "checkouts" directory in the other project and it will be put on the classpath
23:23technomancyno need for the lein install/lein deps dance
23:24technomancyit's mentioned in the faq in the readme
23:30slyrusoh, ok. thanks technomancy!
23:32slyrustechnomancy: what does "symlink some other projects into it" mean?
23:33slyrusother projects.clj or their enclosing directories?
23:33slyrusmy-project.lng, or similar, would have made more since, IYAM, which you didn't :)
23:36drewrslyrus: C-h f toggle-uniquify-buffer-names RET
23:37slyrusbah... i still hate having multiple files with the same name. but, then again, it's probably just because i'm used to my-project.asd files
23:43BahmanHi all!
23:48cais2002hi Bahman
23:48BahmanHi cais2002!