#clojure log - Nov 13 2009

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

0:06 defn: If I have a big list of words like '("book", "shoe", "house",...), how can I use filter to get the list of words that are 3 characters

0:06 I imagine it looks something like (filter (= (count (map #(seq %) word-list)) 3))

0:07 hiredman: uh

0:07 nope

0:07 defn: hiredman: i love you for all of your help

0:07 hiredman: (filter (comp (partial = 3) count) list)

0:08 (filter #(= 3 (count %)) list)

0:08 defn: what is comp

0:08 hiredman: compose

0:08 defn: the force is strong with you

0:10 hiredman: thanks for your help

0:11 hiredman: what is the best way to represent a list of 2000 strings in clojure? Is it the same if I use a list or a vector here? A list is probably best, yes?

0:12 hiredman: defn: sure

0:13 if you don't need index access then use a list

0:13 defn: hiredman: your gists are really great btw

0:13 lots of interesting clojure in there

0:13 thanks

0:14 hiredman: :)

1:02 duncanm: la la la

1:08 hiredman: ~ping

1:08 clojurebot: PONG!

1:08 Raynes: ~pong

1:08 clojurebot: Titim gan éirí ort.

1:22 defn: I could use a little help on something

1:25 G0SUB_: defn: ask

1:25 defn: G0SUB_: im torn between asking and continuing to work at it

1:26 but basically I was wondering if someone could explain to me the recur/loop forms

1:26 I don't really understand how those work

1:26 G0SUB_: defn: sure.

1:27 defn: loop establishes some binding and a recursion point, recur sets new values for those bindings and jumps back to that recursion point with new bindings.

1:28 defn: does that help?

1:28 defn: im also really struggling to understand a way to a create a lazy sequence of something by using lazy-seq -- like let's say i have this setup: (* (/ 1 2) n (+ n 1)) -- let's say i want the first 100 values of that sequence starting at 1, how do you write that?

1:29 G0SUB_: sort of, could you write a short piece of code and sort of step from the inside out?

1:29 like (loop [a 1] (+ a 1) (recur ??

1:30 G0SUB_: defn: come here, I will explain - http://etherpad.com/VSekWefWtV

1:43 tomoj: I rather dislike etherpad :(

1:52 somnium: tomoj: how come? first time I've seen it its kind of cool, multi-player notepad++

1:55 tomoj: yeah it's cool I guess

1:55 but I like IRC better

1:56 somnium: i like the shared code buffer thing anyway

1:59 ngoc: Hi, (slurp f) = Reads the file named by f into a string and returns it. Why the word "slurp" is used? Does it have a special history?

1:59 somnium: slurp is the sound people make when they eat noodles

1:59 think of ramen

2:00 wooby: is reduce lazy?

2:00 somnium: no

2:00 danlarkin: how could it be

2:01 somnium: i saw a lazy reduce somewhere, in contrib maybe

2:01 wooby: i would think the 2 argument form could be

2:01 somnium: its much more performant by not being lazy, and usually you want to realize the whole thing

2:02 the lazy variant i saw conses onto a collection, so it makes more sense

2:02 wooby: (take 10 (reduce (fn [xs y] (conj xs (+ (last xs) y))) [0] (iterate inc 1))) was what i wishfully came up with

2:03 hiredman: wooby: reduce can only be lazy in a language that has a lazy evaluation (haskell)

2:04 wooby: ahh i get it

2:04 because reduce would somehow need to pass on the 'knowledge' that the underlying list generation is happening lazily?

2:05 hiredman: in your eample reduce turns into something like (conj (conj [0] 1) 2)

2:05 wooby: aha

2:06 hiredman: the other thing to keep in mind is vector s are not lazy

2:06 the only lazy thing in clojure is lazy-seqs

2:06 wooby: so if it were haskellish take would trigger un-nesting lazily? whereas on jvm that's just stack overflow

2:06 ok

2:06 ok that is very awesome to know, thank you

2:08 btw hiredman i saw your php lisp thing on the github there, how's that going? looked like you'd started on compilation

2:10 hiredman: wooby: I haven't touched it in sometime

2:10 actually I was just thinking about it again

2:15 wooby: ,(take 10 (rest (map first (iterate (fn [[a b]] [(+ a b) (inc b)]) [0 1])))))

2:15 clojurebot: (1 3 6 10 15 21 28 36 45 55)

2:17 hiredman: I'd like to get compilation working

2:18 wooby: i was looking around the other day for a jvm in php, i think that would be 'ideal'

2:18 parrot seems to be as close as it gets though

2:19 hiredman: a jvm in php?

2:19 :|

2:19 somnium: i'm not sure if php is the best language to implement a jvm in

2:19 _ato: O.o

2:20 wooby: i find it not the best language for much of anything... except employment :l

2:23 hiredman: actually I wrtoe a little cache thing in php.lisp that I used for this little utility I wrote for a guy

2:24 so it's in use...

2:24 wooby: i have been reading it... i could really use it myself

2:29 _ato: http://technomancy.us/

2:29 ^ multiplayer emacs thing "rudel"

2:29 haven't tried it myself yet

2:29 G0SUB_: http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey

2:30 _ato: G0SUB_: hehe.. I have that on pause in another window :)

2:30 G0SUB_: _ato: I already have the video downloaded :)

2:40 qed: technomancy: You have some borked links on your Gobby/Ebby post.

2:46 gilbertleung: hi...

2:46 anyone around to answer a small question?

2:46 how do i set *out* to STDERR?

2:47 _ato: (binding [*out* *err*] .... ) ?

2:47 gilbertleung: cool!

2:47 _ato thanks again

2:47 (i just didn't know it's *err*)

3:12 noidi: is there anything new in the "are we there yet" presentation?

3:12 the first few slides look awfully familiar

3:13 i mean, really familiar, nothign awful about them :)

3:14 somnium: I think he explains very eloquently how stateful OO is a broken model of time in a general sense

3:20 defn: Someone needs to make github, but for connecting coders in shared buffers.

3:21 or connect it into github, so you can socially code

3:21 on a given repo

3:23 noidi: ah, the slides have been online since (at least) september http://wiki.jvmlangsummit.com/Image:HickeyJVMSummit2009.pdf

3:23 good, this means that I'm not going crazy and I've really seen the slides before :)

4:39 ordnungswidrig: hi all

4:42 Licenser: hi ordnungswidrig

4:42 hi rest of the world

4:42 Kjellski: Hi Licenser!

4:42 esj: Good Morning Clojurians.

4:43 Kjellski: Good Morning...

4:44 Could someone give me a hint why this doesn´t work? (.setPathName (javax.sip.SipFactory/getInstance) "nist.gof") Whereas this is giving me a SipFactory?(javax.sip.SipFactory/getInstance)

4:44 It just returns nil.

4:45 Licenser: I've a question, I try to use the jsch (Java SSH) library from clojure, I can connect send a command but when I try to read the output from the stream clojure hangs entirely :(

4:45 G0SUB_: I am trying to convert a nested combo of clojure maps and vectors to a bunch of different java datastructures which have their own constructors. what's the best way to do that?

4:46 this is for MongoDB interop. Maps should be BasicDBObject and vectors should be BasicDBList.

4:46 Licenser: G0SUB_: ask somnium he has done that already when I'm not wrong

4:46 G0SUB_: somnium: ping

4:46 somnium: Kjellski: .setPathName seems to mutate the instance, so youre getting the return value, you can use (doto (javax.../getInstance) (.setPathName "nist.gof"))

4:47 Licenser: hi somnium :)

4:47 G0SUB_: somnium: need a bit of help with the above problem.

4:47 somnium: G0SUB_: well, you could use my congomongo from github, or you could just use the ClojureDBObject class if you don't need the extra stuff

4:47 Hi Licenser :)

4:48 G0SUB_: somnium: link?

4:48 somnium: http://github.com/somnium/congomongo

4:48 G0SUB_: somnium: found it. thanks

4:49 somnium: you don't need to use BasicDBList apparently, or at least that's what the devs told me. Not sure why its there

4:49 G0SUB_: somnium: well, inserts work with clojure vectors, update doesn't

4:50 Licenser: if someone would be so kind and have a look at https://gist.github.com/74dff9294228f4300caa (problem is that I can't read from *ssh-in*) and I've no idea what I'm doing wrong

4:51 somnium: sadly I'll not really be using mongo so much any more, it is frustrating but since they nither do support my HW nor plan to ever do so I'll likely have to find an alternative

4:51 G0SUB_: Licenser: what hw are you using?

4:52 Licenser: G0SUB_: A Sun SPARC Server, and they don't want to support SPARC HW

4:53 they say making it run on the different endianity will make it slower for everyone else - I wonder how ever other major database works around this but it seems as mongo can't

4:53 somnium: does the java driver support multiple updates? I think DBList just creates an object like { 1 :foo 2 :bar }. I recall licenser doing something with $set to get around it

4:54 Licenser: they can't just make a special build?

4:54 Licenser: $set isn't good since it interfeers with indexes and does not work for this or that

4:54 somnium: how strange

4:54 Licenser: somnium: was my impression but they say no :P

4:55 somnium: well, couch seems a nice alternative

4:55 it could use a clojure map-reduce dsl for sure (hint hint)

4:55 Licenser: hehe

4:56 first I need to get the ssh stuff working :P that is work so it sadly has priority

5:01 k-factor: Hi, I'm just making my first steps with clojure (love the language), and I wonder if someone could take a look at https://gist.github.com/e6a04f4d63974fb37cc2 to make sure I'm in the right functional way of thinking?

5:05 Kjellski: Anyone got an idea of how to append things to the path in enclojure for a project?

5:06 somnium: Licenser: perhaps it should be wrapped in a with-open or similar? the only clojure io I've done has been with duck-streams

5:07 wooby: last statement results in NPE, thanks in advance for help: http://gist.github.com/233726

5:07 Kjellski: k-factor : I would recommend you to comment your functions a bit...

5:08 somnium: Kjellski: I think you can add libraries by right clicking on the lib icon in projects pane

5:09 (though I only tend to use netbeans when I find myself writing java)

5:09 Licenser: wooooh solved it!

5:09 somnium: nice, what was the trick?

5:32 CalJunior: on mutable data in go: http://bit.ly/4EGOFW

5:33 the question: "So, what's the right way of avoiding passing mutable structs or maps in channels?  I realize "don't do that" is an easy answer, but it's not very useful :)."

5:33 Kjellski: Is it correct that if I want an interface to be implemented in clojure I need a proxy? And where can I find a complex example of that?

5:34 CalJunior: the money quote anwer from Ian Lance Taylor: "It's the only answer we have so far, sorry"

5:36 somnium: do they even have constant types? (I know D has this with concurrency in mind)

5:36 CalJunior: yes

5:36 G0SUB_: I have only one java file in my clj codebase. how do I easily AOT compile that file?

5:38 somnium: G0SUB_: you just need to java -cp it with what ever clojure jars it needs, netbeans makes it pretty easy

5:38 G0SUB_: somnium: hmm

5:38 somnium: er, javac I guess, I let the ide write build.xml

5:39 G0SUB_: somnium: can't clojure import .java files?

5:39 Kjellski: Noone with a good example with a translated java implements to clojure translation? The more complex the better.

5:40 somnium: I'm not too up on compilation with clojure, sometimes order matters, so I've just split things into separate jars

5:40 _ato: for ; i < len(b) && !isDigit(b[i]); i++ { ... }

5:40 oh man... C-style for loops without parens give me motion-sickness

5:44 * Maddas agrees

5:45 CalJunior: :-)

5:45 Maddas: It's unfortunate to see how unnecessarily complicated and confusing the syntax in many other languages seems once you're used to more regular syntax :-)

5:45 (Unfortunate because you slowly morph into a smug lisp weenie, and this is just the first step)

5:46 _ato: hehe

5:46 somnium: G0SUB_: at least in my experience, when I've had clojure code on the classpath that needs to find a .class file ant always choked before it got started. So it was simpler just to have two separate builds.

5:47 I think Python will always have a reasonable second place for syntax :)

5:47 k-factor: Kjellski: thanks for looking, I've added a comment to the "main" function. I'm striving to make this code as compact and as easy to read as a Ruby version.

5:48 somnium: (even Paul Graham spoke at one of their 'lesser-language' conventions)

5:50 febeling: Hi. I have trouble accessing a static member dynamically, when I dont have the literal symbol.

5:51 Chousuke: febeling: you need to use the java reflection APIs or eval

5:51 febeling: ah, really? ok

5:52 Chousuke: but of course, the real problem might be elsewhere

5:52 febeling: so there is nothing like (. Level (symbol "ERROR"))

5:52 _ato: febeling: (eval `(. Math ~(symbol "PI")))

5:52 Chousuke: you really shouldn't need to do that.

5:53 febeling: what wrong with it

5:53 Chousuke: well... it's eval. :P

5:53 febeling: hehe, ok

5:53 Chousuke: what would you use this for?

5:53 susheel: quit clojure

5:53 febeling: but should i then resort to a cond?

5:53 Chousuke: maybe.

5:53 or perhaps a macro

5:54 febeling: the cond would be a bit like the C solution, it feels

5:54 not too dynamic

5:55 Chousuke: is the string defining the symbol known only at runtime? :/

5:55 febeling: depends, but that was my initial idea

5:55 Kjellski: k-factor : Sorry, I´ve got to go... but I´ll look that up the next time...

5:56 Chousuke: febeling: I really can't tell whether making it dynamic like that is a good idea or not without knowing what the context is :/

5:57 febeling: well, i could read all static fields in advance and build a macro ofc

5:57 Chousuke: you can also use reflection in a macro.

5:57 and produce code based on the reflection :)

5:57 G0SUB_: somnium: how do I convert a mongo datastructure to clojure map using clojuredbobject?

5:58 febeling: Chouske: thats i meant

5:58 somnium: G0SUB_: .toClojure

5:58 Chousuke: I guess eval is sometimes needed for some things but I haven't encountered any :P

5:58 G0SUB_: somnium: how to I create a clojuredbobject from a basicdbobject?

5:59 somnium: hmm

5:59 haven't done that much

5:59 but (doto clojuredbobject (.putAll basicdbobject) should work)

5:59 G0SUB_: somnium: hmm

5:59 _ato: Chousuke: it's needed for clojurebot! :p

6:00 somnium: usually I've set every collections class to clojure dbobject so no conversion needed

6:01 some operations unfortunately still return basicdbobjects, like json/parse and errors... working on a patch for the java driver but its a bit messy and not quite a priority

6:01 _ato: febeling: but yeah, generally it's better to do that sort of stuff at compile-time if possible. reflection/eval is slow and messy

6:02 Chousuke: _ato: right. because clojurebot is a repl :P that doesn't count.

6:02 febeling: _ato: if it is not in the inner loop i don't really bother about speed, tbh. thanks for the eval line

6:03 Chousuke: in clojure.core there's at least definline which uses eval.

6:05 _ato: although definline does it at compile-time

6:15 G0SUB_: somnium: did you mean .putClojure?

6:16 somnium: G0SUB_: .putClojure create a clojuredbobject from a persistent map

6:16 G0SUB_: somnium: I don't see putAll in the file.

6:16 somnium: basicdbobject is a java.util.HashMap so .putAll should probably be used

6:16 G0SUB_: ok

6:16 somnium: use repl-utils/show

6:16 its there, trust me :)

6:17 G0SUB_: somnium: :)

6:18 somnium: fantastic. works.

6:20 somnium: great

6:29 djpowell: is there any relationship between protocols and 'isa?' ?

6:31 _ato: djpowell: I don't think so

7:02 Licenser: hmm does with-open act as binding?

7:03 AWizzArd: no

7:04 Licenser: darn

7:07 hrm hrm

7:12 gerry`: how about google go language? i'm downloading now

7:13 ttmrichter: gerry`: What about it?

7:13 somnium: gerry`: it may be a nice host for clojure once it has better libraries

7:14 gerry`: does it use any vm like java?

7:16 ttmrichter: Well, considering that one version of it is a GCC front end, probably not.

7:16 eevar2: gerry`: once it has better libraries that java? ;)

7:16 *than

7:17 gerry`: it will be after twenty years :)

7:18 ttmrichter: 20 more years of the squiggly-brace hegemony? I'll just cut my wrists now, thank you very much. :D

7:21 gerry`: you mean parenthesis will rock forever? :)

7:22 Licenser: No one day we'll have compilers that understand plain english with typos!

7:22 (+ 2 2)

7:22 clojurebot: 4

7:24 esj: silly question: I'm defining a file with a namespace within which I want to use another, compojure. Individually I can do these things successfully, but (ns newspace :use 'compojure) tells me no. What am I doing wrong here ?

7:24 _ato: (ns newspace (:use compojure))

7:24 esj: bah !

7:25 _ato: yeah.. it's nuisance how it's inconsistent like that

7:25 esj: i'd preloaded by brain to think it was working like a map, on account of :reload etc

7:26 thanks _ato

7:28 Drakeson: is there an alias for the special form "." ?

7:30 _ato: Drakeson: as in like @ is (deref)? no it's just .

7:30 Drakeson: yes. thanks.

7:31 I find it a bit easy to miss (well, depends on the fonts, etc., but still)

7:40 Licenser: I've a problem with macros, I want to write a macro that wraps a ssh sessions I came up with https://gist.github.com/0362c56884446dfeb1a8 but I always get 'Can't let qualified name: user/config' when I try it on REPL

7:43 yason: Licenser: use config# instead of config, that'll create an automagic gensym

7:43 somnium: Licenser: also for session

7:44 Licenser: yason: I tried that but then when I have a second macro that is called within in-session it generates a different gensym for session :(

7:44 noidi: the :use, :require etc. options to ns are the worst part of clojure, imo

7:44 it seems to me that no one gets them right :)

7:44 somnium: ah, then you need to capture like: ~'session

7:50 Licenser: wooh thanks somnium that works

7:51 yason: Licenser: it's a bit unintuitive with regard to macros in many other lisps where symbol capture is the norm and you have to explicitly trick yourself out of it

7:52 Licenser: yason: I don't know other lisps ;) but well macros are kind of odd

7:53 hrm macros are silly

7:56 hrm hrm all not good

7:57 grr ~code evaluates to ((exec "ls")) narf

7:57 somnium: ~@code

7:57 clojurebot: Excuse me?

7:58 Licenser: I think I really suck :P

7:58 somnium: macros just take some getting used to

7:59 macroexpand-1 is your friend :)

7:59 Licenser: somnium: yap I used macro expand a lot but knowinf what all the ` ~ @ ' # mean is really confusing or even knowing they exist

7:59 hell yea! somnium you're my hero, it freaking works :D

8:00 somnium: try reading the source for 'for ;)

8:02 Licenser: ^^

8:02 now to understand how the ssh library hands stuff

8:02 it's crazy you create a ssh object a session object and a channel objectg o.O

8:18 febeling: coming back to static field access through name... http://clojure.pastebin.com/f32856ff9 anything dodgy with that?

8:26 chouser: ,(clojure.lang.Reflector/getStaticField "java.lang.Integer" "MAX_VALUE")

8:26 clojurebot: 2147483647

8:27 chouser: febeling: Clojure has to do dynamic access at various points automatically. You can manually use the same Reflector class it does.

8:28 febeling: chouser: thanks, i guess thats what i'm after

8:28 chouser: but yours is a macro, so now I'm confused.

8:29 febeling: mine would not give warnings on reflection use, would it?

8:29 chouser: do you know the name of the class and field at compile time?

8:30 febeling: the class yes, the fields only at runtime

8:30 or the one field

8:30 chouser: ah, I see

8:31 using Reflector to do the same thing won't generate a reflection warning either.

8:32 febeling: ok, so then it would be more natural to use that

8:32 chouser: your macro may generate code that runs faster than Reflection/getStaticField because you're taking advantage of the fact that you know the class at compile time.

8:33 (esp. when 'case' is available)

8:33 febeling: so a slight optimization, but probably not needed for confi/startup of an app, as in my case

8:34 thanks for the pointer :)

8:34 chouser: yeah, there can be some subtle issues using the reflection api -- probably not a big deal esp. for static fields, but in general it might be safest and easiest just to use Reflector.

8:41 febeling: btw: is reflector usage of reflection then generally exempt from the warnings, or how are the rules?

8:42 chouser: you only get the warning when the compiler itself at compile time generates some code that at runtime will do reflective calls for your java interop forms.

8:43 so (.foo bar) will get a warning if at compile time it doesn't know what class bar is.

8:47 febeling: and reflector does get around this in cases like the MAX_VALUE one above?

8:48 chouser: right. The compiler sees the class, so that's resolvable. There are only two methods with the name "getStaticField" so as long as it knows whether the first arg is a string or a class, it can generate code that will call that specific method -- no warning.

8:49 then at runtime the Reflector method gets called which in turn calls into the Java reflection classes, but that's all too late for a warning.

8:50 febeling: ok, i get it

8:53 so generally there is a lot of reflection going on, unless one puts the type annotation for arguments and meta for return types into place, is that correct?

8:54 (i mean at runtime now)

8:56 chouser: generally there is only reflection at runtime when you either do it manually or in places that generate warnings if you've got the warning on.

8:56 so if you turn on the warnings it ought to be pretty obvious where there will be runtime reflection

8:57 in practice I find that most of the time a few well-placed type hints can remove all runtime reflection from anywhere that's at all performance critical.

8:57 febeling: ok

8:59 Licenser: nice

9:00 https://gist.github.com/c9ef95778338d3c7da5a <- it's working :D

9:12 febeling: chouser: if that wasn't my conviction, i wouldn't use clojure actually :)

9:13 chouser: febeling: ah, not in favor of static typing then? :-)

9:13 febeling: nope :)

9:16 still like to have the option where it matters

9:17 chouser: I'm still ambivalent, but I'm happy I'm never forced to specify types and rarely need to for improved performance.

9:20 febeling: so much more to be gained from the time-memory tradeoff, in many cases

9:21 Chousuke: and no-one knows what the future will bring.

9:24 I suppose the ideal system would be something with which you can just assert facts about any piece of code and the compiler would use those assertions as a base for optimisations...

9:25 but it's easy to talk about. I have no idea how to actually implement anything like that, or what ramifications it would have on dynamicity

9:25 chouser: and for error checking at compile time.

9:25 I think that's actually what I want, but yes I can't really imagine how it would work.

9:25 I'm hopeful something similar is in rhickey's head and we'll all get to use it some day. :-)

9:26 I'm under the vague impression that's part of the point of the datalog work, but I don't understand how it all relates.

9:27 somnium: I wonder if some day a compiler will be written better than any human programmer, and all 'programming' languages will look like cucumber

9:27 rhickey: chouser: imagine once you have cinc, you run analyze, getting Clojure data structures, which you can stick into Datalog and query for anything that matters to you

9:27 febeling: that sounds interesting, i'll have to look into datalog

9:27 chouser: rhickey: ah!!!!

9:29 with access to any bits of assertion or requests for checking that I might happen to tuck away in form metadata here or there.

9:31 rhickey: chouser: right, basically it becomes completely extensible from the get-go

9:31 and people can do what they consider important, rather than what I do

9:33 chouser: with appropriate libraries of "normal" things available to start with and then extend as needed

9:34 Chousuke: clojure.contrib.optimizations :P

9:35 rhickey: Chousuke: not really about optimizations

9:46 ambient: btw rich's JVM summit 2009 keynote is up http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey

10:23 rhickey: should I put this on the wiki?

10:23 http://groups.google.com/group/clojure/msg/330c230e8dc857a9

10:24 ended up being a bit of a manifesto

10:27 patrkris: rhickey: i can't see why you shouldn't

10:28 djpowell: I currently have a java abstract class holding some data fields, and with accessors that provide calculated values, and a fixed number of subclasses that add extra fields and extra derrived accessors. I was wondering how I could move that to protocols and datatypes. Is there any replacement for implementation inheritance so that the common data and operations are available in all of the sub-types.

10:29 Chousuke: you can put the implementation in a map

10:29 and then give that map to anyone who might want to use it as a basis for their implementation of the protocol.

10:30 * Chousuke likes anthropomorphisation of code :P

10:32 ambient: so do a lot of other people who like oop

10:33 djpowell: Chousuke: ah, cool - that would work for the operations. I suppose there isn't an equivalent for the fields in deftype

10:33 rhickey: djpowell: not the fields, right

10:35 djpowell: rhickey: protocols now dispatch to subclasses - is there anything that they could do with derive?

10:37 rhickey: djpowell: If it were up to me, they wouldn't. This is strictly there for interop. Protocols do not use the derive/hierarchy sytem

10:37 system

10:38 for your fields thing, a mixin could specify it needs a certain set of fields and access them in its implementation fns

10:39 not the same as inheriting fields, but might be enough

10:42 djpowell: rhickey: sorry, I don't understand what you mean by mixin?

10:43 rhickey: djpowell: as Chousuke mentioned - mixins are fn maps you can reuse in extend calls

10:44 so if someone provided such a map, with the condition that - "this mixin presumes fields :mixin-foo and "mixin-bar" the deftype implementor could include those fields

10:45 djpowell: rhickey: ok - i'll take a look at how that would work out

10:45 rhickey: this has the same (closed) nature as derivation, as only the type author can add fields, but if moving from abstract superclass, that was the case there too

10:51 djpowell: tbh - I don't think I need the fields inheritted; the type will correspond to some database row, so I won't need to model the shared fields, they'll just be there

10:51 rhickey: sweet

11:06 chouser: rhickey: so, my finger trees are slower now than they were.

11:06 adding back some gen-interfaces to put the protocols :on could buy back some of that performance, right?

11:08 rhickey: chouser: right, should be identical with :on

11:08 chouser: did you say there as a possibility of eventually generating interfaces from defprotocol?

11:08 rhickey: I'm hoping to play with call-site caches for protocols to make that unnecessary

11:08 chouser: oh, ok.

11:09 rhickey: but I don't know that they will match until I do so

11:09 chouser: ok

11:14 djpowell: two protocols defined in the same namespace mustn't use the same names for methods?

11:14 chouser: right

11:15 djpowell: 'extenders' is cool

11:17 Kjellski: ~rhicker

11:17 clojurebot: Titim gan éirí ort.

11:17 Kjellski: ~rhickey

11:17 clojurebot: excusez-moi

11:18 Kjellski: rhickey : Are your clojure presentations made with LaTeX?

11:29 rhickey: Kjellski: no, Keynote + OmniGraffle

11:30 Kjellski: rhickey: Okay, that´s a pitty... I´m pretty frustrated with latex listings right now...

11:30 rhickey: chouser: so I've got that patch in here, but really dislike the warning (vs, say, an error)

11:31 Kjellski: rhickey : tried really hard to build up a latex listing language for highlighting but I´ve lost hours in documentation and finally give it up...

11:33 chouser: rhickey: really!? it seems like there are several dynamic situations where an error would be inappropriate.

11:34 bradford: ,(into (sorted-map) {:b 2 :a 1})

11:34 clojurebot: {:a 1, :b 2}

11:34 bradford: now how do i do something like this: (into (sorted-map-by #(compare (second %1) (second %2))) {:b 2 :a 1})

11:34 rhickey: the warning basically says - you've (already) messed up your environment

11:34 bradford: produce a sorted map from an unsorted map?

11:34 chouser: rename the protocol, reload the file, you would expect to get a big ol' list of warnings but it would be a shame to have to restart the JVM to do it.

11:35 rhickey: why would you have to restart the JVM?

11:36 chouser: if you got an error when trying to rename your protocol, what else would you do?

11:36 rhickey: oh, well we need a rename/remove protocol and a bunch of other things still

11:36 chouser: I guess you could manually unmap all your protocol-generated methods.

11:36 oh, ok.

11:37 so you want an error before anything's been changed, forcing some kind of manual un-def'ing first?

11:38 rhickey: I've just been waiting to se what they might be, certainly nuke an entire protocol, and remove an impl (unextend, retract?)

11:38 chouser: right, like:

11:38 ,(def String 42)

11:38 bradford: so what would be the easiest way to produce a sorted map from an unsorted map given a cparator?

11:38 clojurebot: DENIED

11:39 rhickey: argh

11:39 chouser: heh

11:39 ok, I can print DENIED

11:39 rhickey: heh

11:39 I've got your patch in, so I'll change it to a throw here

11:40 chouser: probably need to move the assert to before alter-meta! too

11:41 rhickey: the metadata flow has to be better overall, I'd like to preserve meta through to fn var

11:41 Kjellski: bradford : What you´ve written is not working?

11:41 ,(doc sorted-map-by)

11:41 cemerick: it seems like this is a specific case of the non-composability of the various options for defining vars (public or not, defonce or not, etc)

11:41 clojurebot: "([comparator & keyvals]); keyval => key val Returns a new sorted map with supplied mappings, using the supplied comparator."

11:42 cemerick: I mean, totally aside from the impl. details in the background.

11:42 chouser: bradford: are you trying to sort by the value of the key/val pairs? You can't really do that without putting the value in the key as well.

11:42 rhickey: cemerick: which, defprotocol? The names there flow through a lot of stuff, so just a quality of implementation thing

11:43 bradford: or you want a sorted set of the paris

11:43 pairs

11:45 cemerick: rhickey: yeah. It seems like defprotocol could just have the semantics of defonce by default, and have some option to push off existing vars in the ns. Anyway, my point was these sorts of questions are all too common in conjunction with new def* forms. It'd be nice if there were a common, composable mechanism for specifying semantics of such operations.

11:46 rather than a proliferation of def*, un-def*, tweak-def*, etc.

11:47 rhickey: cemerick: when people write those specific things they are just trying to get out of using the composable thing

11:47 metadata maps

11:48 cemerick: Yeah. That's frustrating to me :-)

11:48 patrkris: is it considered more idiomatic to use doseq than dorun?

11:48 drewr: ,Keyword

11:48 clojurebot: java.lang.Exception: Unable to resolve symbol: Keyword in this context

11:49 drewr: ,clojure.lang.Keyword

11:49 clojurebot: clojure.lang.Keyword

11:49 drewr: shouldn't that Keyword import automatically?

11:52 bradford: getting sorted pairs is no problem

11:53 ,(sort #(compare (second %1) (second %2)) {:b 1 :a 2})

11:53 clojurebot: ([:b 1] [:a 2])

11:53 bradford: the prblem is you can't follwo that with into {} of you lose sorted order gaurentee

11:53 so you avhe to use sorted-map-by in order to inejct your own comparator if you want to compare values

11:54 but that doesn't play nicely with the (into foo bar) interface

11:55 so that's the issue...arbitrarty orders of the kv pairs in a map is no pboem, its getting the pairs back into a map in sorted order that seems tricker than it needs to be

12:01 rhickey: bradford: a sorted map means sorted keys, not sorted values or pairs

12:01 technomancy: I noticed in the persistent hash map code there's a "nullValue" setting that you can use to override what's returned for gets for which that key is not present... is that exposed in Clojure at all?

12:01 rhickey: getting map-like performance and arbitrary sorting of values is wanting 2 different things at once

12:08 Chousuke: technomancy: (get themap key notfound)?

12:09 ,({:a 1} :b :FAIL)

12:09 clojurebot: :FAIL

12:15 bradford: rhickey: yea, you are right. this is actually just a special case where i am doing a little hack for visualizing some results at the repl. it is a map of features in the flight data to the values of how infomative each feature is about delays.

12:16 Chousuke: i don't like that overriding return behavior because it messes with another idea i had about map of fns.

12:17 chouser: drewr: java.lang.* is imported automatically, but not clojure.lang.*

12:17 bradford: but its convienient :-) 6 of one, half dozen of the other

12:18 technomancy: Chousuke: yeah, but I'm using this map in a call to update-in, so I'd like the nullValue to be attached to the map

12:19 Chousuke: bradford: sometimes, a nil is a valid value and you NEED some other "not-found" value :/

12:28 arohner: wow, clojure really alters your thinking. I'm reading some Java source today, and I was confused about how this java fn was returning values. Turns out, it was using mutable state, and it took me a minute to figure that out!

12:28 the-kenny: Is there something like filter, that lists the result of the predicate and returns a list of them instead of the original input-values?

12:29 arohner: the-kenny: map?

12:29 the-kenny: arohner: Yeah, but I want to filter for (pred x) = nil

12:30 ...maybe a (filter (comp not nil?) (filter pred lst)) will do it.

12:31 irumiha: hi everyone... I have a silly question... (def (symbol "s") "somevalue") throws "First argument to def must be a Symbol"... what am I doing wrong?

12:32 i thought thiws would be equivalent to (def s "somevalue")

12:32 arohner: irumiha: def is a special form. it doesn't evaluate the first argument

12:32 irumiha: ah, ok... didn't know that

12:34 arohner: you can write a macro that will do that, if you need to

12:34 though usually that isn't done

12:34 what are you trying to do?

12:35 chouser: the-kenny: (remove nil? (map func coll))

12:35 Chousuke: it's pretty easy, actually... (defmacro defstring [string & rest] `(def ~(symbol string) ~@rest)) ... but not very useful :P

12:35 irumiha: i am writing a macro that should up in (defn something...) with something being a String

12:35 the-kenny: chouser: Ah, thats more beautiful than my version. Thanks

12:39 irumiha: Chousuke: thanks, that pushed me in the right direction, now I'm off to create more problems :)

12:42 drewr: chouser: weird, I could have sworn I'd used bare clojure.lang classes before

13:45 Kjellski: ,(doc proxy)

13:45 clojurebot: "([class-and-interfaces args & fs]); class-and-interfaces - a vector of class names args - a (possibly empty) vector of arguments to the superclass constructor. f => (name [params*] body) or (name ([params*] body) ([params+] body) ...) Expands to code which creates a instance of a proxy class that implements the named class/interface(s) by calling the supplied fns. A single class, if provided, must be first. If not provid

13:47 IsaacL: (doc fmap)

13:47 clojurebot: "clojure.contrib.generic.functor/fmap;[[f s]]; Applies function f to each item in the data structure s and returns a structure of the same kind."

13:47 IsaacL: (doc map)

13:47 clojurebot: "([f coll] [f c1 c2] [f c1 c2 c3] [f c1 c2 c3 & colls]); Returns a lazy sequence consisting of the result of applying f to the set of first items of each coll, followed by applying f to the set of second items in each coll, until any one of the colls is exhausted. Any remaining items in other colls are ignored. Function f should accept number-of-colls arguments."

13:48 stacktracer: is there a spelled-out equivalent of ` (backtick)?

13:48 the way "quote" is equivalent to '

13:58 chouser: stacktracer: no

13:58 stacktracer: there may be eventually

14:00 Kjellski: How can I make a Javaish cast in clojure?

14:00 chouser: Kjellski: mostly you don't need to

14:01 Kjellski: Actually I don´t know wethere I need that cast or not... but it seems like: FromHeader from = (FromHeader) req.getHeader("From");

14:01 chouser: well, you don't need to declare locals, so for that line all you need is (let [from (.getHeader req "From")] ...)

14:02 declare the types of locals, I mean.

14:02 tomoj: why does java need that cast, I wonder?

14:02 clearly we want a FromHeader, we already said so at the beginning of the line

14:03 stacktracer: chouser: okay, thanks

14:03 Kjellski: chouser : That´s what I did, just thought that calling methods on that uncasted thing would be dangerous...

14:04 chouser: Kjellski: nope, not dangerous at all. You may want to type hint for speed, but that's strictly for performance not required at all.

14:04 Kjellski: chouser : Okay, thanks again... =)

14:07 Can I nest a function with an argument in the (.. macro ? Like a.b().c(foo).g; ?

14:07 chouser: yeah, but I recommend -> instead

14:07 (-> a .b (.c foo) .g)

14:08 Kjellski: chouser: *pressingthethankschouserbutton*

14:13 ordnungswidrig: re

14:13 * ordnungswidrig will drop some ruby code now and start implementation in clojure. wish me luck.

14:18 chouser: ordnungswidrig: good luck. but you won't need it. ruby->clojure is like going home.

14:23 weissj: is there a simpler way to predicate if an item is in a list besides (some (= item) list)

14:24 chouser: (some #{item} list)

14:24 Bjering: Hi, I just watched Rick Hickeys presentation "Are we there yet?" on infoq, I was intrigued but there are so many things I don't understand is this an ok place to ask about that?

14:24 weissj: chouser: i was thinking there'd be a contains? pred, but i guess not?

14:24 just for maps?

14:24 chouser: weissj: maps and sets.

14:25 weissj: chouser: ah ok i can use a set in this case. thx

14:26 cemerick: ooh, something just clicked for me on protocols

14:27 ambient: hmm, how did i check channel max users?

14:27 * cemerick can be slow sometimes

14:27 cemerick: ~max

14:27 clojurebot: It's greek to me.

14:27 ambient: ~maxusers

14:27 clojurebot: It's greek to me.

14:27 cemerick: ,max

14:27 clojurebot: #<core$max__4506 clojure.core$max__4506@1c39cb2>

14:27 hiredman: clojurebot's max users is kind of broken atm

14:27 cemerick: ah-ha

14:27 hiredman: clojurebot: max users?

14:27 clojurebot: It's greek to me.

14:27 ambient: it just peaked over 200

14:27 chouser: weissj: yeah, unless sets fail you in some way (you need to keep things in a particular order, for example) they're best for doing contains checks.

14:27 cemerick: that's pretty hefty for a language-focussed channel

14:28 hiredman: clojurebot: how much do you know?

14:28 clojurebot: I know 474 things

14:29 chouser: weissj: if you're really sure you want to do a linear seach across a list you can use the .contains method.

14:29 (.contains '[a b c d] 'c)

14:29 ,(.contains '[a b c d] 'c)

14:29 clojurebot: true

14:29 chouser: cemerick: just watch the google go video, it explains most of what you need to know about protocols.

14:29 :-)

14:30 cemerick: lol

14:30 chouser: you're really steamed about it, eh?

14:30 chouser: no, actually, that part amuses me quite a bit

14:30 clearly an idea whose time has come

14:30 the rest of it just makes me tired

14:31 jeremy_____: If I run (partition 5 (range 1 8)), I get ((1 2 3 4 5)). Is there an easy way to instead get ((1 2 3 4 5) (6 7))? I've looked at take, but I thought there might be an easier way to do this.

14:31 cemerick: I've not watched the video. I don't imagine I'm going to bother. Things are getting busier, amazingly enough.

14:31 hiredman: ~max people

14:31 clojurebot: max people is 202

14:31 chouser: cemerick: yeah, I was kidding. don't watch the video.

14:32 jeremy_____: there's partition-all in contrib

14:32 hiredman: maybe the max people thing isn't broken

14:32 jeremy_____: chouser: ah thanks!

14:33 chouser: jeremy_____: depending on what exactly you're trying to do, you might also look at split-at

14:34 stuarthalloway: okay if I create a branch on the official clojure-contrib to experiment with converting my contribs to deftype?

14:34 or should I hide out in my own corner of github

14:37 chouser: stuarthalloway: if the branch is for 'new' in general rather than your contribs in particular, then we can all share it

14:37 stuarthalloway: that was my thought

14:37 I have one gen-class to convert to deftype

14:37 but others probably will as well

14:44 piccolino: stuarthalloway: in an old clojure list post you mention that you were working on CSV parser. Did anything ever become of that?

14:45 stuarthalloway: piccolino: not much. got busy and used SuperCSV instead

14:46 hiredman: (yay code re-use)

14:46 piccolino: Ah, OK.

14:46 I guess I should have done that instead of writing my own.

15:15 lisppaste8: stuartsierra pasted "Simple deftype/defprotocol example" at http://paste.lisp.org/display/90329

15:18 hiredman: stuartsierra: nice

15:19 chouser: stuarthalloway: yeah, that's solid, thanks.

15:20 stuarthalloway: chouser: huh? ...

15:20 chouser: stuarthalloway: sorry, wrong stuart

15:20 stuarthalloway: chouser: I mean, yeah, thanks, I am the coolest Stuart around...

15:20 chouser: stuartsierra: that's solid, thanks.

15:20 :-)

15:21 stuartsierra: chouser: thx

15:21 It doesn't support mixing reals & complex's, not sure how that should work.

15:22 weissj: given a function that takes no args, how do i simply call it?

15:22 apply doesn't work here, afaict

15:22 stuartsierra: weissj: (foo)

15:22 chouser: to make it fit protocols you'd have to pull something like the kind of crazyness that is in the clojure.lang.Numbers

15:22 technomancy: so I posted to the mailing list a while back about having run-tests return true/false depending on whether all the tests passed or not.

15:22 weissj: so if i had a list of functions, i can do (map #(%) list) ?

15:22 technomancy: it's a one-line change and would really help w/ build scripts etc.

15:22 thoughts?

15:23 stuarthalloway: technomancy: agreed

15:23 stuartsierra: technomancy: There's a patch is marked ready to test on assembla.

15:23 stuarthalloway: though I am still hoping to just use circumspec

15:23 technomancy: stuartsierra: awesome; I somehow missed the followup on that.

15:23 stuarthalloway: technomancy: you in SF Bay area next week?

15:23 cemerick: there's already a map containing an :errors slot you can check, no?

15:24 technomancy: stuarthalloway: yeah, I'll be at rubyconf. was hoping to say hi there.

15:24 stuartsierra: cemerick: run-tests doesn't return anything by default

15:24 The patch changes that, and adds a "successful?" predicate.

15:24 stuarthalloway: technomancy: please do. Also I am running the 5k if that is your kind of thing.

15:24 technomancy: stuarthalloway: I wish. =)

15:25 stuarthalloway: I've been building a tool around lancet that I'd like your feedback on: http://github.com/technomancy/leiningen

15:25 cemerick: stuartsierra: ah, I had written my own run-tests long ago that does merge-with + across the results of test-ns.

15:25 stuartsierra: weissj: yes

15:26 weissj: stuartsierra: thx

15:26 stuartsierra: cemerick: that's what run-tests does internally, it just doesn't return the result, patch fixes that.

15:26 stuarthalloway: technomancy: did you see my email question about http client?

15:27 cemerick: once test-is gets ripped out, I'll make myself drop all of my old testing code :-P

15:27 stuarthalloway: technomancy: feedback #1 on leiningen: no need to compare with lancet. It is clearly just a spike

15:27 technomancy: stuarthalloway: yeah, I'm a bit backlogged on email. I think your change looks solid.

15:28 err, your idea for the change

15:28 stuarthalloway: technomancy: conjure is using lancet -- you should reach out to him as a key alpha user of leiningen instead

15:28 technomancy: ah, good idea.

15:29 I hear enough people ask about lancet to make me think that it's not clear to everyone that it's a spike even if it's clear to you and me. =)

15:30 ooh; this test patch would allow clojure-test-mode to be come simpler too; sweet.

15:31 stuarthalloway: technomancy: you should write a blog post about how lancet sucks, pillory me personally, recommend leiningen

15:31 chouser: what's a spike?

15:31 technomancy: stuarthalloway: it's the guaranteed way to get readership!

15:31 stuartsierra: I guess truly general arithmetic would have to use multimethods anyway. (defmethod add [:Real :Complex] ...)

15:31 technomancy: I would need to put ads on my site first though.

15:31 stuarthalloway: chouser: http://www.think-box.co.uk/blog/2006/01/spike.html

15:32 chouser: oh, man. That's all I ever write!

15:32 stuarthalloway: at Relevance we have abused the word spike to include any story card that doesn't deliver working code: experiments, estimation, documentation, what have you

15:32 chouser: except for my day-jobs I suppose.

15:33 stuartsierra: In other words, 99% of what all programmers produce.

15:33 stuarthalloway: chouser: find a free six weeks and come write some spikes here!

15:33 chouser: stuarthalloway: ask me again when the kids are too old to notice I'm gone.

15:34 dakrone: is there a way to do a reduce with more than 2 values at once? I want to do what's I'm describing here: http://pastie.org/697808

15:34 weissj: i thought lancet was pretty useful - couldn't find any other way to use any from clojure like that

15:34 cemerick: "why do you look so sad, little one?" "I'm a clojure-orphan."

15:34 weissj: s/any/ant

15:35 cemerick: sorry, it was funny in my head

15:35 stuarthalloway: weissj: useful, but not fully thought out

15:35 technomancy: weissj: it's useful as a library, but not as a build tool... check out leiningen for that. =)

15:35 chouser: hehe

15:35 weissj: technomancy: no i just wanted the equivalent of AntBuilder in groovy

15:35 stuarthalloway: unfortunately it is the only alternative i'm aware of :)

15:37 cemerick: I'm worried I might have to break down and give in to the maven hordes for dep. mgmt.

15:37 stuartsierra: dakrone: I think you need to break down and use a loop/recur

15:37 rhickey: hrm, protocols are not golang interfaces...

15:38 chouser: rhickey: hehe

15:38 dakrone: stuartsierra: okay, I'll try that

15:38 stuarthalloway: weissj: another alternative: http://twitter.com/stuarthalloway/status/5690154628

15:38 technomancy: cemerick: the maven-ant-tasks jar lets you add just the deps part of maven to a project without all the wacky stuff. (or you could use leiningen.)

15:38 chouser: it's taken a while, but I'm finally learning some ways to tweak rhickey.

15:38 stuartsierra: Maven is easy. Just do everything "The Maven Way." :)

15:38 technomancy: stuarthalloway: uh oh, I better get going whip this thing into shape!

15:38 cemerick: chouser: what's great is that the round trip on that one was at least ~an hour :-D

15:39 fogus_: chouser: His irrational fear of clowns?

15:39 weissj: stuarthalloway: ok, i meant to say at the time i needed lancet there was no alternative :)

15:39 cemerick: technomancy: well, then you just have ivy, essentially.

15:39 i.e. insofar as ivy and maven use the same repos

15:40 stuarthalloway: keeping up with other stuart, here is an example converting an existing gen-class to use deftype: http://bit.ly/1iuRAe. Trivial to do, which is good.

15:41 technomancy: cemerick: I found maven-ant-tasks to be easier to work with from an API level, but I guess that might not matter to you

15:41 wooby: has anyone played with using simple build tool with clj?

15:42 rhickey: stuart vs stuart - love it!

15:42 cemerick: technomancy: yeah, I've only cared about the ant targets

15:43 chouser: stuarthalloway: you couldn't use proxy because you needed a named class?

15:44 arohner: lisppaste8: url

15:44 lisppaste8: To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.

15:44 arohner pasted "invalid args?" at http://paste.lisp.org/display/90338

15:44 arohner: is that the error you get when you call a java fn with the wrong arguments?

15:47 hiredman: arohner: there are only clojure fns

15:47 arohner: fine. java method

15:47 hiredman: ,(.foo nil)

15:47 clojurebot: java.lang.NullPointerException

15:48 arohner: I understand how normally NPEs can be generated. I'm surprised at the <init> and Unknown Source

15:49 chouser: arohner: I doubt that's the whole of the backtrace

15:49 hiredman: <init> is maybe a static block?

15:49 lisppaste8: arohner annotated #90338 "untitled" at http://paste.lisp.org/display/90338#1

15:49 chouser: I think <init> is the name given to instance constructors internally

15:49 stuarthalloway: chouser: not sure if it has to be named or not -- probably

15:50 michaeljaaka: hi

15:50 can anybody give me an usage of function clojure.set/select ?

15:51 is there also any simple way to call select method without clojure.set namespace?

15:51 is there any import with :as x or something like this?

15:51 I'm trying to call (clojure.set/select #(= 2 %1) [ 1 2 3 4] )

15:51 but without success

15:52 hiredman:

15:52 michaeljaaka: what is pred ?

15:52 when I looked into set.clj

15:52 chouser: michaeljaaka: you probably just want 'filter' for that

15:52 michaeljaaka: I can see if (pred x )

15:52 chouser: ,(filter #(= 2 %1) [1 2 3 4])

15:52 clojurebot: (2)

15:52 michaeljaaka: no I'm just trying to figure out how to call select

15:52 hiredman: michaeljaaka: and what exception did you get?

15:53 stuarthalloway: (select #(< (.length %) 2) #{"a" "quick" "example"})

15:53 michaeljaaka: #<CompilerException java.lang.ClassCastException: clojure.lang.LazySeq cannot be cast to clojure.lang.IPersistentSet (NO_SOURCE_FILE:0)>

15:53 hiredman: michaeljaaka: what does that suggest about the input to select?

15:53 michaeljaaka: that arguemnt in function is not a seq

15:54 chouser: (use '[clojure.set :only [select]])

15:54 stuarthalloway: almost: argument is a seq, but it not a set

15:54 chouser: (select :good #{{:name "C++"} {:name "Clojure" :good true}})

15:54 stuarthalloway: (swap! snark inc)

15:55 michaeljaaka: ok

15:55 hiredman: stuarthalloway: well, it's not a seq

15:55 michaeljaaka: i see now

15:55 thanks

15:55 hiredman: clojure.*set*

15:56 michaeljaaka: thanks!

15:56 dakrone: I can't seem to wrap my head around doing this functionally, I keep wanted to have some kind of state to keep track of things, http://pastebin.com/d5b7e6b51 can anyone help me understand the functional way to do it?

15:57 tomoj: recursion

15:57 dakrone: I understand recursion, but recursion with *what* is what I can't make the mental leap to yet

15:57 hiredman: you can use reduce to create map of n => instance count of n

15:59 chouser: dakrone: I don't understand yet quite what you're trying to do. Why does the last example in the comment add two numbers the first time, but 3 the rest?

15:59 tomoj: are you trying to chop chunks off the list, run each of those chunks through a function, and then combine the results?

15:59 dakrone: chouser: it's starting from the last number in the sequence, averaging backwards with 3 numbers, when it gets to the front there's only 2 numbers left, so it divides by 2

16:00 so giving more weight to numbers farther left in the list

16:00 tomoj: yea, that's basically it

16:01 tomoj: well, I don't really understand your pastie at all

16:01 dakrone: the (w-avg ...) function does what I want, if I wanted it segmented by 2 each time

16:01 tomoj: but you can do like (recur (take 3 seq) (drop 3 seq) <maybe an accumulator here>) to do what I described

16:01 dakrone: but if I want to segment by 3 each time, it doesn't do it

16:01 tomoj: er, except without the first parameter

16:02 just (recur (drop 3 seq) (<use (take 3 seq) and fold the result into the accumulator here>))

16:03 dakrone: tomoj: okay, I'll try that, thanks

16:03 tomoj: I don't actually know if that will help you.. don't understand weighted averages

16:03 dakrone: I think it will help me understand how to do what I'm trying to do more

16:04 chouser: I think partition and reduce will suffice

16:05 tomoj: yeah better to use the helpers than to manually recur if you can avoid it

16:06 dakrone: chouser: I'm not sure how to partition and carry through the average to be used for averaging again

16:06 stuarthalloway: technomancy: does leiningen help me if I am on non-released versions of stuff (e.g. named git commits)?

16:06 dakrone: so for [1 2 3 4 5] it'd have to partition to (1 2 (avg 3 4 5)) for me, how can I get partition to do that?

16:07 chouser: dakrone: what's the correct answer to your example?

16:07 dakrone: the [1 2 3 4 5]?

16:08 stuarthalloway: are the higher weights at the beginning?

16:08 dakrone: 7/3

16:08 so it does 3 + 4 + 5 = 12, 12/3 = 4

16:08 then 1 + 2 + 4 = 7, 7/3

16:09 chouser: hm... I think I'm close, but I must have a bug.

16:09 dakrone: expanded it's (1 + 2 + ((3 + 4 + 5) / 3)) / 3

16:19 lisppaste8: Chouser pasted "for dakrone" at http://paste.lisp.org/display/90343

16:19 chouser: a bit messy, I'm sure there's a cleaner way.

16:20 maravillas: ah, partition-all

16:21 chouser: oh, sorry, left out the 'use' bit

16:21 I hate it when people do that.

16:21 (use '[clojure.contrib.seq-utils :only (partition-all)])

16:23 the edge cases make it ugly -- first group doesn't takes size+1 from the list instead of size and last group may need a non-size divide. :-/

16:25 dakrone: chouser: I'll read and learn, thank you for the help :)

16:27 technomancy: stuarthalloway: I thought about that. I implemented some of that in a spike, but I think the better solution is to make it easier for library developers to publish jars to a repo

16:28 lisppaste8: Chouser annotated #90343 "maybe cleaner" at http://paste.lisp.org/display/90343#1

16:30 maravillas annotated #90343 "my contribution" at http://paste.lisp.org/display/90343#2

16:31 maravillas: although i guess there's a better method than (concat [%1] %2)

16:31 like cons :)

16:33 oops, didn't use n

16:33 lisppaste8: maravillas annotated #90343 "size fix" at http://paste.lisp.org/display/90343#3

16:34 stuarthalloway: technomancy: makes sense

16:34 chouser: maravillas: that works for you?

16:35 maravillas: seemed to

16:35 did i miss something?

16:35 chouser: not sure, I'm just getting an exception

16:36 maravillas: oh, maybe the args? mine are reversed relative to yours

16:36 chouser: oh, yep, just found that.

16:37 I like yours better (if you were to use cons instead of concat anyway :-)

16:37 maravillas: :)

16:38 dakrone: maravillas: very readable, thank you much!

16:38 maravillas: welcome

16:39 it's funny how often i need something fairly basic, and then find it in contrib

16:39 like partition-all

16:40 technomancy: stuarthalloway: I may revisit it if the jar repo thing doesn't take off.

16:41 chouser: maravillas: for the most part I like our process. we've been debating over the right way to get something like partition-all into core, but haven't settled on anything yet.

16:41 until we do, we've got contrib. :-

16:41 :-)

16:41 * technomancy has found that he uses the I/O stuff from contrib more than anything else

16:41 technomancy: I wonder if there would be room for clojure.io in a future release.

16:42 stuartsierra: I've wondered the same.

16:42 * hiredman rarely uses contrib

16:42 arohner: duck-streams is pretty great

16:42 stuartsierra: I've also wondered if clojure-contrib should be packaged into each Clojure release.

16:42 technomancy: I use duck-streams in probably 1 out of every 5 namespaces, and java-utils/file all over the place.

16:43 chouser: I use seq-utils, repl-utils, and str-utils2 quite a bit

16:43 technomancy: (only a slight exaggeration)

16:43 maravillas: yeah, i can understand that. i was mostly musing that i start to put together something just before i think to check contrib.

16:43 hiredman: I should use contrib, I mean, I have it sitting there, compojure requires it, so it's like getting it for free

16:44 lisppaste8: stuarthalloway pasted "separate reduce/weight" at http://paste.lisp.org/display/90345

16:45 stuarthalloway: maravillas: loved yours, just posted a slight mod

16:46 fradiavalo: xb

16:46 the-kenny: It is possible to have two repls connected to the same clojure instance in emacs?

16:46 *Is it

16:46 arohner: the-kenny: yes, using swank

16:47 the-kenny: arohner: Can you tell me how?

16:47 maravillas: ah yes, nice

16:47 arohner: download swank-clojure

16:48 start it up in your process

16:48 oh wait, I'm answering a slightly different question

16:48 you can make a clojure process than can serve multiple repls

16:48 I don't know about one emacs process with multiple swank connections

16:49 I'd be surprised if it's not possible, but I don't know how to do that

16:49 the-kenny: arohner: I have a running swank-clojure setup. I just want to create two repls pointing to the same clojure instance :)

16:50 arohner: oh, just try M-x slime-connect

16:50 when it asks if you want to close the other connection, say no

16:51 the-kenny: hm.. what's the default port?

16:51 arohner: 4005

16:51 the-kenny: 4005 isn't working

16:51 "make process client failed"

16:51 ew "make client process failed"

16:52 arohner: I can tell you I manually start swank-server in my process, so I can access it all the time

16:52 that might be different than how clojure-mode does things

16:53 drewr: has anyone experimented with using contrib as a submodule in clojure core in order to keep versions in sync?

16:53 the-kenny: Looks like clojure uses a local file

16:54 stuartsierra: drewr: yes, I did for a while

16:54 drewr: stuartsierra: no good?

16:55 stuartsierra: It worked, but I decided it was easier to use Maven snapshots.

16:55 drewr: k

16:56 stuartsierra: Most libs in contrib are not tightly coupled to core, anyway.

16:57 arohner: ugh. Anyone have any good articles on implementing a stateful java API in clojure?

16:57 stuarthalloway: stateful how?

16:57 arohner: instance.loadData(data); instance.processData();

16:58 stuarthalloway: looks done already, except for refactoring away instance :-)

16:59 are you implementing existing Java interfaces?

16:59 arohner: yes

16:59 hiredman: google likes to use "Builders" where all the methods return this

16:59 arohner: and I think I might have to extend a concrete superclass

16:59 stuarthalloway: gen-class is pretty straightforward

17:00 hiredman: did defclass vanish into thin air?

17:00 stuarthalloway: simple genclass example: http://github.com/stuarthalloway/programming-clojure/blob/master/examples/tasklist.clj

17:00 arohner: yeah, it looks fine. I'm mainly interested advice about style

17:00 chouser: hiredman: yes

17:00 hiredman: neat

17:00 chouser: hiredman: deftype ate it

17:01 stuarthalloway: arohner: keep all state (if you need any) in a single object

17:01 other than that pretty trivial

17:01 arohner: stuarthalloway: thanks

17:01 hiredman: loadData should obviously return a FutureTask which processes the Data when you call .get

17:02 but if you are implementing some api, :(

17:02 arohner: hiredman: yeah :-(

17:02 I'm doing some machine learning stuff. I have my own implementation already working, and in good clojure style

17:03 now I'm trying to shoehorn my classifier into WEKA

17:03 very Java-y API

17:03 the contrast is stark

17:03 hiredman: might be a good place to explore the new types and protocols stuff

17:03 chouser: can I use (are ... (thrown? ...)) somehow?

17:04 arohner: can protocols implement an interface?

17:05 chouser: arohner: yes! using :on

17:05 arohner: oh, nice

17:05 chouser: and it makes them run faster too

17:06 arohner: oh, you can extend a class too!

17:06 hiredman: I'm not clear on how that works, so feel free to lisppaste some examples

17:08 stuartsierra: chouser: (are ... ) expands to (do (is ...) (is ...)) so it should work

17:10 arohner: in my experience, WEKA is easy to understand but very procedural, not to mention inefficient

17:16 stuarthalloway: stuartsierra: while on the subject of are--I find myself wanting each expansion to include a description

17:17 i.e. (are [desc a b c...] (something that reports desc on failure))

17:26 froog: silly question, how do I check the length of a list?

17:27 tomoj: ,(count '(1 2 3))

17:27 clojurebot: 3

17:28 froog: tomoj: thanks

17:28 I had used .length until now, but that doesn't work on lists

17:29 tomoj: if you ask counted? on something it will tell you whether count will quickly give you the length

17:29 ,(counted? '(1 2 3))

17:29 clojurebot: true

17:29 froog: that's clever

17:29 tomoj: ,(counted? (range 100))

17:29 clojurebot: false

17:30 tomoj: you can still count ranges but it won't be very fast

17:31 ,(time (count (range 100000)))

17:31 clojurebot: 100000

17:31 "Elapsed time: 357.762 msecs"

17:31 tomoj: ,(time (count (range 1000000)))

17:31 clojurebot: 1000000

17:31 "Elapsed time: 362.483 msecs"

17:31 tomoj: wat?

17:31 how'd clojurebot do that so fast?

17:32 _mst: chunked seqs? (random guess)

17:32 tomoj: I have chunked seqs I believe..

17:32 for me it takes nearly 10 times longer to count (range 1000000) as it does (range 100000)

17:32 Chousuke: maybe it was a jvm fluke

17:32 _ato: it could be a JIT effect

17:33 hiredman: ~clojurebot

17:33 clojurebot: clojurebot is like life: you make trade-offs

17:33 _ato: ,(time (count (range 100000)))

17:33 clojurebot: 100000

17:33 hiredman: ~clojurebot

17:33 clojurebot: "Elapsed time: 31.894 msecs"

17:33 clojurebot is amazing

17:33 Chousuke: :D

17:33 _ato: haha

17:33 tomoj: oh, I see

17:33 so yeah, linear

17:33 hiredman: there is another one, but I always feel bad spamming the channel trying to get clojurebot to say want I want

17:33 * froog will run all his code on clojurebot

17:34 _mst: *chuckles*

17:42 krumholt: ,(counted? (range 10000))

17:42 clojurebot: false

17:43 krumholt: that returns true on my repl :)

17:44 froog: here too

17:45 krumholt: maybe that changed on some clojure version

17:46 ,(clojure-version)

17:46 clojurebot: "1.1.0-alpha-SNAPSHOT"

17:47 krumholt: strange :)

17:54 IsaacL: (doc counted)

17:55 clojurebot: Titim gan éirí ort.

17:55 krumholt: ,(doc counted?)

17:55 clojurebot: "([coll]); Returns true if coll implements count in constant time"

18:45 michaeljaaka: Hi!

18:45 I have problem using inspector

18:45 I do

18:45 (require '(clojure.inspector))

18:45 (clojure.inspector/inspect #{ "hello" })

18:45 and get exceptino

18:45 user=>

18:45 nil

18:45 user=>

18:45 #<CompilerException java.lang.ClassNotFoundException: clojure.inspector (NO_SOURCE_FILE:448)>

18:45 user=>

18:46 what is wrong?

18:49 tomoj: michaeljaaka: it's (require 'clojure.inspector)

18:50 michaeljaaka: wow, it works!

18:50 thanks!

19:17 hi

19:17 I would like to process two sequences

19:17 within doseq

19:17 to do that

19:17 I have to make

19:18 (doseq [ x y (map vector '(1 2 3) '(4 5 6))] and here goes body )

19:19 hiredman: nope

19:19 michaeljaaka: is there any simpler way so I don't have to map sequences with vector function?

19:19 the real code is

19:19 (doseq [ [x y] (map vector (take 5 (iterate inc 0)) (take 5 (iterate inc 2))) ]

19:19 (println x " " y))

19:21 tomoj: well, you could do

19:22 (dorun (map #(println %1 " " %2) (take ..) (take ..)

19:22 I would like for and doseq to be able to go through multiple seqs in parallel in a pretty way, though, hm

19:26 michaeljaaka: well with dorun is ok too

19:26 because one of the sequences have side-effects

19:26 and it blocks on I/O

19:27 but dorun is prepared for such sequences

19:51 slyrus_: does anyone around have/use anything like a clojure-y slitex for making presentations/pdfs?

20:00 chouser: 'range' changed

20:00 (class (range 100))

20:00 ,(class (range 100))

20:00 clojurebot: clojure.lang.LazySeq

20:01 aaron__: i'd like to be able to serialize the Map i get back from some Clojure code. I'm currently getting a PersistentHashMap, but alas it's not actually Serializable due to its internal data structures. Should this be considered a bug?

20:02 tomoj: what did range used to be?

20:02 aaron__: I think the idea I've heard most for serialization is to just prn and read

20:02 and I think there are some bindings you can use to make it better

20:03 aaron__: hmmm. well, i'm doing the serialization work in Java

20:03 (my Java code uses some Clojure code for utility stuff, then runs with the output)

20:03 so maybe i want to use the output from an addtl. prn to send across the wire?

20:04 what i'm currently doing as a workaround is new HashMap(theMapIgotFromClojure)... but that's a lot of extra work to

20:05 (too)

20:05 tomoj: ~def pr

20:06 man those huge blobs on github make my browser cry

20:07 aaron__: tomoj: me too

20:08 i wonder which is "better": serializing a new HashMap(theMapIgotFromClojure), or sending what i get back from prn

20:09 tomoj: I have no idea

20:09 aaron__: hmmm... i have to juggle an extra stream it looks like, if i go the pr route. a little awkward

20:25 chouser: tomoj: (range) used to return a Range object

20:27 I think

21:20 kanak: I have a seq of seqs how do i "flatten" then so that i can draw from the items of the first seq, then from the second, and so on?

21:22 devlinsf: kanak: there's a flatten function in clojure contrib. Check the namespace clojure.contrib.seq-utils

21:23 kanak: it has some trouble with sets, btw...

21:23 _ato: ,(apply concat [[1 2] [3 4] [5 6]])

21:23 clojurebot: (1 2 3 4 5 6)

21:23 kanak: devlinsf: thanks. Checking it out right now. I'm not using sets so that shouldn't be a problem.

21:23 _ato: if it's just two levels that you want to flatten

21:23 kanak: I didn't want to do an apply because I don't want to have these seqs evaluated all at once.

21:25 devlinsf: ,(str "Clojruebot???")

21:25 clojurebot: "Clojruebot???"

21:25 _mst: ,(take 10 (apply concat [(range 1 5) (iterate inc 1)]))

21:25 clojurebot: (1 2 3 4 1 2 3 4 5 6)

21:25 devlinsf: cool

21:26 kanak: wait does this mean that apply doesn't force the evaluation of seqs?

21:26 hiredman: correct

21:27 kanak: cool :) I can just use apply concat then :)

21:35 mtf: can anyone tell me how to load a .jar into a running clojure instance if i did not specify it in the classpath?

21:35 is there a repl command?

21:37 chouser: mtf: you can try add-classpath, but it may not work depending on your context

21:37 _ato: ~add-classpath

21:37 clojurebot: add-classpath is bad, avoid it. I mean it!

21:37 _ato: :p

21:37 yeah it'll usually work for basic things

21:37 drewr: ,(doc add-classpath)

21:37 clojurebot: "([url]); Adds the url (String or URL object) to the classpath per URLClassLoader.addURL"

21:37 drewr: mtf: better is to extract the jar's class files in a path already on the classpath

21:38 mtf: ok thanks

21:38 and the path to the .jar file is a string right?

21:38 not #P"/blah" like common lisp

21:38 chouser: String or URL

21:38 drewr: (add-classpath "file:///path/to/foo.jar")

21:38 _ato: (add-classpath "file:///some/dir/")

21:38 mtf: ok

21:38 thx

21:47 hiredman: ,(doc add-classpath)

21:47 clojurebot: "([url]); You are crunchy and taste good with ketchup"

21:48 chouser: much better

21:48 tomoj: who is a french fry?

21:49 hmm, maybe "what would you say to me if I were a french fry?" ?

21:54 devlinsf: do not meddle in the affairs of dragon

21:54 http://www.buzzymultimedia.com/meddle-not-with-dragons.html

22:07 burny: can you nest transaction's? (send-off (some function that also sends-off))

22:07 chouser: those aren't transactions

22:08 but yes, you can send from inside an agent's action fn. The send will be held until the action completes.

22:09 hiredman: same if you send from inside a transaction

23:17 michaeljaaka: Hi

23:17 I want to create Thread

23:18 and watch how a println "Hello Wolrd" is executed

23:18 I have written somehting like this

23:19 (doto (proxy[Thread] ('run[] ( println "Hello World " )))

23:19 (.start))

23:19 but gets #<CompilerException java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to java.lang.ThreadGroup (NO_SOURCE_FILE:0)>

23:19 user=>

23:19 Do you know why?

23:23 _ato: you don't need proxy: (doto (Thread. #(println "Hello world")) (.start))

23:24 but as to why, proxy takes two vectors before the methods, not one

23:24 and you dont need to quote run

23:25 michaeljaaka: there's some examples of using proxy here: http://en.wikibooks.org/wiki/Clojure_Programming/Examples/API_Examples/Java_Interaction

23:27 george__: is clojure faster or slower than java ?

23:28 chouser: how could it be faster?

23:28 george__: taking slower time to run a program

23:28 in JVM

23:30 _ato: technomancy: ha! http://gemcutter.org/gems/clojure

23:32 michaeljaaka: _ato: thanks

Logging service provided by n01se.net