#clojure log - May 31 2010

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

4:33 LauJensen: Morning all

4:34 Quiesce: Hello

4:37 bobo_: is there any webframework for clojure that separates the view as strongly as lift/wicket? ie, you cant write any logic at al in it.

4:39 Fossi: why can't you do that in wicket?

4:39 you mean the html template?

4:39 bobo_: yeh, you can separate it entierly if you want to

4:40 Fossi: hmmm. haven't seen a templating framework yet

4:42 bobo_: could probably use wicket, i think il have a look at that

4:46 Fossi: bobo_: if you do i'd be interested how that feels

4:46 tomoj: with enlive, you have the html in a separate file

4:46 then write some clojure which transforms the html

4:47 no clojure in the html files at all

4:47 LauJensen: Fossi: Did you see my latest blogpost?

4:47 I've built bestinclass.dk entirely on Enlive templates and the Moustache micro-webframework, meaning 100% separation of logic and html/css

4:47 Fossi: LauJensen: nope, could you link?

4:48 LauJensen: http://bestinclass.dk/index.clj/2010/05/refresh-your-cache--best-in-class-has-been-baked.html

4:50 Fossi: jupp found it :)

4:50 looks sane

4:50 LauJensen: Thats a plus

4:51 Fossi: but still i wonder what wicket feels like from clojure. i used them both for zuite a while, but never together

4:51 *quite

4:51 unfo-: LauJensen, oh cool! thanks for link

4:52 LauJensen: np

4:52 And I really should hurry up and opensource the code, it has a Wordpress -> Hthml converter, Atom feed generator, backend for posting and moderating comments

4:56 unfo-: what was this format-> [:body :> any-node]

4:57 LauJensen: Its selectors, similar to CSS but prefixed with :, so body > any-nody, means match any node directly under a body tag

4:58 unfo-: aaah css-style

4:58 LauJensen: http://enlive.cgrand.net/syntax.html

4:59 unfo-: ah thanks

4:59 and also... my clj-fu has been written to swap in mah brainz

4:59 >_>

5:00 need to reapply learning ^_^

5:20 rava: greetings programs

8:49 dnolen: hmm if I want to extend-type int[] how can I refer to that as a class ?

8:59 spariev: hi, I need a function which takes a list of pairs on ints and 'concat' neighbour pairs together, ie ([0 2] [2 4]) becomes ([0 4])

8:59 here's my take http://gist.github.com/419810

9:00 could it be made more simpler ?

9:04 candera: spariev: You could partition and then do a destructuring binding against the result.

9:04 Although I'm not entirely sure what algorithm you're trying to implement.

9:05 Licenser_: spariev: you don't have all specs, what happens if neighboring pairs do not match?

9:07 spariev: Licenser_: you just leave them as they were, ie ([2 4] [6 7]) => ([2 4] [6 7])

9:11 candera: So is it equivalent to flattening it and then removing any duplicates? Or will you ever wind up with pairs that have two elements the same?

9:13 spariev: I need this to corrently build a Lucene query with OR clauses. I have a vector with conditions, which can contain :or , like ["foo" "bar" :or "baz" :or "biz" "chunky bacon"]

9:14 So I have to structure this vector into something like ["foo" [:or "bar" "baz" "biz"] "chunky bacon"]

9:15 bartj: spariev: I thought ([2 4] [6 7]) would give ([2 7] [4 6]) - care to explain the definition of "neighbourhood"?

9:20 spariev: bartj: it seems like I was quite unclear, my apologies. by the "neighbour pairs" I meant pairs like [2 4][4 6] , where the last item of first pair is equal to the first item of next pair

9:21 candera: yep, you are right, flatten and remove duplicates will suffice

9:21 thanks all, sorry for the unclear question

9:23 candera: spariev: Are you sure? If you flatten and remove dups from [0 2] [2 4] [4 4] [4 6], you'll get [0 6]

9:23 Is that what you want?

9:23 spariev: yes, there wont be pairs like [4 4]

9:24 candera: OK. Was playing with the underlying problem (queries with :or) but didn't get anywhere.

9:29 spariev: candera: thanks. my idea is to find indices of all conditions with :or near them, so ["foo" "bar" :or "baz" :or "biz" "chunky bacon"] will give [1 3] [3 5]

9:29 candera: I see.

9:30 I was going at it from the direction of partitioning the original sequence with overlap, and looking at whether the subsequence has :or in it.

9:31 Yours makes sense to me. But then again I fully expect someone else to say, "Oh, you just call these two functions on the original sequence." :)

9:32 spariev: candera: heh, completely forgot about overlap param in partition. that's the solution I'm looking for :) thanks

9:33 candera: I'll be curious to see your final code.

9:34 spariev: ok, I'll update gist when it will be ready

10:33 lessthantristan: i'm putting together a job queue. i have a ref counting the number of running jobs, and a (ref []) for the queue of waiting jobs. since i'm doing things like (if (> max-jobs @running-jobs) ... (dosync (alter ...))) in my add-job and finish-job, i should be wrapping the whole function in a dosync rather than just the bits where the refs are altered, correct?

10:34 opqdonut: yeah

10:35 otherwise you can accidentally go over the maximum job number

10:39 lessthantristan: cool thanks. are all dosync calls linked, or is each one managed separately? i'm worried that my different add and finish job functions, which both read and manipulate the refs still might cause concurrency issues

10:40 hmm. maybe some testing is required, i'm seeing lots of possible future problems with what i'm trying to do :)

10:48 Licenser_: lessthantristan: if you have multuiple dosync calls within eachothyer they all count as one transaction

10:58 spariev: candera: here's what I finally came up with - http://gist.github.com/419810

10:58 feels kinda wordy, but works

10:58 I tried to do it via partition with overlap, but decided to stick with my original idea in the end

10:58 Chousuke: more succinctly put: transactions have dynamic scope

12:09 SinDoc: [naïve] How can I use the bindings provided e.g. here [1] in another file?

12:09 [1] http://github.com/sindoc/algorithms/blob/master/src/main/clojure/whiteboard/y2010/hide-adt-state/datatype-01.clj

12:27 cgrand: SinDoc: add (:require [com.khakbaz.algorithms.clojure.whiteboard.y2010.hide-adt-state.datatype-01 :as d]) to the ns declaration in your other file

12:27 then d/op-a will reference op-a etc.

12:28 SinDoc: How does Clojure know where to find the file where that namespace is defined?

12:29 bozhidar: same way as for java packages

12:29 cgrand: they must be on your classpath

12:29 bozhidar: the namespace reflects a particular

12:29 directory structure

12:30 the root of which should be available in the classpath

12:30 unless you have jar packaged code that is

12:32 SinDoc: Thank you, cgrand and bozhidar.

12:48 noidi: d

12:49 oops, didn't mean to write that :P

13:14 LaPingvino: hello

13:14 hello Lau

13:15 what was the date of that european Clojure stuff again, and where?

13:15 LauJensen: LaPingvino: June 23-25 in Brussels - All the details incl. schedule are on conj-labs.eu

13:16 hugod: I'm having problems modifying code at the repl - Could someone try entering http://gist.github.com/420007 at a 1.2-master-SNAPSHOT repl and comment on the result

13:16 LaPingvino: LauJensen: tnx :)

13:18 LauJensen: LaPingvino: np - Let me know if you need anything else :)



13:18 hugod: I see 'b'

13:19 hugod: LauJensen: thanks, what is the date on you snapshot?

13:19 LauJensen: hugod: can the repl tell me ?

13:20 Its 20100427.170231-51

13:20 hugod: LauJensen: I'm seeing this on shapshots after around 20100521

13:22 LauJensen: hugod: Time to roll out --bisect

13:25 hugod: LauJensen: thanks :) I'm also having issues with redefining multimethods; presumably related somehow

13:26 LauJensen: hmm

13:26 Fortunately you've got a simple way to test, so a bisect run shouldn't take long

13:26 hugod: Lunch first :)

13:37 Licenser: cooookies!

13:51 naeu: I'm just having a play with reify. I'm trying to reify a particular interface: http://users.frii.com/jarvi/rxtx/doc/gnu/io/SerialPortEventListener.html

13:52 However, I don't seem to be having much luck with the following: (reify gnu.io.SerialPortEventListener (serialEvent [e] (println "hi")))

13:53 I get the error: "Can't define method not in interfaces: serialEvent"

13:55 LauJensen: hugod: HTH, bisect log http://gist.github.com/420075

14:13 naeu: is there any way to inspect a Java interface from Clojure

14:13 it would be nice to see how Clojure sees a particular interface, i.e. what methods it thinks it requires to be implemented...

14:13 LauJensen: naeu: You can inspect anything Java using C-c I

14:14 tomoj: clojure.contrib.repl-utils/show

14:14 naeu: LauJensen: how cool is that!

14:15 LauJensen: naeu: Its pretty high on the list :)

14:16 naeu: OK, so it still doesn't explain why I can't reify this particular interface - the emacs inspection gizmo says that the interface has one method: serialEvent and my reification form just contains that

14:17 LauJensen: naeu: but its not your method being run ?

14:18 naeu: LauJensen: I'm trying to reify this: http://users.frii.com/jarvi/rxtx/doc/gnu/io/SerialPortEventListener.html

14:18 using this form: (reify gnu.io.SerialPortEventListener (serialEvent [e] (println "hi")))

14:18 tomoj: naeu: the inspection gismo says serialEvent takes one param?

14:18 naeu: the gizmo says this: public abstract void gnu.io.SerialPortEventListener.serialEvent(gnu.io.SerialPortEvent)

14:18 tomoj: oh, maybe you need a self param for reify?

14:19 naeu: tomoj: that didn't fail...

14:19 LauJensen: Its been changed not too long ago I think, but reify takes an explicit this argument now

14:19 tomoj: I mean, try (serialEvent [l e] ...)

14:19 hugod: LauJensen: thanks for the bisect

14:20 LauJensen: n

14:20 p

14:20 naeu: interesting, it doesn't appear to be in the docs...

14:20 tomoj: heay, i tried (serialEvent [_ e] ...)

14:21 tomoj: s/heay/yeah

14:21 LauJensen: naeu: How are you determining that you're failing ?

14:21 naeu: LauJensen: Emacs is complaining when I eval it in slime

14:22 but if I add an initial anonymous param like tomoj suggested the eval completes successfully

14:22 tomoj: naeu: same error?

14:22 ah, yes

14:22 LauJensen: naeu: tomojs suggestion is the correct form

14:22 tomoj: then what's the problem? :)

14:22 naeu: none, now, it seems :-)

14:22 i said it didn't fail :-)

14:22 tomoj: ah, I see

14:22 the first parameter is the object itself

14:22 naeu: sure a this/self param

14:22 tomoj: the one which will have a .serialEvent method I mean

14:23 mrTrololo: Hi! Tell me please how can I use my "do" if I have something like this: (let [do println] ...)

14:23 naeu: right, i'm off out for a walk now, i'll get back to this later

14:23 thanks so much for the help LauJensen and tomoj

14:23 LauJensen: np

14:23 $(let [do println] (do "hello"))

14:23 sexpbot: => "hello"

14:24 mrTrololo: I mean do will work as println inside binding

14:24 LauJensen: Thats right

14:25 tomoj: no..

14:25 $(let [do +] (do 1 2))

14:25 sexpbot: => 2

14:26 tomoj: also..

14:26 LauJensen: hmm

14:26 tomoj: $(let [do 3] do)

14:26 sexpbot: => nil

14:26 tomoj: :)

14:26 I can explain the former but not the latter

14:26 LauJensen: I dont get that

14:26 tomoj: do is a special form

14:27 so you can't replace it with let

14:27 not sure why a lone do is allowed inside let, though.. I remember it being discussed here before but don't remember the explanation

14:27 $(let [] do 3)

14:27 sexpbot: => 3

14:28 tomoj: something to do with the implicit do I guess

14:28 LauJensen: I didn't consider that its a special form

14:28 And Im not sure why it needs to be

14:28 ,source do

14:28 clojurebot: java.lang.Exception: Unable to resolve symbol: source in this context

14:28 LauJensen: $source do

14:28 sexpbot: Command not found. No entiendo lo que estás diciendo.

14:29 tomoj: hrmmm

14:29 $(let [let 3] let)

14:29 sexpbot: => 3

14:29 tomoj: wat?

14:29 clojurebot: For Jswat: start clojure with -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8888

14:29 tomoj: let is a special form too

14:29 so "do is a special form" is not an explanation

14:29 $(let [let +] (let 1 2))

14:29 sexpbot: java.lang.IllegalArgumentException: let requires a vector for its binding

14:29 tomoj: well, that works for me in 1.2

14:29 (i.e. it returns 3)

14:30 mrTrololo: really strange

14:30 kotarak: LauJensen: I think you need proxy to handle abstract methods. But I'm not sure.

14:31 LauJensen: kotarak: re the reify issue?

14:31 kotarak: tomoj: It should work, because the "real" let special form is let*. Not so for do.

14:31 LauJensen: yes

14:31 tomoj: kotarak: aha

14:32 kotarak: tomoj: let is macro adding destructuring and stuff.

14:32 tomoj: but it should be treated as special form

14:32 LauJensen: kotarak: Ah I think you're right actually

14:32 tomoj: ?def let

14:33 kotarak: ~source let

14:35 tomoj: strange

14:35 so (doc let) special cases it and calls it a special form, I guess?

14:36 even though it's really a macro

14:36 kotarak: tomoj: it should be treated as special form

14:44 LauJensen: hmmm.... Why should the interface have an abstract method? I don't think, that's what happens. There is something else going on.

14:47 Borkdude: Is there something like with fn (foo [coll] ...), (op foo x1 x2), op like apply, but the other way around?

14:48 raek: the other way around? can you show an example?

14:49 tomoj: (foo [x1 x2]) ?

14:49 Borkdude: I mean, foo expects a coll

14:49 but I don't want to wrap x1 and x2 inside a coll

14:49 like with apply, when it the fn does not want a coll, but direct args

14:50 tomoj: why don't you want to wrap? just curious

14:50 Borkdude: because I'm too lazy

14:50 kotarak: (defn unspread [f & args] (f args)) (unspread foo 1 2 3)

14:51 Borkdude: for example I want to do this: (merge-with (fn [r l] r) {:foo "Lucy"} {:bar "Ethel"} {:bar "Ricky"})... I can't pass just the first function, because first expects a coll

14:51 and or isn't a function, so that doesn't work either

14:52 tomoj: interesting

14:53 so with (defn unspread [f] (fn [& args] (f args))), (unspread first) would work?

14:54 Borkdude: This works: (merge-with (partial unspread first) {:foo "Lucy"} {:bar "Ethel"} {:bar "Ricky"})

14:54 kotarak: (apply merge (reverse {:foo "Lucy"} {:bar "Ethel"} {:bar "Ricky"}))

14:55 tomoj: (partial merge-with (partial unspread first)) == merge, I think

14:57 Borkdude: (defn unspread [f]

14:57 (fn [& args]

14:57 (f args)))

14:57 kotarak: tomoj: merge merges left to right. So right wins. So probably (partial merge-with (partial unspread second)) => merge

14:57 Borkdude: (merge-with (unspread first) {:foo "Lucy"} {:bar "Ethel"} {:bar "Ricky"})

14:57 tomoj: oh, yeah

14:58 that unspread is kind of interesting

15:04 Borkdude: I'm not sure about the name though

15:06 why not unapply?

15:06 or deply? :)

15:09 uncoll

15:10 I think I like that one

15:11 because usually the argname in things like first is coll

15:11 and it sounds a bit like 'uncall' which is close to 'unapply' in meaning

15:17 tnx for the help. gtg again

17:42 Raynes: technomancy: Ping.

17:44 * Raynes just replies on github. Never has much luck pinging Phil. ;)

17:44 technomancy: Raynes: sorry, I'm on the phone

17:45 a github message is good

17:45 Raynes: technomancy: It's cool. I'll just reply on github. :p

18:04 zakwilson: I'm trying to use lein remote-swank. It looks like it's working, but no java process is running on the remote machine.

19:34 Ankou: hi, I have a map with a :type metadata and I defined a print-method on it. So when I now write (print m) it prints correctly but when I write (print (with-meta m {:type nil})) I get an clojure.lang.LazySeq cannot be cast to clojure.lang.IFn exception. How can this be?

19:35 I mean, I thought print should always print something and never throw an exception like this one?

19:40 anyone?

21:52 jweiss: hi, i keep trying to use map, when not all the data i need to process is in the seq i'm passing to map. for instance, i want to add metadata to each item in a seq, but the metadata obviously isn't in the seq, it's in a different one. what's the functional way to do this

21:57 zakwilson: jweiss: pass both seqs and a function that takes two args to map.

21:58 jweiss: zakwilson: ah yes, i keep forgetting that map can take more than 1 coll :) thanks

22:26 mebaran151: I just reinstalled my linux installation and am having a little bit of trouble re-setting up emacs

22:26 I'd like to set up Clojure Slime to work with the new Clojure 1.2, but even the release versions are throwing strange errors

22:27 particularly wrong number of args passed to basic$eval#compile-file-for-emacs

22:36 bhenry: membran151 what linux installation?

Logging service provided by n01se.net