#clojure log - Nov 14 2010

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

0:20 pppaul: $fortune

0:20 sexpbot: You will yawn in 5 seconds.

0:20 pppaul: $fortune

0:20 sexpbot: You will yawn in 5 seconds.

0:20 pppaul: $8ball is $fortune broke?

0:20 sexpbot: pppaul: Concentrate and ask again.

0:21 johndeo: $fortune

0:21 sexpbot: one day sexpbot will have a large fortune database

0:22 pppaul: i gave it some cookies

0:22 what gives

0:23 $fortunecookie

0:23 $fortune cookie

0:23 sexpbot: You will yawn in 5 seconds.

0:23 pppaul: hmph

0:23 johndeo: $fortune

0:23 sexpbot: You will yawn in 5 seconds.

0:48 johndeo: ##(assoc-in nil [:a :b :c] 1)

0:48 sexpbot: ⟹ {:a {:b {:c 1}}}

0:49 johndeo: ##(assoc-in nil [:a :b :c] :foo)

0:49 sexpbot: ⟹ {:a {:b {:c :foo}}}

0:49 johndeo: Can anyone tell me how to read the :foo out of there?

0:51 ({:a {:b {:c :foo}}} :b)

0:51 ##({:a {:b {:c :foo}}} :b)

0:51 sexpbot: ⟹ nil

0:53 johndeo: ##({:a {:b {:c :foo}}} :a)

0:53 sexpbot: ⟹ {:b {:c :foo}}

0:56 amalloy: johndeo: ##(get-in {:a {:b {:c :foo}}} [:a :b :c])

0:56 sexpbot: ⟹ :foo

0:57 sproust: Anybody know what happened to with-out-writer?

0:58 (Porting some code to the bleeding edge, lots of stuff moved.)

1:01 johndeo: ##(def deephash (assoc-in nil [:a :b :c :d] '(:a :b :c :d)))

1:01 sexpbot: java.lang.SecurityException: You tripped the alarm! def is bad!1

1:01 johndeo: oops

1:02 amalloy: Oh! Thanks.

1:03 replaca: sproust: you have to use (with-open [w (writer "xxx")] (binding [*out* w] ...)), I think

1:04 sproust: with-out-writer was considered to do too many things at once to migrate to core

1:04 sproust: replaca: thanks.

1:05 I'll redo the macro in my code-- it's very useful.

1:05 What you wrote above is long enough for me to create an abstraction.

1:08 replaca: I now get "Evaluation aborted" on evaluating (ns) directives instead of errors. Is there a fix?

1:09 LauJensen: Morning all ya'll

1:09 replaca: sproust: I don't know. I haven't seen that prob.

1:10 Morning Lau. Congrats on all the CQL progress

1:11 Lau: for the record, I vote for select, et al. rather than shadowing core stuff

1:11 LauJensen: replaca: thanks, and thanks for your input

1:11 Reading the official Wiki on library design, it occured to me that shadowing core was encouraged when there are parallel semantics

1:12 Why would you prefer I didnt do it ?

1:14 replaca: LauJensen: to me it only works if the semantics are *really* identical. And the I'd rather get all the way to implementing the same underlying protocol. Plus, the semantic model of SQL is already very familiar, so hiding it seems like obfuscation

1:15 pppaul: show me some CQL

1:15 LauJensen: @(conj! users {:name "Jack"})

1:15 >>> ({:id 1 :name "Lau"} {:id 2 :name "Christophe"} {:id 3 :name "Frank"} {:id 4 :name "Jack"})

1:15

1:15 (-> (table {} :users)

1:15 (select (where (= :admin true)))

1:15 (aggregate [:count/* :country]))

1:15 >>> "SELECT users.country,count(users.*) FROM users WHERE (admin = true) GROUP BY country"

1:15

1:15 @(join users visitors :id) ; USING(id)

1:15 >>> ({:id 1 :name "Lau" :guest "false"} {:id 3 :name "Frank" :guest "true"})

1:15

1:16 pppaul: the rest is here https://github.com/LauJensen/clojureql on the front-page, scroll down

1:16 replaca: LauJensen: but it's important to note that my vote doesn't come from any direct experience with CQL itself

1:16 LauJensen: replaca: The official way, is not to shadow when the semantics are identical, but parallel. In this case, clojure.set is an implementation of relational algebra and so is CQL. Main difference is CQL puts the results in a database

1:16 This is more of a library design issue than a SQL issue

1:17 sproust: That's very cool! Not so much as a replacement for SQL's syntax, but as a way to generate queries programmatically!

1:17 LauJensen: However - The semantics are very parallel, the primitives are identical. So I figured a familiar interface like conj/disj/sort/take etc would be great - no learning curve

1:17 pppaul: so, sometimes CQL wraps SQL, and sometimes you have to use SQL as text?

1:17 LauJensen: sproust: exactly

1:17 replaca: LauJensen: yeah, I get that. You asked for my preference :). I would always be looking through to the generated code :)

1:18 LauJensen: pppaul: CQL always wraps SQL, but if you want, I let you escape our syntax with strings so tht you can write raw sql. shouldnt be necessary

1:18 pppaul: it looks cool... how many public symbols are there?

1:19 LauJensen: pppaul: https://github.com/LauJensen/clojureql/blob/master/src/clojureql/core.clj#L21 those listed in the protocol definition, + a contructor, table? and where

1:21 pppaul: ^_^

1:22 sproust: Hmmm... bleeding-edge SLIME w/ bleeding-edge swank w/ Bleeding-edge Clojure = broken. Errors don't trickle back up to Emacs.

1:22 "error in process filter"

1:23 G'night folks!

1:24 amalloy: aww. missed my chance to tell him there's a reason they call it bleeding-edge

1:24 pppaul: too much bleeding

1:32 quizme: how do you do a deep merge of two maps with conj ?

1:38 http://www.pastie.org/1296480

1:49 LauJensen: Can anybody think of a good name for the CQL equivalent of with-results ?

1:50 quizme: nm, i found it: clojure.contrib.map-utils/deep-merge-with

1:52 tonyl: i was looking for it in contrib figure there might be something

1:52 cool

1:55 with-records ? maybe

1:58 how does this work ##(let [{a :a, b :b, c :c, :as m :or {a [2 3] b [3 4]}} {:a [5 6] :c [6 7]}] [a b c m])

1:58 sexpbot: ⟹ [[5 6] [3 4] [6 7] {:a [5 6], :c [6 7]}]

1:59 tonyl: i know it is destructuring

1:59 but one map has the keys as symbols and are not even quoted

2:07 pppaul: :as /

2:07 :as ????

2:08 barf @ tonyl's code

2:08 tonyl: :as it is a special key

2:08 in destructuring it returns the entire map of the binding

2:08 yeah, i don't get it either

2:09 this is where my understanding of destructuring stops

2:09 pppaul: i don't know :as or :or

2:09 lots of things to learn...

2:09 tonyl: &(let [[a b :as m] [1 2 3 4 5 6 ]] [a b m])

2:09 sexpbot: ⟹ [1 2 [1 2 3 4 5 6]]

2:11 tonyl: check this out http://blog.jayfields.com/2010/07/clojure-destructuring.html

2:12 pppaul: hot stuff

2:12 tonyl: it's like a mini language

2:17 amalloy: do you still have a question, tonyl? ("how does this work" is insufficiently specific)

2:19 tonyl: i dont understand this map {a :a, b :b ... } used in destructuring, why are the keys symbols

2:20 pppaul: &(doseq [[k v] {:a 1, :b 2, :c 3}]

2:20 sexpbot: java.lang.Exception: EOF while reading

2:20 pppaul: (println k "=" v))

2:20 (doseq [[k v] {:a 1, :b 2, :c 3}](println k "=" v))

2:20 &(doseq [[k v] {:a 1, :b 2, :c 3}](println k "=" v))

2:20 sexpbot: ⟹ :a = 1 :b = 2 :c = 3 nil

2:21 pppaul: how does that work?

2:21 the [k v ] part

2:21 amalloy: tonyl: the keys in map bindings are the locals (or more complicated binding forms) you want assigned to the value of the corresponding keys in the map

2:22 &(let [{[a b :as c] :val} {:val [1 2 3]}] [a b c])

2:22 sexpbot: ⟹ [1 2 [1 2 3]]

2:22 tonyl: &(let [{val :k} {:k "tee"}] [val])

2:22 sexpbot: ⟹ ["tee"]

2:22 tonyl: I guess the switch threw me off

2:23 amalloy: it's surprising the first time you see it, but there's a reason

2:23 tonyl: yeah, the example I saw was big. I needed it to break it down smaller

2:24 amalloy: tonyl: does mine make sense to you now?

2:24 tonyl: yeah

2:24 thanks

2:24 amalloy: welcome

2:24 there's a shorthand for the complicated one you posted first

2:24 tonyl: what is the shorthand?

2:25 amalloy: &(let [{:keys [a b c] :as m} {:a [5 6] :c [6 7]}] [a b c m])

2:25 sexpbot: ⟹ [[5 6] nil [6 7] {:a [5 6], :c [6 7]}]

2:25 tonyl: ooh :keys right

2:26 pppaul the map entry which is passed as a vector destructures vector to the key en value

2:27 amalloy: pppaul: ##(seq {:a 1, :b 2, :c 3})

2:27 sexpbot: ⟹ ([:a 1] [:b 2] [:c 3])

2:28 amalloy: after that it's just destructuring a plain old list-of-lists, with no map funkiness to worry about

2:28 replaca: tonyl: I think the answer to your question is that in a macro (and destructuring is effectively done in a macro) the map has been read but not evaled

2:28 pppaul: amalloy, how would i do that in a let?

2:29 amalloy: do what?

2:29 pppaul: [k v] {:a 1 :b 2 :c 3}

2:29 replaca: tonyl: therefore, the symbols are not yet evaled and can be torn out to use as locals

2:29 pppaul: oh

2:29 i see

2:29 nm

2:29 i missed your reply

2:31 replaca: &(read-string "{a :a b :b}")

2:31 sexpbot: ⟹ {a :a, b :b}

2:57 Mimisbrunnr: Hi all, I cannot for thel if of me, seem to get clojure-contrib working

2:57 *the life

2:57 the path to the jar is in my CLASSPATH but java doesn't seem to find it

2:58 (I'm on OSX 10.5.x) ideas?

2:58 tonyl: does it load clojure?

2:59 Mimisbrunnr: yes, clojure loads fine, though I'm using -cp for that, if I use -cp for both of them, it doesn't load

2:59 amalloy: Mimisbrunnr: you can't give two -cp entries

2:59 you need -cp /path/1:/path/2

2:59 tonyl: are you using the right path separator

2:59 Mimisbrunnr: amalloy: I did that, and tonyl yes I'm using : and /

3:00 (: for differnt paths / for folders )

3:00 tonyl: are you using direct paths or relative ones?

3:03 Mimisbrunnr: direct

3:03 tonyl: now that is weird

3:03 Mimisbrunnr: tonyl: hence my being here =P

3:03 tonyl: can you show us the full command you are using

3:04 Mimisbrunnr: sure, let me try it again, I'll pastebin the error as well

3:04 tonyl: ok, another thing might be permissions to the jar file

3:05 Mimisbrunnr: ...

3:05 well, slap my ass and call me charlie

3:05 it works

3:05 sorry to waste your time

3:05 Raynes: *SPANK* CHARLIE!

3:05 tonyl: charlie

3:05 np

3:06 Mimisbrunnr: haha danke =P

3:06 well, now it works, I can go to bed, or keep coding..

3:06 tonyl: or both

3:07 Mimisbrunnr: I find, while I do my best napping while driving, I do my worst coding while alseep

3:07 tonyl: hahaha now your limits, wise

4:11 bmh: How can I use a function defined later on in my source in one earlier in the source?

4:12 amalloy: bmh: (declare later-fn)

4:12 or, my preference, reorder things

4:13 bmh: amalloy: thanks. Neither of those solutions are particularly pleasant

4:33 aslam: how do I get a list of currently running thread from clojure?

4:34 Java's Thread has an enumerate function, but it takes an array of Thread and copies references to the array.

4:36 Raynes: aslam: Is there a particular reason you wish to do that via code? If you use jconsole and attach to the JVM, you can see how many threads are running and such like thatr.

4:36 In any case, this code should be easy enough to adapt: http://stackoverflow.com/questions/1323408/get-a-list-of-all-threads-currently-running-in-java

4:37 aslam: @raynes thanks

4:38 amalloy: aslam: (let [a (make-array Thread (Thread/activeCount))] (Thread/enumerate a) (seq a))

4:38 Raynes: There ya go.

4:38 amalloy is the much less lazy version of myself.

4:39 amalloy: well, it takes Raynes ten minutes to download http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html

4:39 so i do the heavy lifting for him

4:39 Raynes: 9.4 seconds

4:40 aslam: you guys are awesome :)

4:40 amalloy: Raynes: is that timing wget/curl, or firefox with firebug?

4:41 Raynes: amalloy: It's clicking your link and counting while chrome loads the page.

4:41 * amalloy doesn't believe for a second that Raynes has decisecond accuracy

4:41 Raynes: I can't be off by more than 3 seconds on either side.

4:42 amalloy: fwiw firebug says it takes me 3.5s

4:42 Raynes: &(let [a (make-array Thread (Thread/activeCount))] (Thread/enumerate a) (seq a))

4:42 sexpbot: ⟹ (#< Thread[ObjectId-TimeFixer,5,main]> #<PoolThread Thread[27282470@qtp0-0,5,main]> #<PoolThread Thread[21680790@qtp0-1 - Acceptor0 SocketConnector@0.0.0.0:8881,5,main]> #<Thread Thread[Thread-4,5,main]> #<Thread Thread[pool-2-thread-1,5,main]> #<Thread Thread[Thread... http://gist.github.com/676047

4:42 Raynes: Neat, it actually works.

4:42 amalloy: 1s if i don't bypass the cache

4:42 Raynes: i would have tried it here, but i assumed you weren't allowing thread operations

4:43 oh, i see. but we're not calling any methods on threads, just on Thread

4:43 Raynes: &(.stop (Thread. (fn [])))

4:43 sexpbot: java.security.AccessControlException: access denied (java.lang.RuntimePermission stopThread)

4:44 amalloy: okay, i'm going to bed. have to be out of the house in like 7 hours

4:45 night all; Raynes

4:45 Raynes: Aww.

4:45 Night

4:45 Now I'm all alone.

4:46 aslam: Raynes: I see 224 users

4:47 Raynes: But none of them are amalloy_ ;(

4:49 aslam: Raynes: ah. can't do anything about that

5:12 user> (mod 10 3)

5:12 1

5:12 user> (mod -10 3)

5:12 2

5:12 user> (mod 10 -3)

5:12 -2

5:12 user> (mod -10 -3)

5:12 -1

5:12 user> (rem 10 3)

5:12 1

5:12 user> (rem -10 3)

5:12 -1

5:12 user> (rem 10 -3)

5:12 1

5:12 user> (rem -10 -3)

5:12 -1

5:12 I understand that mod takes the sign of divisor and rem takes the sign of divident

5:12 but why is mod showing 2 when signs are opposite?

5:14 ah got it

5:24 pppaul: (inc aslam)

5:24 sexpbot: ⟹ 1

5:25 pppaul: what would be a good way to do a 2d array in clojure?

5:26 is a list of lists reasonable?

5:35 morphling: pppaul: vector of vectors is closer to a 2d array

5:35 since lists have O(n) access to the nth element

5:37 pppaul: for my purpose execution time is not a problem

5:37 i guess the syntax and everything would be the same with a list or vector

5:40 aslam: what is the difference between rest and next?

5:43 Nikelandjelo: How to draw parametric functions using incanter.charts? For example I have functions for circle: x(t) = cos(t) y(t) = sin(t) . I can generate points for t from 0 to 2*PI, but I don't know how to draw them using charts. xy-plot and add-lines don't work. They seem to sort these points by x and then display. Is there some other function for it?

5:50 pppaul: aslam, look on clojure.org

5:50 next is for pure lazy seqs

5:55 fliebel: morning

5:56 aslam: next

5:56 function

5:56 Usage: (next coll)

5:56 Returns a seq of the items after the first. Calls seq on its

5:56 argument. If there are no more items, returns nil.

5:56 rest

5:56 function

5:56 Usage: (rest coll)

5:56 Returns a possibly empty seq of the items after the first. Calls seq on its

5:56 argument.

5:57 the only difference seems to be the ending where next returns nil and rest returns an empty sequence

5:59 and since '() is true in boolean context, rest could potentially cause some infinite loops I think

6:05 jarpiain: aslam: (next (cons 1 (lazy-seq ...))) has to force the lazy seq to see if it should return nil

6:09 aslam: jarpiain: I c. thanks

6:18 jarpiain: that is not the case it seems

6:18 (def tmp (next (cons 1 (iterate #(do (println (str %1)) (flush) (inc %1)) 1))))

6:18 user> (first tmp)

6:18 1

6:18 user> (first (next tmp))

6:18 1

6:18 2

6:19 (first tmp) didn't cause the println to print 1

6:25 zmyrgel: hmm, how can I check if list of records contain specific record?

6:25 my quick attempt with 'some' didn't work

6:30 jarpiain: aslam: (iterate f x) returns (cons x (lazy-seq (iterate f (f x))), i.e., the the first cons cell is not lazy and doesn't require calling f

6:31 zmyrgel: yep, totally wrong predicate for some, got it fixed

6:32 jarpiain: ,(let [x (iterate #(do (print "test") (inc %1)) 1)] (next x) (first x))

6:32 clojurebot: test

6:32 1

6:32 jarpiain: ,(let [x (iterate #(do (print "test") (inc %1)) 1)] (rest x) (first x))

6:32 clojurebot: 1

6:32 raek: first does not force the rest of the list

6:33 ah. misread it.

6:34 also: https://gist.github.com/480608

6:35 aslam: ah, i c. thats interesting :) thanks

9:34 zmyrgel: hi, I need a bit of help writing function to create a game board

9:35 I need to make an empty game-board and then update it with by giving it 2 parameters, string of game pieces and a row number where to put pieces

9:36 it sounds like a job for reduce but I've only used it for simple stuff

9:36 tomoj: "update it"?

9:36 like, assoc?

9:37 how do you represent the game-board?

9:38 vector of vectors?

9:38 zmyrgel: its a vector

9:39 http://pastebin.com/DiVSvMNM

9:39 here's my current progress

9:40 tomoj: I see

9:40 so..

9:40 zmyrgel: I mean to have empty game board, and then apply function which would add pieces for single row to it

9:40 tomoj: each row of the game-board is placed in its own part of the vector?

9:41 zmyrgel: each row starts at 0x0, 0x10 coordinate on the vector

9:41 tomoj: cool

9:42 I don't really understand your code yet

9:42 but..

9:42 the (for [fen ...] (reduce apply-fen... looks problematic

9:42 I can only guess based on the variable/fn names

9:42 zmyrgel: lemme give more expanded example

9:42 tomoj: but, if you build up a sequence and want to reduce over it

9:42 you don't reduce in for

9:43 oh

9:43 zmyrgel: I have working function which does it already but I'm rewriting it

9:43 tomoj: was it smelly?

9:44 what does splitting on /+ leave you with?

9:44 mrBliss: What's the Common Lisp equivalent of (take n coll)?

9:44 zmyrgel: http://pastebin.com/FcEZm169

9:45 it leaves a list of strings

9:45 the existing function seems quite iterative

9:45 tomoj: and you have one string in the list for each row?

9:46 zmyrgel: yes, each string in the list has all the chess pieces on that row

9:47 tomoj: "4P3"?

9:47 zmyrgel: It means 4 empty squares and pawn piece followed by 3 empty squares

9:48 tomoj: aha

9:49 so

9:49 zmyrgel: I replaced my previous board->fen function with more functional approuch and it got much simpler

9:49 tomoj: I think it would be helpful to avoid for

9:49 zmyrgel: so I wanted to see if I could do the same for this part too

9:50 ok

9:50 tomoj: at least for me to figure out what you really want

9:50 maybe for will be useful in the end

9:51 zmyrgel: I planned to have one function which would take a [board fen row] arguments and return new board with pieces from fen applied to row

9:51 tomoj: where is map-indexed?

9:51 oh, right there in core

9:51 wow

9:52 so you have this list of row descriptions

9:52 you can map-indexed over it

9:53 then your reduce will have access to both the row fen string and the row number

9:53 ... I think

9:54 zmyrgel: hmm

9:54 tomoj: but what would be in the map function?

9:54 you want to do all the real work in the reduce function, I guess?

9:55 zmyrgel: yeah

9:55 tomoj: so the reduce fn will take a game-board (initialized to empty), and a row

9:55 zmyrgel: and the fen string

9:55 tomoj: and it does all the linearization math to get the proper place to stick the pieces in the game-board array?

9:57 does your scheme for mapping all the rows into a 1d array make it so that the array is just all the pieces in row-major order?

9:57 zmyrgel: yes, for example, with "3p4" fen and 0x30 coord it would assign empty squares to board coordinates 0x30, 0x31 and 0x31 and so forth

9:57 tomoj: or is there gaps?

9:58 zmyrgel: there are 'gaps', its like two chess boards side by side and the others empty

9:58 tomoj: oh, hmm

9:58 (just curious, why? because the 0x30 coord for row 4 (?) is pretty?)

9:59 zmyrgel: so board indexes 0x20 to 0x27 are on the board and 0x28 to 0x2f are outside

9:59 It helps when checking piece movements and if the index is on the board

9:59 tomoj: ok

9:59 zmyrgel: http://chessprogramming.wikispaces.com/0x88

10:00 tomoj: awesome

10:00 do you have great chess-fu

10:00 zmyrgel: nope :)

10:00 I haven't played chess in over 10 years and this is my first functional programming work

10:01 tomoj: those who can, do. those who can't, build software.

10:01 zmyrgel: Doing my bachelor's thesis on this

10:01 tomoj: unfortunately I didn't get to hear the lambda tones actually play anything real

10:02 but I wonder, how many of the tool pioneers are also great at whatever the tool is for?

10:02 zmyrgel: yeah

10:02 tomoj: anyway

10:02 zmyrgel: well, this is still the easy stuff

10:03 once I get to the AI stuff

10:03 tomoj: :D

10:03 what model?

10:03 zmyrgel: model?

10:03 tomoj: you can get the array coords for a piece by adding its index in the row to the row coord, right?

10:04 zmyrgel: yes

10:04 tomoj: I mean, give me some buzzwords that appear often in your readings

10:04 zmyrgel: alphabeta pruning

10:04 though I would be happy with working minimax

10:05 tomoj: but how do you do position evaluation?

10:06 zmyrgel: so far it only calculates material balance and some simple board location checks

10:06 Once I get my pieces to move correctly I plan to move to AI stuff

10:06 now my rook can jump over pieces etc :)

10:07 tomoj: well, I think what you were planning was to reduce over the pieces in each row, maybe?

10:07 then the reduce assoc's into the game-board vector according to the row coord + index in row?

10:07 zmyrgel: yeah, that was my plan

10:08 I have no idea how the reduce's function arguments should be presented to it

10:09 tomoj: well

10:10 you can always reduce (map vector coll (range))

10:10 oh

10:10 no

10:11 (map-indexed vector coll)

10:11 zmyrgel: ok

10:11 tomoj: this will give you the index in the row, to which you can add the row coord which should (I think) be closed over

10:12 so your reduce function will look like (fn [game-board [index piece]]) I think

10:14 assuming you can generate all the pieces into a coll/seq for a row

10:14 zmyrgel: yeah

10:17 tomoj: and then each time through the reduce, you assoc (+ row-coord index) in the game-board?

10:18 and then you reduce over the rows... :(

10:19 zmyrgel: hmm, my brain starts to get pretty twisted already

10:23 tomoj: (reduce (fn [game-board [row-coord row]]) ...)

10:25 the coll there should be [[0x00 pieces-for-row-0] [0x10 pieces-for-row-1] ...]

10:25 which you can get by doing a map-indexed over the processed row strings with a map function that looks up the index to get a coord

10:26 then, in the reduce fn, you reduce again over the (pieces in the) row

10:27 doing a map-indexed again to get the assoc index for each piece by adding to the row-coord, which is closed over here

10:28 make any sense?

10:28 zmyrgel: some, but I think it takes some repl fooling and doc reading to really sink in

10:31 tomoj: I may be full of shit since I don't think I fully understand what you're doing

10:33 mtyaka: hi all, i'm trying to come up with a nice way of turning a vector of strings like this: ["-a" "b" "-c" "d" "e" "f" "-g" "-h" "i"]

10:33 into this: ["-ab" "-cdef" "-g" "-hi"]

10:34 This is what I've got so far: https://gist.github.com/676245

10:34 Is there a cleaner way?

10:37 zmyrgel: yeap, but at least it has given me some pointers where to focus

10:38 opqdonut: mtyaka: try using split-with

10:39 tomoj: will the very first character always be \-?

10:39 mtyaka: yes

10:40 opqdonut: thanks for the pointer, will try it out

10:45 opqdonut: or if you like to keep it simple, try something like

10:45 (clojure.contrib.str-utils/re-split #"-" (str ["-a" "b" "c" "-d" "e" "-f" "g"]))

10:45 err, apply str

10:45 I couldn't get re-split to work in clojurebot so I can't demonstrate :)

10:47 LauJensen: &(clojure.string/re-split #"-" (str ["-a" "b" "c" "-d" "e" "-f" "g"]))

10:47 sexpbot: java.lang.Exception: No such var: clojure.string/re-split

10:47 raek: &(require 'clojure.string)

10:47 sexpbot: ⟹ nil

10:47 raek: &(clojure.string/re-split #"-" (str ["-a" "b" "c" "-d" "e" "-f" "g"]))

10:47 sexpbot: java.lang.Exception: No such var: clojure.string/re-split

10:47 MayDaniel: &(clojure.string/split #"-" (str ["-a" "b" "c" "-d" "e" "-f" "g"]) #"-")

10:47 sexpbot: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.regex.Pattern

10:47 LauJensen: &(clojure.string/re-split #"-" (str ["-a" "b" "c" "-d" "e" "-f" "g"]))

10:47 sexpbot: java.lang.Exception: No such var: clojure.string/re-split

10:47 MayDaniel: &(clojure.string/split (str ["-a" "b" "c" "-d" "e" "-f" "g"]) #"-")

10:47 sexpbot: ⟹ ["[\"" "a\" \"b\" \"c\" \"" "d\" \"e\" \"" "f\" \"g\"]"]

10:48 LauJensen: &(use 'clojure.contrib.str-utils)

10:48 sexpbot: ⟹ nil

10:48 LauJensen: &(clojure.string/re-split #"-" (str ["-a" "b" "c" "-d" "e" "-f" "g"]))

10:48 sexpbot: java.lang.Exception: No such var: clojure.string/re-split

10:48 MayDaniel: &(clojure.string/split (apply str ["-a" "b" "c" "-d" "e" "-f" "g"]) #"-")

10:48 sexpbot: ⟹ ["" "abc" "de" "fg"]

10:48 LauJensen: &(clojure.contrib.str-utils/re-split #"-" (str ["-a" "b" "c" "-d" "e" "-f" "g"]))

10:48 sexpbot: ⟹ ("[\"" "a\" \"b\" \"c\" \"" "d\" \"e\" \"" "f\" \"g\"]")

10:50 mtyaka: very nice :)

10:52 Raynes: &(.split (str ["-a" "b" "c" "-d" "e" "-f" "g"]) "-")

10:52 sexpbot: ⟹ #<String[] [Ljava.lang.String;@3351c1>

11:00 jweiss_: is there a direct way to parse xml from a string, or do you have to create an InputStream to pass to clojure.xml/parse?

11:04 tomoj: well..

11:05 the input-stream function (not sure where the latest version lives now... clojure.contrib.io? clojure.java.io?) can take a byte array

11:05 so you could pass the .getBytes of the string to input-stream

11:06 &(with-open [xml-in (clojure.java.io/input-stream (.getBytes "<foo><bar/></foo>"))] (clojure.xml/parse xml-in))

11:06 sexpbot: ⟹ {:tag :foo, :attrs nil, :content [{:tag :bar, :attrs nil, :content nil}]}

11:06 clojurebot: ,(let [testar (fn [x y] (cond (= (reduce + (filter odd? (range 0 x))) y) (str y " is a")) )] (testar 11 25))

11:19 fliebel: Is there some magic to attach headers to this input stream when doing an url? I have some more java trickery set up for that currently.

11:20 raek: to avoid encoding issues, it would be better to make a Reader rather than an InputStream

11:21 fliebel: raek: Well, my connection has getInputStream, but I don't know about getReader.

11:21 raek: oh sorry. was refering to tomoj's suggestion

11:21 fliebel: oh, okay

11:22 raek: &(clojure.xml/parse (java.io.StringReader. "<foo><bar/></foo>"))

11:22 sexpbot: java.lang.IllegalArgumentException: No matching method found: parse for class com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl

11:23 raek: hrm

11:24 &(with-open [xml-in (clojure.java.io/input-stream (.getBytes "<foo><bar/></foo>" "UTF-8"))] (clojure.xml/parse xml-in))

11:24 sexpbot: ⟹ {:tag :foo, :attrs nil, :content [{:tag :bar, :attrs nil, :content nil}]}

11:24 clojurebot: ⟹ "Returns the metadata of obj, returns nil if there is no metadata."

11:24 raek: (the pedantic way...)

11:24 the default encoding of XML is UTF-8

11:24 if you don't specify the encoding for .getBytes, the JVM rolls a dice for you

11:24 :)

11:25 fliebel: raek: Like the xkcd one? I think they rolled the dice at the implementation and chose… forgot it, read it just yesterday.

11:26 raek: fliebel: this one? http://xkcd.com/221/ :-)

11:27 fliebel: yes sir

11:27 raek: fliebel: were you previous question about web dev?

11:28 fliebel: raek: Well, web related at least. It's just a terminal app for now. But it does web stuff.

11:28 raek: what do you mean by "attach headers to the input stream"?

11:29 fliebel: well, the url needs basic auth.

11:29 raek: are you using ring?

11:29 fliebel: now, pure java.

11:30 raek: are you implementing an HTTP server?

11:31 fliebel: no, just accessing twitter streams.

11:32 (inc raek)

11:32 sexpbot: ⟹ 1

11:32 raek: do you open a stream using url.openStream() (or something like that) and want to add headers to the HTTP request?

11:33 fliebel: raek: meh, I'm doing some funky java stuff with urls and connections, which works just fine, but I saw someone use clojure.java.io/input-stream, so I was just wondering if there was a shorter way to do it.

11:34 But yes, adding headers I am.

11:36 raek: I found this http://download.oracle.com/javase/6/docs/technotes/guides/net/http-auth.html

11:37 fliebel: raek: extending classes is not going to be any shorter than what I have.

11:37 tomoj: twitter streams?

11:37 considered and rejected aleph?

11:38 fliebel: tomoj: http://stream.twitter.com/1/statuses/sample.json

11:38 raek: looks like org.apache.commons.httpclient.HttpClient is more configurable

11:39 http://www.java-tips.org/other-api-tips/httpclient/how-to-use-basic-authentication.html

11:39 fliebel: tomoj: Replace that with ignored and you get the picture.

11:39 tomoj: heh

11:39 https://github.com/ztellman/aleph/wiki/Consuming-and-broadcasting-a-Twitter-stream

11:40 raek: looks like java's UrlConnection does not have basic auth built in

11:40 tomoj: oh

11:40 dunno if it does basic auth

11:40 fliebel: tomoj: But once I get to the point where I need a datastore I might as well use a library like Aleph.

11:40 tomoj: oh, yes it does

11:41 fbru02: hey guys why and what's the usual cure when making a defrecord I get : Don't know how to create ISeq from: clojure.lang.Symbol ?

11:43 raek: fbru02: looks like you have an error in the way you're calling defrecord

11:43 fbru02: raek isn't defrecord classname, followed by the protocol?

11:43 raek: like calling (defrecord Foo ProtoA (method [] ...)) instead of (defrecord Foo [field] ProtoA (method [] ...))

11:44 fbru02: defrecord classname vector-of-fields protocol

11:44 fliebel: tomoj: Okay, that example looks terse enough to consider, together with ClojureQL or some other database.

11:45 Nevena: Can anyone tell me in which lib/ns is 'thrown?' function?

11:45 fbru02: raek: nice , now i get it , sometimes i was doing like that, sometimes id wasn't and i didn't understand the root cause thanks !

11:49 fliebel: How can I tell if a reader is still open?

11:52 raek: if you have a BufferedReader (the fns in clojure.java.io will return one of those), readLine will return null

11:52 .read will return -1

11:53 doesn't look like there is any .isClosed method or anything similar

11:53 vic_nyc: hi, was wondering if anyone has experience using date/times with mongodb (particularly congomongo) with clojure

11:53 fliebel: raek: But readers are not really concurrent, so if it is still open, I screw up the other tread that's reading from it.

11:53 But it looks like it's still running now.

11:54 raek: I guess you have to lock it before doing anything with it

11:54 I'm really happy that those things are dead simple in clojure

11:54 fliebel: 3000 urls and counting… :) With http://www.peopleschoice.com/pca/votenow.jsp being the top one...

11:55 raek: scanning tweets for urls?

11:55 fliebel: yea :)

11:55 Making my private crows sourced news source :)

11:56 vic_nyc: I guess not..

11:57 fliebel: vic_nyc: I stored a timestamp in congomongo once, but nothing beyond that.

11:59 vic_nyc: thx fliebel, will keep looking for ways.

11:59 fliebel: vic_nyc: But try asking a more concrete question, like "if i store a java.date.time.whatever in a mongodb, what will I get back?"

12:00 vic_nyc: was wondering what the best way would be to store dates. I found some documentation that says that transforming dates into numbers would be best (most efficient)

12:00 (alternatively, using mongodb's datetime library would be terrible in terms of performance)

12:00 fliebel: yea, that is what I said about the timestamp

12:03 vic_nyc: I guess I was looking for a function that would map some kind of date object into a number representation, in a way that would still allow efficient queries

12:03 e.g. give me all records between these dates (where the datetimes have been mapped into numbers)

12:04 fliebel: What data representation are you thinking of? With a timestamp these are just simple larger-than and smaller-than queries.

12:04 *date

12:05 vic_nyc: a timestamp would be good. however the one in congomongo relies on objectid and in my particular project I'm not using Mongo's ObjectIds

12:06 fliebel: *puzzled look*

12:07 vic_nyc: http://download.oracle.com/javase/1.4.2/docs/api/java/util/Date.html#getTime()

12:14 vic_nyc: thx fliebel I think that may work quite well for what I need

13:01 silveen: Anyone here who uses vim+slimv.vim for developement?

13:23 Bronsa: seangrove: i used to

13:23 but it's terrible

13:30 TobiasRaeder: hey :)

13:30 is there an idiomatic way to conver the (keyword) keys of a map to their string values?

13:31 technomancy: TobiasRaeder: (zipmap (map name (keys m)) (vals m))

13:32 Vinzent: How can I get value from structmap inside macros?

13:32 fliebel: technomancy: What is this going to do to the order of the keys and value?

13:33 TobiasRaeder: @technomancy thx a ton

13:33 technomancy: fliebel: keys and vals is guaranteed to always be consistently ordered when called on the same map

13:33 fliebel: cool

13:33 technomancy: it's just that if you assoc more stuff onto the map the order may change

13:34 fliebel: I got into deep trouble with python in this way once. I admit I did something to them on the way though.

13:36 raek: Vinzent: like you would with a map

13:36 Vinzent: https://gist.github.com/676400

13:36 raek, I got nil

13:37 raek: Vinzent: you could use an ordinary function in that case

13:38 what happens now is that this is evaled: ['(struct q 1) (:a '(struct q 1))]

13:40 remember that what the macro gets as its parameter is the unevaluated code

13:41 Vinzent: raek, ok probably I should reorganize code, thank you

14:35 bobo_: anyone used appengine magic? change the number of fields in an entity and it doesnt work to store it with swank anymore, using dev_appserver works :-/

17:49 mattmitchell: I'm trying to call an instance method on a java object but having no luck

17:49 for one of the methods, I get "java.lang.ClassCastException (NO_SOURCE_FILE:0)"

17:49 and for another I get: "java.lang.IllegalArgumentException: No matching field found: toSolrParams for class org.apache.solr.client.solrj.SolrQuery (NO_SOURCE_FILE:0)"

17:50 but I know the methods exist, and the object I'm working with is an instance of the class

17:50 here's the code I have now:

17:50 (def sp (org.apache.solr.client.solrj.SolrQuery.))

17:50 (.toSolrParams sp)

17:50 (.add sp "one" "two")

17:51 anyone have any ideas?

17:54 raek: mattmitchell: from the javadocs it seems that the toSolrParams method is static

17:55 mattmitchell: (import 'org.apache.solr.client.solrj.SolrQuery) (SolrQuery/toSolrParams sp)

17:55 if sp is an instance of NamedList

17:56 pppaul: to map over a 2D vector i'm doing a map of a map... is there a better way other than flattening/partitioning?

17:56 raek: also, add seems to take an instance of SolrParams, rather than two arguments

17:59 mattmitchell: the syntaxes for method calls are as follows: (.instanceMethod object arg1 arg2 ...) (Class/classMethod arg1 arg2 ...)

18:15 mattmitchell: raek: there is also an add that takes 2 strings: http://lucene.apache.org/solr/api/org/apache/solr/common/params/ModifiableSolrParams.html#add%28java.lang.String,%20java.lang.String...%29

18:16 raek: does it make sense that I'd be able to just call that on the instance?

18:17 raek: you'right about the toSolrParams, my bad!

18:17 raek: hrm, I think variadic methods are special

18:18 you could try looking at the signature with clojure.contrib.repl-utils/show

18:18 I vagely recall that the "..." args are passes as an array or something

18:19 mattmitchell: raek: ok cool, i'll have a look. thanks for your help!

18:22 raek: usage example: (use '[clojure.contrib.repl-utils :only (show)]) (show java.lang.String #"toString")

18:22 KirinDave: So didn't chouser... I think it was chouser, have some thing about not using :only?

18:22 I never quite understood

18:24 raek: well, I think it's safer to use :only than bare use. if someone adds a new var to the namespace, you will not get any unexpected collisions

18:24 require is even safer

18:24 since it covers the case when things are added to clojure.core

18:25 KirinDave: I agree.

18:32 miltondsilva: Hi, the spit function in clojure core is very interesting but, is there some way to spit bytes on a clojure seq.. or on a byte-array?

18:39 ohh.. wait.. java already does that.. sorry

18:53 lrenn: anyone have a clojure 1.1 repl handy?

19:02 kumarshantanu: hi, can anybody tell how to configure log level using c.c.logging?

19:02 I want it to be DEBUG

19:27 wooby: kumarshantanu: there's a 'debug' in logging you can use

20:26 kumarshantanu: wooby: debug log is not visible somehow

20:26 only INFO is visible

20:27 need to change some default setting?

20:29 pppaul: $8ball 8balls?

20:29 sexpbot: pppaul: Very doubtful.

20:43 stuartsierra: kumarshantanu: It's configured in the logging implementation you use.

20:54 pppaul: can someone point me to a tutorial / examples of using types and records? the clojure.org site just explains them, but doesn't give examples (that i can see)

20:55 &(#(% %) #(% %))

20:55 sexpbot: java.lang.StackOverflowError

20:58 dnolen: pppaul: http://freegeek.in/blog/2010/05/clojure-protocols-datatypes-a-sneak-peek/

20:58 pppaul: thanks

20:58 these work as of 1.2 right?

20:58 dnolen: pppaul: yup

20:58 pppaul: what is special about 1.3?

20:59 dnolen: pppaul: changes to binding, primitive math support the biggest things

20:59 pppaul: interesting

21:00 so, as clojure.org tells me, i should not be using genclass?

21:00 $8ball should i use genclass?

21:00 sexpbot: pppaul: Ask again later.

21:01 stuartsierra: pppaul: genclass is still necessary for some kinds of Java interop

21:01 pppaul: such as?

21:01 stuartsierra: subclassing a concrete class

21:01 pppaul: ~_^

21:01 clojurebot: everyday is Rich Hickey Appreciation Day

21:02 pppaul: i'm glad that i'm rich hickey appreciation day

21:02 oh

21:02 everyday

21:02 why did clojurebot say that?

21:02 making clojure seem like a cult

21:03 i just happen to love cults

21:11 mattmitchell: is there something special i have to do when calling a java method that is defined with varargs?

21:12 _ato: mattmitchell: pass it an array of the variable arguments

21:12 Java's "..." stuff is just syntax sugar for passing an array as the last argument

21:12 mattmitchell: _ato: i see. so, i tried doing: (.method obj (to-array "arg1")) -- is that correct?

21:13 _ato: (to-array ["arg1"])

21:13 otherwise you'll get an array of characters

21:14 mattmitchell: _ato: ahh ok

21:14 _ato: you might also want into-array instead of to-array, unless the variable argument is of type "Object"

21:14 mattmitchell: _ato: awesome, into-array did the trick. thank you!

21:15 _ato: :)

21:48 cemerick: stuartsierra: ping

21:48 bleh

22:07 stuartsierra: talios?

22:11 talios: stuartsierra: Are you able to run 1.6 on the server, then use maven-toolchains-plugin ? http://maven.apache.org/guides/mini/guide-using-toolchains.html

22:11 stuartsierra: yeah, we'll try that

22:12 Can that be configured but still permit anyone else to build on any supported JDK?

22:12 cemerick: hrm, hopefully hudson can autogenerate that toolchains.xml file…

22:12 stuartsierra: i.e. don't force users to have 1.5 intsalled

22:12 talios: You could enable that in a profile

22:12 stuartsierra: if they want to build locally

22:13 yeah

22:13 cemerick: talios: good afternoon (or whatever) :-)

22:13 stuartsierra: just would rather not complicate the POM any further

22:13 talios: afternoon :) 4:16pm

22:13 * talios nods - understandable.

22:13 talios: a profile in ~/.m2/settings.xml should work fine.

22:14 stuartsierra: that's a thought

22:14 cemerick: (inc talios)

22:14 sexpbot: ⟹ 1

22:14 * talios feels empowered. and lonely. 1 is so lonely.

22:14 stuartsierra: (inc talios)

22:14 sexpbot: ⟹ 2

22:15 talios: :)

22:17 cemerick: see my reply about that maven-find-plugin ? ( re source dirs of deps ) I think that'll be too messy tho, I think anything that resolves source dirs from dependencies should be separate from the pom.xml,

22:18 cemerick: talios: saw the email, haven't looked at the link yet

22:18 AFAICT, this would not be in the pom

22:18 i.e. it shouldn't affect proper builds

22:18 talios: *nod*

22:19 cemerick: totally a local-environment thing; so, just a property (perhaps falling back on a env var lookup for shell types that like to set such things) would be ideal

22:19 It all seems creepy to me, but I'm trying to keep the hurdles low

22:20 talios: however it works, I was thinking "walk our poms dependencies, for each GAV - *resolve a source dir somehow* - replace the classpath entry with that

22:26 stuartsierra: ok, too sleepy to write any more XML right now

22:31 If it's possible to get the plugin to target 1.5, it will be very helpful to the Clojure core release process!

Logging service provided by n01se.net