#clojure log - Jul 18 2010

The Joy of Clojure
Main Clojure site
Google Group
List of all logged dates

0:31 Raynes: TimMc: Github is nice. Email works as well.

0:47 Bahman: Hi all!

1:09 TakeV: So, 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?

1:47 vishsingh: It depends. You could potentially get more concurrency in other ways if you have constraints on how the list will be modified.

1:47 e.g. if it is being used as a queue

1:50 TakeV: vishsingh: It's a list of hashes, each of which will probably be modified.

1:54 vishsingh: you 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.

1:59 TakeV: Well, one thread will. Everything else will just read from it.

2:09 bobo_: is there any simple way to make map/filter and so on use multiple cores?

2:09 just out of curiosity

2:11 TakeV: bobo_: Isn't that was pmap does?

2:11 (doc pmap)

2:11 clojurebot: "([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."

2:11 bobo_: oh i did not know that

2:11 awesome

2:14 TakeV: I don't know if there is a pfilter, though. Let's see...

2:14 (doc pfilter)

2:14 clojurebot: Pardon?

2:14 TakeV: Yeah...

2:47 holoway: hi - 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?

2:48 ie: http://gist.github.com/480189

2:49 vishsingh: if I understand what you're asking correctly, you can use 'apply' to do that

2:49 (doc apply)

2:49 clojurebot: "([f args* argseq]); Applies fn f to the argument list formed by prepending args to argseq."

2:50 vishsingh: it basically lets you call a function with a list of parameters, rather than the parameters themselves

2:51 holoway: gotcha!

2:51 that's exactly it

2:51 thank you

2:51 vishsingh: happy to help

2:52 holoway: vishsingh: 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?

2:53 vishsingh: yes, that's the way you do it, in Clojure and in many other Lisps too

2:53 holoway: cool - I've written all of like 10 lines of clojure so far, and never touched a lisp, so I appreciate the super-newbie help :)

2:54 vishsingh: no prob :) clojure is a great way to get into lisp

3:36 holoway: how do I set a public variable, for example the json-keyword-keys var on the clojure.contribjson.read lib?

3:38 mikem: holoway: you can probably wrap calls to functions which care about json-keyword-keys in a (binding ...)

3:38 ,(doc binding)

3:38 clojurebot: "([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."

3:39 holoway: mikem: ahh, that makes sense

3:39 clever!

3:42 mikem: thank you

3:42 mikem: holoway: no problem :)

3:42 holoway: how does anyone learn a new language without irc? :)

3:52 gregh: travel?

4:18 mikem: why does this happen?

4:18 ,(do (def *tester* "test") (var-set *tester* "change"))

4:18 clojurebot: DENIED

4:18 mikem: eh...

4:18 at my REPL I get: CompilerException java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.Var

4:18 am I misunderstanding var-set?

4:19 if I initially have (def *tester* 14), the exception says java.lang.Integer cannot be cast

4:24 hoeck: mikem: var-set requires a var

4:24 so either (var-set (var *tester*) 'foo) or (var-set #'tester 'foo)

4:25 mikem: hoeck: so should I do (var-set #'*tester* "new")

4:25 ok

4:25 actually, I tried this, and got CompilerException java.lang.IllegalStateException: Can't change/establish root binding of: *tester* with set

4:25 hoeck: right, #'the-var returns the var-object instead of resolving the vars value

4:26 mikem: yes, you can only use var-set if you rebound the var with (binding ...)

4:26 to alter the root binding, use (alter-var-root #'*tester* (constantly 'foo))

4:26 mikem: hoeck: ah, that makes sense :)

4:27 great, alter-var-root is probably what I was looking for

7:10 octe: when 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

7:10 anyone know how to get all output?

7:19 msappler: hi

7:21 raek: maybe one could set the root binding of *out* to swank thread's value

7:21 haven't tried this, though

7:21 msappler: How can I thread a form through a variable number of functions?

7:22 apply -> does not work because -> is a macro

7:22 raek: maybe reduce could be used

7:23 (reduce #(apply %2 %1) val [fn1 fn2 fn3])

7:25 ,(reduce #(apply %2 [%1]) 1 [inc #(* % 2) even?])

7:25 clojurebot: true

7:26 msappler: hmm but my functions only have 1 argument

7:26 so i need to re-write the apply somehow

7:26 the anonymous

7:27 raek: octe: this works: (alter-var-root #'*out* (constantly *out*))

7:27 (future (println "hello world!"))

7:27 now prints in slime

7:28 msappler: in my second code example, the functions will always be applied with one argument

7:28 hence the one-element vector

7:29 msappler: ah nice it works! thx

7:29 you just wrote the '->' macro with reduce lol

7:30 shachaf: ((reduce comp identity [f1 f2 f3]) val)

7:31 raek: whoa, that was far more elegant

7:31 msappler: and that will take me a few minutes to understand ;)

7:37 somnium: ,(letfn [(p [x] (prn x) x)] ((reduce comp (interleave (repeat p) (take 10 (repeat inc)))) 42))

7:37 clojurebot: 52

7:37 43 44 45 46 47 48 49 50 51 52

7:48 shachaf: ,(letfn [(p [x] (prn x) x)] ((reduce comp (take 20 (cycle [p inc])) 42))

7:48 clojurebot: EOF while reading

7:48 shachaf: ,(letfn [(p [x] (prn x) x)] ((reduce comp (take 20 (cycle [p inc]))) 42))

7:48 clojurebot: 52

7:48 43 44 45 46 47 48 49 50 51 52

7:49 * shachaf is not used to the parentheses. :-)

7:51 somnium: shachaf: haskell?

7:52 shachaf: somnium: Yep. :-)

7:53 somnium: shachaf: the `reduce comp ...' gave you away :)

7:54 shachaf: somnium: I guessed so. The #(apply %2) thing didn't even occur to me, what with being used to homogeneous lists and all.

7:57 somnium: If `reduce comp ...' gave me away, what's the standard way of doing in Clojure? The #(apply ...) thing?

8:07 somnium: shachaf: 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

8:11 ,(letfn [(p [x] (prn x) x)] ((->> (cycle [p* inc]) (take 20) (apply comp)) 42))

8:11 clojurebot: java.lang.Exception: Unable to resolve symbol: p* in this context

8:11 somnium: doh

8:39 Bahman: Hi all!

11:19 bobo_: is there a simple way to turn 12345 into [1 2 3 4 5]?

11:20 SinDoc: 12345 being a number?

11:20 bobo_: yes

11:21 SinDoc: you could turn it into a string

11:23 bobo_: ah re-seq looks nice

11:24 ,(req-seq #"[1-5]" (str 12345))

11:24 clojurebot: java.lang.Exception: Unable to resolve symbol: req-seq in this context

11:24 bobo_: ,(re-seq #"[1-5]" (str 12345))

11:24 clojurebot: ("1" "2" "3" "4" "5")

11:24 Hodapp: take the number modulo 10 for the last digit, then divide the number by 10 and repeat

11:24 * Hodapp runs

11:28 SinDoc: The mod 10 solution works too but then you need a loop

11:29 bobo_: regexp feels faster. atleast to type

11:30 mefesto: ,(map #(Integer/parseInt %) (map str "12345"))

11:30 clojurebot: (1 2 3 4 5)

11:31 Hodapp: SinDoc: well, it could be done recursively as well.

11:31 bobo_: oh yes, strings are seqs, didnt think of that

11:32 Nikelandjelo: ,(map bigint (seq (str 12345)))

11:32 clojurebot: java.lang.IllegalArgumentException: No matching ctor found for class java.math.BigInteger

11:33 SinDoc: (map #(- (int %) (int \0)) (seq (str 12345)))

11:34 i came up with this

11:34 Hodapp: iteration is obviously better, and hey, mine ended up being iterative too

11:36 that of mefesto sounds nice too

12:15 mfex: ,((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:15 clojurebot: (1 2 3 4 5)

12:18 eshira: hi, 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:20 mefesto: eshira: what is your classpath set to?

12:20 eshira: in my bashrc, i wrote: export CLASSPATH=${CLASSPATH}:/Users/eshira/code/clj-processing/

12:20 that folder contains the jars

12:21 mefesto: i 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:22 for testing you could do: java -cp clojure.jar:rosado.process.jar file.clj

12:22 raek: jar files are treated the same as directories in the class path

12:22 i.e. all of them have to be listed

12:23 potentially with an asterisk *

12:24 eshira: thanks, i will look into this

12:24 mefesto: oops forgot clojure.main :)

12:24 eshira: ill add it

12:24 mefesto: http://download-llnw.oracle.com/docs/cd/E17409_01/javase/6/docs/technotes/tools/windows/java.html

12:24 the -cp flag describes what raek said

12:24 eshira: i should probably use something like leiningen rather than haphazardly modifyling CLASPATH

12:35 * slyrus liked it back in the good old days when you could change the classpath in a running clojure instance

12:36 * slyrus has learned to live with lein swank

12:39 slyrus: hrm... 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:40 TimMc: Circular dependency?

12:40 opqdonut: (declare make-foo)?

12:42 slyrus: thanks!

12:56 rubydiamond: How is Programming Clojure peepcode video?

12:58 eshira: so 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:58 polypus: how are protocols used from javaland?

12:58 eshira: yeah

12:59 eshira: can i run my app w/o doing a "lein jar" then?

13:03 polypus: eshira: 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:08 eshira: interestingly, 'lein repl' gives me: Exception in thread "main" java.lang.ClassNotFoundException: clojure.main. any ideas?

13:10 rhudson: re 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:11 polypus: eshira: you might be interested in my http://github.com/polypus74/cajual

13:11 or you could check out cljr on github

13:17 eshira: i've never gotten cljr to work. "cljr repl" produces the same error as above.

13:18 i probably have some other dependencies out there screwing w/ it

13:19 but 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:21 rhudson: eshira: what OS? what JVM?

13:21 eshira: ok, fixed it w/ a super simple solution: $ rm /Library/Java/Extensions

13:22 i mean: rm /Library/Java/Extensions/jline.jar

13:22 rhudson: ah, that sounds a likely culprit

13:22 eshira: i am on OS X 10.6

13:23 polypus: eshira, cajual mentioned above keeps jline up to date with a simple lein deps

13:23 slyrus: what is the properly idiomatic way to do (drop 1 [1 2 3]) and get [2 3] instead of (2 3)?

13:23 polypus: works for me on 10.6

13:25 slyrus: or, put another way, why doesn't (rest [1 2 3]) return [2 3]?

13:26 polypus: slyrus: because it is a sequence function, not a vector manipulation function

13:27 slyrus: ok... but why not return a sequence of the same type as what was passed in? why default to a list?

13:27 presumably it's because things like dropping the first item of a vector are pretty expensive

13:28 polypus: slyrus: it's not a list

13:28 ,(class (drop 1 [1 2 3]))

13:28 clojurebot: clojure.lang.LazySeq

13:30 polypus: if 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:30 slyrus: fair enough

13:35 eshira: polypus, thanks. i'l check it out

13:36 polypus: eshira: np

13:36 raek: vectors are not sequences

13:37 vectors and lists are collections, and sequences are sequential views of collections

13:38 polypus: or even abstact sequence with no underlying collection (repeat :foo)

13:42 raek: although, when treated as collections (e.g. when using conj), sequences behave as if they were lists

13:43 polypus: and lists are sequences as ell as collections

13:43 ,(seq? '(1 2 3))

13:43 clojurebot: true

13:43 polypus: well*

13:47 raek: I really like how clojure makes all these different data structures and the traditional cons cells work so beatifully together...

13:48 polypus: i 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:49 raek: hrm, I dont't know.... but I do know that #(.invoke %1 %2) is preferred now

13:49 ...voer memfn

13:49 *over

13:49 hrm, "voer" looks dutch :)

13:50 SinDoc: raek: inderdaad ;)

13:50 xcthulhu: raek, 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:52 polypus: raek: problem is i need to (apply (memfn invoke) args)

13:54 raek: polypus: why not make the class inhertir from AFn and use it as a function?

13:55 polypus: raek: i don't have access to the class. in fact it's dynamically generated. it's a javafx anonymous function

13:56 raek: xcthulhu: that code looks fine if you want [index value] pairs

13:56 it's identical to "indexed" in http://media.pragprog.com/titles/shcloj/flow.pdf

13:57 Chousuke: xcthulhu: are you using 1.2?

13:57 raek: hrm

13:57 polypus: tricky

13:57 Chousuke: xcthulhu: it has a map-indexed IIRC

13:58 xcthulhu: 1.0

13:58 I'm gonna be lame here, but is there something like Haskell's "zip" for clojure?

13:58 (not zippers)

13:59 polypus: zipmap? i don't know haskell

13:59 raek: what does Haskell's zip do? I haven't gotten into Haskell yet...

13:59 (I have a strong feeling that I will one day)

13:59 rhudson: xcthulhu: (map vector a b) is Clojure's equivalent

14:00 xcthulhu: (zip [1 2 3] ["A" "B" "C]) would return ([1 "A"] [2 "B"] [3 "C"])

14:00 rhudson: awesome. Thanks

14:00 raek: (zipmap [:a :b :c] [1 2 3]) => {:a 1, :b 2, :c 3)

14:01 polypus: zipmap does same but returns a map

14:01 jinx

14:02 raek: zipmap is wonderful to have when implementing a lisp

14:02 rhudson: xthulhu: As a rule of thumb, most things that produce a sequence produce a lazy sequence, and mostly nothing else is lazy

14:02 raek: (let [new-env (extend-env env (zipmap formal-params actual-params))] ...)

14:06 LauJensen: Good evening all

14:07 xcthulhu: raek, I'm trying to teach myself clojure by writing something that solves http://www.dourish.com/goodies/aptitude-test.html

14:08 raek: heh

14:08 xcthulhu: raek, 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:08 raek: polypus: maybe you could to a macro that expands into (.invoke f foo bar ...)

14:09 xcthulhu: You can't use find-first with a map, right?

14:09 raek: that problem should be fairly straight forward to solve with the non-deterministic interpreter from SICP

14:10 find-first?

14:10 xcthulhu: raek, It's in clojure.contrib.seq

14:10 raek: you could use "some"

14:10 ah

14:10 a sequence would be made for the map

14:10 ,(seq {:a 1, :b 2, :c 3})

14:10 clojurebot: ([:a 1] [:b 2] [:c 3])

14:11 polypus: raek: memfn is implemented like this `(fn [target# ~@args]

14:11 (. target# (~name ~@args))))

14:12 i don't think there is a way of doing it w/o dropping into javaland

14:12 raek: what error did you get again?

14:13 polypus: wrong number of args. i think it's because the invoke method of the javafx functions is variable arity

14:13 xcthulhu: raek, Thanks a bunch. I'll rewrite some of this...

14:13 lpetit: ,(re-seq #"[0-9]*(?!\.)" "10")

14:13 clojurebot: ("10" "")

14:13 lpetit: ,(re-seq #"[0-9]*(?!\.)" "10.0")

14:13 clojurebot: ("1" "" "0" "")

14:14 raek: is #"(?!foo)" some special re syntax?

14:14 qbg: Yes

14:15 lpetit: Hello, 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:15 (when I say ("0" "") I'm talking about the 2d "0", not the first

14:16 raek: (?!f) means "negative lookahead for char \f"

14:16 raek: zero-width negative lookahead, that is

14:17 is there a possibility to have the desired behaviour via the use of greedy ... operators ?

14:18 raek: it matches the first 1 since it's not followed by a period

14:20 (re-seq #"[0-9]*(?!\.|[0-9])" "10.0")

14:20 ,(re-seq #"[0-9]*(?!\.|[0-9])" "10.0")

14:20 clojurebot: ("0" "")

14:20 slyrus: what'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:20 raek: added criterium: the matched digits should not have any following digits

14:20 qbg: ,(some #{3} [1 2 3 4 5 6])

14:20 clojurebot: 3

14:21 slyrus: ok, thanks qbg

14:24 raek: lpetit: did #"[0-9]*(?!\.|[0-9])" solve the problem?

14:24 lpetit: was gone

14:25 ,(re-seq #"[0-9]*(?!\.|[0-9])" "1000.0")

14:25 clojurebot: ("0" "")

14:25 lpetit: ,(re-seq #"[1-9](?!\.)[0-9]*(?!\.|[0-9])" "1110.0")

14:25 clojurebot: nil

14:26 lpetit: ,(re-seq #"[0-9]*(?!\.|[0-9])" "110000")

14:26 clojurebot: ("110000" "")

14:26 lpetit: raek: seems so

14:26 thx

14:32 raek: btw, does someone recommend any atricles/blog posts/books on Clojure program design/architecture?

14:33 Programming Clojure touches on this a bit when suggesting that one could divide the program into a purely functional part and one mutation part

14:34 slyrus: here's an improved version of my undirected graph implementation. now with bfs and dfs: http://gist.github.com/479786

14:34 raek: these slides (from a different background) suggests something similar: http://www.st.cs.uni-sb.de/edu/seminare/2005/advanced-fp/docs/sweeny.pdf

14:35 some algorithms are better of being purely functional

14:35 and the mutation part benefits from a STM

14:35 slyrus: is my use of lazy-seq correct in the {breadth,depth}-first-traversal functions?

14:38 raek: a lazy-seq often looks like something like this:

14:38 (defn lazy-something []

14:38 (if more-elements?

14:38 no wait

14:39 http://clojure.org/lazy

14:39 the second to last example is a pretty good example

14:41 slyrus: here is an example I made for experementing with lazy sequences: http://gist.github.com/480608

14:42 it can be useful for getting the feel for when items in the lazy sequence are realized

14:43 slyrus: ok, 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:43 raek: (lazy-seq (if there-is-more-elements (cons one element (call-to-make-rest ...))))

14:43 slyrus: is there a penalty for sprinkling in excess lazy-seq calls?

14:44 raek: IMHO, you shold not have to worry about the performance of making it lazy

14:44 slyrus: ah, but perhaps I should move the lazy-seq call outside of the (if (seq queue)

14:45 raek: the body of lazy-seq should result in a sequence

14:45 of which a part most often is a call to make the rest

14:46 slyrus: yes, then the check for whether is's empty or not is lazy too :)

14:47 very often, you can make a sequence making function lazy by just wrapping everything in a lazy-seq

14:47 (and also changing (recur) forms into normal function calls)

14:50 hrm, I don't think your function in it's current form is lazy at the moment

14:50 try to add a prinln to trace when it's realized

14:50 lpetit: ,(re-seq #"[0-9]*(?!\.|[0-9])" "12.3")

14:50 clojurebot: ("3" "")

14:50 lpetit: ,(re-seq #"[0-9]*(?!\.|[0-9])" "12.3")

14:50 clojurebot: ("3" "")

14:51 chouser: does anyone know off the top of their head an enlive selector for matching a tag with a specific title attr?

14:52 I see examples for class and id attrs, but not title.

14:53 raek: slyrus: I would do it something like this: http://gist.github.com/480615

14:53 (warning: not tested)

14:54 LauJensen: chouser: You just need to check if the title tag matches some predicate?

14:55 chouser: equal to a value, yes.

14:55 raek: slyrus: also, there is a clojure.lang.PersistentQueue class (which is fairly unknown)

14:55 LauJensen: (select node (has [[:title (pred #(= "something" (text %)))]]))

14:55 I think that should get you there

14:57 raek: slyrus: it supports conj, peek and pop

15:02 slyrus: hmm... 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:03 raek: ,Q

15:03 clojurebot: java.lang.Exception: Unable to resolve symbol: Q in this context

15:03 raek: naw, where did the fish-queue-syntax go?

15:04 who did the fish-queue pprint fork? replaca?

15:05 http://clojure-log.n01se.net/date/2010-05-12.html#12:55

15:05 slyrus: thanks raek, that's nicer

15:14 raek: http://gist.github.com/479786 seems to be properly lazified now. thanks again!

15:15 polypus: raek: check it http://gist.github.com/480630

15:15 slyrus: gists are pretty nice, btw

15:15 polypus: agreed

15:16 chouser: LauJensen: isn't :title for a <titile> tag?

15:16 I want the title attribute, like <a title="indexme">...</a>

15:17 LauJensen: chouser: ah, (select node [[:a (has ...)]]) with the code above inserted

15:17 chouser: 'has' is for attributes?

15:17 LauJensen: no wait, thats actually for nested tags Im thinking

15:17 lemme check the docs

15:18 chouser you need attr? or attr= depending on wether you are checking for existance or content

15:18 chouser: 'attr?' is for the existence of an attribute but seems to ignore the contents

15:18 oh!

15:18 LauJensen: http://enlive.cgrand.net/syntax.html

15:18 chouser: ah, attr= looks right. thanks!

15:23 duck1123: Does 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:23 or perhaps a better way to do what I'm doing?

15:28 LauJensen: duck1123: I dont know one off the top of my head, but it should be trivial to write your own

15:29 duck1123: I 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:30 slyrus: is there a zero-arg iterate like function?

15:30 surely there's a better way than: (drop 1 (take 10 (iterate (fn [_] (rand-int 300)) nil)))

15:30 LauJensen: slyrus: repeatedly

15:31 slyrus: thanks LauJensen!

15:53 bleakgadfly: Hey

15:55 I 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:55 As you can see in the link, if I do it in Compojure I get the jar file I want

15:55 chouser: have a lot of trouble understanding the enlive docs

15:55 I have

15:56 bleakgadfly: Could anyone tell me after reading the java output if the error is in Clojure, leiningen or in the library?

15:57 chouser: bleakgadfly: leiningen is passing a nil to Clojure's name fn, which then throws.

15:57 ,(name nil)

15:57 clojurebot: java.lang.NullPointerException

15:57 bleakgadfly: Hmm

15:57 chouser: it's not clear to me where that nil is coming from -- perhaps the lein config file?

16:00 bleakgadfly: Okay

16:00 Thanks

16:05 technomancy: who's ready for a Leiningen release?

16:07 LauJensen: technomancy: adding more cenjureship? :)

16:07 technomancy: LauJensen: why, do you have a suggestion? =)

16:07 LauJensen: "Ver 1.2: Now forbidding all names that rhyme, all camelcased names, all names inspired from contemporary music"

16:07 clojurebot: amespaces 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:07 chouser: a sugjesjion.

16:08 * chouser bows

16:08 technomancy: "Now you must name all your projects using names from literature, so START READING, you philistines."

16:08 LauJensen: Awesome :)

16:09 holoway: technomancy: leiningen is very cool

16:09 technomancy: holoway: thanks.

16:09 holoway: technomancy: kind of delightful, honestly

16:09 LauJensen: Yea dont get me wrong phil, its good stuff :)

16:11 technomancy: LauJensen: of course; all in good fun. =)

16:29 slyrus: so, 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:35 jneira: hi people

16:36 another clojure novice looking for a better version of his poor implementation ;-)

16:37 Chousuke: slyrus: does the same name really describe a set of data AND a set of operations?

16:37 jneira: this time for a function (in-range? [[0 0 0][0 0 0]] [0 2]) -> true

16:38 (in-range? [[0 0 0][0 0 0]] [1 3]) --> false

16:38 slyrus: Chousuke: yeah, i dunno... i started off with protocol Edge and record UndirectedEdge. I don't think that's right.

16:38 i'm needing new names as I think about protocols and records for things like directed graphs and edges.

16:38 Chousuke: slyrus: "Edge" doesn't sound like it's a protocol

16:39 slyrus: next you're going to tell me that Graph doesn't either :)

16:39 Chousuke: well, hmm

16:39 slyrus: not that you'll be wrong...

16:40 Chousuke: what you want to name is the set of operations you can perform on graph-like things

16:40 slyrus: Chousuke: http://gist.github.com/479786 is what I'm working on

16:40 yeah, that's what I'm starting to realize

16:41 Chousuke: you might call them GraphOps or something like that

16:41 jneira: my take of in-range? http://gist.github.com/480694

16:49 slyrus: Chousuke: 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:50 makes it easier to see how, say, DirectedGraph and DirectedEdge can fit in.

16:53 lpetit: raek: seems like using a possessive quantifier also solves the problem:

16:53 ,(re-seq #"[0-9]*+(?!\.)" "10.0")

16:53 clojurebot: ("0" "")

16:53 lpetit: ,(re-seq #"[0-9]*+(?!\.)" "10")

16:53 clojurebot: ("10" "")

17:02 raek: a typographical question about Joy of Clojure: Aren't the footnotes supposed to be at the bottom of the page?

17:02 clojurebot: you mean clojure.main

17:04 raek: clojurebot: here, have some bot snack

17:04 clojurebot: botfight is http://raek.se/botfight.html

17:04 raek: whoa! luckily I deleted that page

17:05 the title contained an instruction for sexpbot

17:06 no wait, sexpbot printed the title, which was a comman to clojurebot, which in turn outputed the url again

17:06 => infinite loop

17:08 slyrus: why 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:08 chouser: raek: fluke of the MEAP/PDF tool. Presumably the footnotes will actually be at the foot of the page in the final book.

17:09 though actually, most of the footnotes will be gone I suspect.

17:10 brb

17:12 raek: chouser: also, in the section illustrating the character syntax: "\u30DE ; The unicode katakana character „Éû}"

17:12 chouser: hm. unfortunate.

17:13 raek: looks like a double encoding issue to me

17:14 technomancy: slyrus: yes, one-namespace-per-file simplifies a lot of things in Clojure

17:15 slyrus: technomancy: how so?

17:16 technomancy: slyrus: well, there's less jumping around needed; you can see everything right in front of you

17:18 slyrus: i 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:19 chouser: I guess it's not surprising that zip-filter/xml is more suited to my specific needs than enlive is.

17:19 raek: slyrus: you can still divide the code in multiple files

17:19 the user might only need to use one of the files/namespaces

17:20 the others can be for splitting up the implementation of the "main" namespace

17:20 technomancy: it forces you to think about the relationship between the functions

17:20 * raek reads the wholde of slyrus's utterance

17:21 technomancy: since all sharing between namespaces is explicit

17:22 chouser: which is likely desirable between truly separate modules, and undesirable within things that are actually interdependent.

17:28 lpetit: maybe 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:28 s/where/were/g

17:28 sexpbot: lpetit: Format is sed [-<user name>] s/<regexp>/<replacement>/ Try $help sed

17:28 lpetit: s/where/were/

17:28 sexpbot: s/were/were/g

17:28 lpetit: gargl

17:31 technomancy: lpetit: yes, I must confess that's part of what appeals to me. =)

17:31 lpetit: technomancy: ahah, I was sure about that one :-)

17:32 technomancy: breaking one-namespace-per-file also forces you to use load-file instead of use/require, which is icky

17:35 chouser: so nobody else using enlive has needed something to extract all the textual content from a node?

17:41 bortreb: If I make a mistake when uploading a jar to clojars, then is there any way to reverse it?

17:50 lpetit: technomancy: congrats for Lein 1.2 !

17:54 * raek just learned about :strs in map destructuring

17:57 rhudson: There's :syms too, but I've never used anything but :keys

17:59 raek: the version of compojure I have been using (pre 0.4) passed http headers as maps with string keys

18:00 I think the most common usage scenario would be when one gets map-like data from another data format

18:00 e.g. Json

18:01 xcthulhu: Is there a prime? function for clojure?

18:06 rhudson: xcthulhu: not to my knowledge. There's clojure.contrib.lazy-seqs/primes, which as you might guess is a lazy sequence of the primes.

18:09 xcthulhu: rhudson, The SICP book presents Fermat's probabilistic algorithm but it's not in a library:

18:09 http://sicpinclojure.com/?q=sicp/1-2-6-example-testing-primality

18:10 rhudson: Right, you could use the 'primes seq as test divisors for up to (sqrt n)

18:11 raek: is autopromotion still in 1.2?

18:14 rhudson: Interesting about the Fermat test; hadn't heard of that

18:17 xcthulhu: rhudson, it's not perfect; there's lots of refinements

18:17 For instance: http://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test

19:04 bortreb: this looks like a good implementation of various primality tests http://code.google.com/p/clj-primetest/

19:05 the clj stands for , of course, "command line java"

19:22 Raynes: Woot! Leiningen 1.2.0!

19:26 xcthulhu: bortreb, Well... I ended up implementing the brute force algorithm myself.

19:27 erikcw1: Is 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:29 xcthulhu: To be honest, I know that the numbers I am checking are bounded above by 20, so my efficiency concerns are a bit silly...

19:34 An 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:43 erikcw1, Sorry, I missed your post

19:44 erikcw1: np

19:44 xcthulhu: find-first in clojure.contrib.seq is what you want

19:44 erikcw1: Just found that

19:44 xcthulhu: :(

19:44 erikcw1: looks like chunking of lazy seqs is a problem though

19:44 I only have about 8 items in the seq

19:44 Raynes: -> (some identity [nil false 1 nil false])

19:44 sexpbot: => 1

19:45 erikcw1: so they all get pulled

19:45 konr: Guys, 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:46 Raynes: erikcw1: (some identity ...) works.

19:48 erikcw1: Raynes: thanks -- not really sure how that works. I'll have to dig into the source. I haven't used identity before

19:49 xcthulhu: , (identity 5)

19:49 clojurebot: 5

19:49 xcthulhu: , (identity "Hello")

19:49 clojurebot: "Hello"

19:50 xcthulhu: In Haskell it's called id

19:50 tomoj: konr: are you not using leiningen?

19:50 erikcw1: xcthulhu: Where would I put my predicated in this example?

19:51 konr: tomoj: I am. Perhaps clojure-1.1 is required, let me see...

19:51 tomoj: clojure 1.1 is not required

19:51 xcthulhu: , (some odd? [2,4,6,8,7,9,9,10,11])

19:51 clojurebot: true

19:51 tomoj: konr: paste you project.clj

19:53 does clojure play nice with gcj?

19:53 chouser: gnu classpath doesn't implement all the classes clojure.core uses

19:53 tomoj: konr: that could be your problem?

19:54 xcthulhu: erikcw1, Hmm... I'm not sure.

19:54 konr: tomoj: not really, the error changed, but I still got an error, haha... let me paste the file

19:54 xcthulhu: erikcw1, this is kind of ugly, but what about:

19:55 , (some identity (map #(and (even? %) %) [1,3,5,7,11,12,14,16])

19:55 clojurebot: EOF while reading

19:55 xcthulhu: , (some identity (map #(and (even? %) %) [1,3,5,7,11,12,14,16]))

19:55 clojurebot: 12

19:56 xcthulhu: erikcw1, I think that has the semantics you want...

19:56 throw in pred for even? and coll for [1,3,...]

19:57 erikcw1: , (some identity (map #(do (print \.) (and (even? %) %)) [1,3,5,7,11,12,14,16]))

19:57 clojurebot: 12

19:57 ........

19:58 erikcw1: xcthulhu: seems like it looses its de-chunkified lazyiness

19:59 xcthulhu: hmm

20:01 konr: tomoj: http://884e867afd61073a.paste.se/ - apparently slime keeps polling and *inferior-lisp* contains http://c8096c7945723343.paste.se

20:01 chouser: map will do chunks on a vector

20:01 'some' will pull individual cons cells from that

20:03 tomoj: konr: http://94e90f3e196645be.paste.se/ try that

20:03 but if what chouser says is true, I think you will need to get sun or openjdk and switch

20:04 konr: and do `lein clean` and `lein deps` before trying `lein swank` again

20:07 konr: hmmm, lein couldn't find the files and suggested me to download them manually

20:07 tomoj: err

20:09 I screwed up

20:10 konr: http://66a7040ca1ad624f.paste.se/

20:24 konr: tomoj: strange, now I got another kind of error: http://2dd5ecc0568d2d09.paste.se/

20:36 tomoj: konr: again, you need to switch to sun or openjdk

20:53 thunk: It 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:06 * slyrus keeps finding himself wanting to do: #([(last %) (count %)]), eg, instead of #(vector (last %) (count %))

21:07 chouser: yeah

21:08 slyrus: or maybe #[(last %) (count %)]

21:08 nah, that's crazy talk

21:09 yeah, 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:10 konr: tomoj: that was the problem in the end! Thanks! :)

21:35 cais2002: morning

21:46 slyrus: i 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:51 rhudson: slyrus: you can use split-with

21:58 pdk: can regular clojure (a b c) type lists be serialized in a standardized way that preserves nested lists

22:01 konr: Do 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:03 slyrus: my 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:03 pdk: the everyman's graph!

22:04 slyrus: huh?

22:04 pdk: it's a catchy name no

22:05 slyrus: no

22:50 when does the "WARNING: spit already refers to..." warning go away?

22:58 how about shortcut for the name of my graph library?

23:01 ok, 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:02 Raynes: -> (partition 2 [1 2 3 4 5])

23:02 sexpbot: => ((1 2) (3 4))

23:02 Raynes: Is wish it would do something meaningful with the last odd numbered element. :\

23:12 chouser: -> (parition-all 2 [1 2 3 4 5])

23:12 sexpbot: java.lang.Exception: Unable to resolve symbol: parition-all in this context

23:13 chouser: -> (parition 2 2 [1 2 3 4 5] [0 0])

23:13 sexpbot: java.lang.Exception: Unable to resolve symbol: parition in this context

23:13 chouser: -> (partition 2 2 [1 2 3 4 5] [0 0])

23:13 sexpbot: => ((0 0))

23:13 chouser: -> (partition 2 2 [0 0] [1 2 3 4 5])

23:13 sexpbot: => ((1 2) (3 4) (5 0))

23:14 chouser: -> (partition-all 2 [1 2 3 4 5])

23:14 sexpbot: => ((1 2) (3 4) (5))

23:14 chouser: there you go. sorry for the noise.

23:14 Raynes: chouser: You're my hero.

23:14 * chouser strikes a pose, cape billowing in the wind.

23:22 technomancy: slyrus: you can use checkout dependencies for the situation youv'e described

23:23 slyrus: put a symlink from the dependency into the "checkouts" directory in the other project and it will be put on the classpath

23:23 no need for the lein install/lein deps dance

23:24 it's mentioned in the faq in the readme

23:30 slyrus: oh, ok. thanks technomancy!

23:32 technomancy: what does "symlink some other projects into it" mean?

23:33 other projects.clj or their enclosing directories?

23:33 * slyrus has never been a fan of project.clj as if you have a bunch of 'em open in emacs its project.clj<4>, for instance.

23:33 slyrus: my-project.lng, or similar, would have made more since, IYAM, which you didn't :)

23:36 drewr: slyrus: C-h f toggle-uniquify-buffer-names RET

23:37 slyrus: bah... 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:43 Bahman: Hi all!

23:48 cais2002: hi Bahman

23:48 Bahman: Hi cais2002!

Logging service provided by n01se.net