#clojure logs

2009-11-13

00:06defnIf 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
00:06defnI imagine it looks something like (filter (= (count (map #(seq %) word-list)) 3))
00:07hiredmanuh
00:07hiredmannope
00:07defnhiredman: i love you for all of your help
00:07hiredman(filter (comp (partial = 3) count) list)
00:08hiredman(filter #(= 3 (count %)) list)
00:08defnwhat is comp
00:08hiredmancompose
00:08defnthe force is strong with you
00:10defnhiredman: thanks for your help
00:11defnhiredman: 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?
00:12hiredmandefn: sure
00:13hiredmanif you don't need index access then use a list
00:13defnhiredman: your gists are really great btw
00:13defnlots of interesting clojure in there
00:13defnthanks
00:14hiredman:)
01:02duncanmla la la
01:08hiredman~ping
01:08clojurebotPONG!
01:08Raynes~pong
01:08clojurebotTitim gan éirí ort.
01:22defnI could use a little help on something
01:25G0SUB_defn: ask
01:25defnG0SUB_: im torn between asking and continuing to work at it
01:26defnbut basically I was wondering if someone could explain to me the recur/loop forms
01:26defnI don't really understand how those work
01:26G0SUB_defn: sure.
01:27G0SUB_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.
01:28G0SUB_defn: does that help?
01:28defnim 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?
01:29defnG0SUB_: sort of, could you write a short piece of code and sort of step from the inside out?
01:29defnlike (loop [a 1] (+ a 1) (recur ??
01:30G0SUB_defn: come here, I will explain - http://etherpad.com/VSekWefWtV
01:43tomojI rather dislike etherpad :(
01:52somniumtomoj: how come? first time I've seen it its kind of cool, multi-player notepad++
01:55tomojyeah it's cool I guess
01:55tomojbut I like IRC better
01:56somniumi like the shared code buffer thing anyway
01:59ngocHi, (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?
01:59somniumslurp is the sound people make when they eat noodles
01:59somniumthink of ramen
02:00woobyis reduce lazy?
02:00somniumno
02:00danlarkinhow could it be
02:01somniumi saw a lazy reduce somewhere, in contrib maybe
02:01woobyi would think the 2 argument form could be
02:01somniumits much more performant by not being lazy, and usually you want to realize the whole thing
02:02somniumthe lazy variant i saw conses onto a collection, so it makes more sense
02:02wooby(take 10 (reduce (fn [xs y] (conj xs (+ (last xs) y))) [0] (iterate inc 1))) was what i wishfully came up with
02:03hiredmanwooby: reduce can only be lazy in a language that has a lazy evaluation (haskell)
02:04woobyahh i get it
02:04woobybecause reduce would somehow need to pass on the 'knowledge' that the underlying list generation is happening lazily?
02:05hiredmanin your eample reduce turns into something like (conj (conj [0] 1) 2)
02:05woobyaha
02:06hiredmanthe other thing to keep in mind is vector s are not lazy
02:06hiredmanthe only lazy thing in clojure is lazy-seqs
02:06woobyso if it were haskellish take would trigger un-nesting lazily? whereas on jvm that's just stack overflow
02:06woobyok
02:06woobyok that is very awesome to know, thank you
02:08woobybtw hiredman i saw your php lisp thing on the github there, how's that going? looked like you'd started on compilation
02:10hiredmanwooby: I haven't touched it in sometime
02:10hiredmanactually I was just thinking about it again
02:15wooby,(take 10 (rest (map first (iterate (fn [[a b]] [(+ a b) (inc b)]) [0 1])))))
02:15clojurebot(1 3 6 10 15 21 28 36 45 55)
02:17hiredmanI'd like to get compilation working
02:18woobyi was looking around the other day for a jvm in php, i think that would be 'ideal'
02:18woobyparrot seems to be as close as it gets though
02:19hiredmana jvm in php?
02:19hiredman:|
02:19somniumi'm not sure if php is the best language to implement a jvm in
02:19_atoO.o
02:20woobyi find it not the best language for much of anything... except employment :l
02:23hiredmanactually I wrtoe a little cache thing in php.lisp that I used for this little utility I wrote for a guy
02:24hiredmanso it's in use...
02:24woobyi have been reading it... i could really use it myself
02:29_atohttp://technomancy.us/
02:29_ato^ multiplayer emacs thing "rudel"
02:29_atohaven't tried it myself yet
02:29G0SUB_http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey
02:30_atoG0SUB_: hehe.. I have that on pause in another window :)
02:30G0SUB__ato: I already have the video downloaded :)
02:40qedtechnomancy: You have some borked links on your Gobby/Ebby post.
02:46gilbertleunghi...
02:46gilbertleunganyone around to answer a small question?
02:46gilbertleunghow do i set *out* to STDERR?
02:47_ato(binding [*out* *err*] .... ) ?
02:47gilbertleungcool!
02:47gilbertleung_ato thanks again
02:47gilbertleung(i just didn't know it's *err*)
03:12noidiis there anything new in the "are we there yet" presentation?
03:12noidithe first few slides look awfully familiar
03:13noidii mean, really familiar, nothign awful about them :)
03:14somniumI think he explains very eloquently how stateful OO is a broken model of time in a general sense
03:20defnSomeone needs to make github, but for connecting coders in shared buffers.
03:21defnor connect it into github, so you can socially code
03:21defnon a given repo
03:23noidiah, the slides have been online since (at least) september http://wiki.jvmlangsummit.com/Image:HickeyJVMSummit2009.pdf
03:23noidigood, this means that I'm not going crazy and I've really seen the slides before :)
04:39ordnungswidrighi all
04:42Licenserhi ordnungswidrig
04:42Licenserhi rest of the world
04:42KjellskiHi Licenser!
04:42esjGood Morning Clojurians.
04:43KjellskiGood Morning...
04:44KjellskiCould 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)
04:44KjellskiIt just returns nil.
04:45LicenserI'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 :(
04:45G0SUB_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?
04:46G0SUB_this is for MongoDB interop. Maps should be BasicDBObject and vectors should be BasicDBList.
04:46LicenserG0SUB_: ask somnium he has done that already when I'm not wrong
04:46G0SUB_somnium: ping
04:46somniumKjellski: .setPathName seems to mutate the instance, so youre getting the return value, you can use (doto (javax.../getInstance) (.setPathName "nist.gof"))
04:47Licenserhi somnium :)
04:47G0SUB_somnium: need a bit of help with the above problem.
04:47somniumG0SUB_: well, you could use my congomongo from github, or you could just use the ClojureDBObject class if you don't need the extra stuff
04:47somniumHi Licenser :)
04:48G0SUB_somnium: link?
04:48somniumhttp://github.com/somnium/congomongo
04:48G0SUB_somnium: found it. thanks
04:49somniumyou don't need to use BasicDBList apparently, or at least that's what the devs told me. Not sure why its there
04:49G0SUB_somnium: well, inserts work with clojure vectors, update doesn't
04:50Licenserif 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
04:51Licensersomnium: 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
04:51G0SUB_Licenser: what hw are you using?
04:52LicenserG0SUB_: A Sun SPARC Server, and they don't want to support SPARC HW
04:53Licenserthey 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
04:53somniumdoes 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
04:54somniumLicenser: they can't just make a special build?
04:54Licenser$set isn't good since it interfeers with indexes and does not work for this or that
04:54somniumhow strange
04:54Licensersomnium: was my impression but they say no :P
04:55somniumwell, couch seems a nice alternative
04:55somniumit could use a clojure map-reduce dsl for sure (hint hint)
04:55Licenserhehe
04:56Licenserfirst I need to get the ssh stuff working :P that is work so it sadly has priority
05:01k-factorHi, 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?
05:05KjellskiAnyone got an idea of how to append things to the path in enclojure for a project?
05:06somniumLicenser: perhaps it should be wrapped in a with-open or similar? the only clojure io I've done has been with duck-streams
05:07woobylast statement results in NPE, thanks in advance for help: http://gist.github.com/233726
05:07Kjellskik-factor : I would recommend you to comment your functions a bit...
05:08somniumKjellski: I think you can add libraries by right clicking on the lib icon in projects pane
05:09somnium(though I only tend to use netbeans when I find myself writing java)
05:09Licenserwooooh solved it!
05:09somniumnice, what was the trick?
05:32CalJunioron mutable data in go: http://bit.ly/4EGOFW
05:33CalJuniorthe 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 :)."
05:33KjellskiIs 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?
05:34CalJuniorthe money quote anwer from Ian Lance Taylor: "It's the only answer we have so far, sorry"
05:36somniumdo they even have constant types? (I know D has this with concurrency in mind)
05:36CalJunioryes
05:36G0SUB_I have only one java file in my clj codebase. how do I easily AOT compile that file?
05:38somniumG0SUB_: you just need to java -cp it with what ever clojure jars it needs, netbeans makes it pretty easy
05:38G0SUB_somnium: hmm
05:38somniumer, javac I guess, I let the ide write build.xml
05:39G0SUB_somnium: can't clojure import .java files?
05:39KjellskiNoone with a good example with a translated java implements to clojure translation? The more complex the better.
05:40somniumI'm not too up on compilation with clojure, sometimes order matters, so I've just split things into separate jars
05:40_atofor ; i < len(b) && !isDigit(b[i]); i++ { ... }
05:40_atooh man... C-style for loops without parens give me motion-sickness
05:45CalJunior:-)
05:45MaddasIt's unfortunate to see how unnecessarily complicated and confusing the syntax in many other languages seems once you're used to more regular syntax :-)
05:45Maddas(Unfortunate because you slowly morph into a smug lisp weenie, and this is just the first step)
05:46_atohehe
05:46somniumG0SUB_: 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.
05:47somniumI think Python will always have a reasonable second place for syntax :)
05:47k-factorKjellski: 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.
05:48somnium(even Paul Graham spoke at one of their 'lesser-language' conventions)
05:50febelingHi. I have trouble accessing a static member dynamically, when I dont have the literal symbol.
05:51Chousukefebeling: you need to use the java reflection APIs or eval
05:51febelingah, really? ok
05:52Chousukebut of course, the real problem might be elsewhere
05:52febelingso there is nothing like (. Level (symbol "ERROR"))
05:52_atofebeling: (eval `(. Math ~(symbol "PI")))
05:52Chousukeyou really shouldn't need to do that.
05:53febelingwhat wrong with it
05:53Chousukewell... it's eval. :P
05:53febelinghehe, ok
05:53Chousukewhat would you use this for?
05:53susheelquit clojure
05:53febelingbut should i then resort to a cond?
05:53Chousukemaybe.
05:53Chousukeor perhaps a macro
05:54febelingthe cond would be a bit like the C solution, it feels
05:54febelingnot too dynamic
05:55Chousukeis the string defining the symbol known only at runtime? :/
05:55febelingdepends, but that was my initial idea
05:55Kjellskik-factor : Sorry, I´ve got to go... but I´ll look that up the next time...
05:56Chousukefebeling: I really can't tell whether making it dynamic like that is a good idea or not without knowing what the context is :/
05:57febelingwell, i could read all static fields in advance and build a macro ofc
05:57Chousukeyou can also use reflection in a macro.
05:57Chousukeand produce code based on the reflection :)
05:57G0SUB_somnium: how do I convert a mongo datastructure to clojure map using clojuredbobject?
05:58febelingChouske: thats i meant
05:58somniumG0SUB_: .toClojure
05:58ChousukeI guess eval is sometimes needed for some things but I haven't encountered any :P
05:58G0SUB_somnium: how to I create a clojuredbobject from a basicdbobject?
05:59somniumhmm
05:59somniumhaven't done that much
05:59somniumbut (doto clojuredbobject (.putAll basicdbobject) should work)
05:59G0SUB_somnium: hmm
05:59_atoChousuke: it's needed for clojurebot! :p
06:00somniumusually I've set every collections class to clojure dbobject so no conversion needed
06:01somniumsome 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
06:01_atofebeling: but yeah, generally it's better to do that sort of stuff at compile-time if possible. reflection/eval is slow and messy
06:02Chousuke_ato: right. because clojurebot is a repl :P that doesn't count.
06:02febeling_ato: if it is not in the inner loop i don't really bother about speed, tbh. thanks for the eval line
06:03Chousukein clojure.core there's at least definline which uses eval.
06:05_atoalthough definline does it at compile-time
06:15G0SUB_somnium: did you mean .putClojure?
06:16somniumG0SUB_: .putClojure create a clojuredbobject from a persistent map
06:16G0SUB_somnium: I don't see putAll in the file.
06:16somniumbasicdbobject is a java.util.HashMap so .putAll should probably be used
06:16G0SUB_ok
06:16somniumuse repl-utils/show
06:16somniumits there, trust me :)
06:17G0SUB_somnium: :)
06:18G0SUB_somnium: fantastic. works.
06:20somniumgreat
06:29djpowellis there any relationship between protocols and 'isa?' ?
06:31_atodjpowell: I don't think so
07:02Licenserhmm does with-open act as binding?
07:03AWizzArdno
07:04Licenserdarn
07:07Licenserhrm hrm
07:12gerry`how about google go language? i'm downloading now
07:13ttmrichtergerry`: What about it?
07:13somniumgerry`: it may be a nice host for clojure once it has better libraries
07:14gerry`does it use any vm like java?
07:16ttmrichterWell, considering that one version of it is a GCC front end, probably not.
07:16eevar2gerry`: once it has better libraries that java? ;)
07:16eevar2*than
07:17gerry`it will be after twenty years :)
07:18ttmrichter20 more years of the squiggly-brace hegemony? I'll just cut my wrists now, thank you very much. :D
07:21gerry`you mean parenthesis will rock forever? :)
07:22LicenserNo one day we'll have compilers that understand plain english with typos!
07:22Licenser(+ 2 2)
07:22clojurebot4
07:24esjsilly 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 ?
07:24_ato(ns newspace (:use compojure))
07:24esjbah !
07:25_atoyeah.. it's nuisance how it's inconsistent like that
07:25esji'd preloaded by brain to think it was working like a map, on account of :reload etc
07:26esjthanks _ato
07:28Drakesonis there an alias for the special form "." ?
07:30_atoDrakeson: as in like @ is (deref)? no it's just .
07:30Drakesonyes. thanks.
07:31DrakesonI find it a bit easy to miss (well, depends on the fonts, etc., but still)
07:40LicenserI'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
07:43yasonLicenser: use config# instead of config, that'll create an automagic gensym
07:43somniumLicenser: also for session
07:44Licenseryason: I tried that but then when I have a second macro that is called within in-session it generates a different gensym for session :(
07:44noidithe :use, :require etc. options to ns are the worst part of clojure, imo
07:44noidiit seems to me that no one gets them right :)
07:44somniumah, then you need to capture like: ~'session
07:50Licenserwooh thanks somnium that works
07:51yasonLicenser: 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
07:52Licenseryason: I don't know other lisps ;) but well macros are kind of odd
07:53Licenserhrm macros are silly
07:56Licenserhrm hrm all not good
07:57Licensergrr ~code evaluates to ((exec "ls")) narf
07:57somnium~@code
07:57clojurebotExcuse me?
07:58LicenserI think I really suck :P
07:58somniummacros just take some getting used to
07:59somniummacroexpand-1 is your friend :)
07:59Licensersomnium: yap I used macro expand a lot but knowinf what all the ` ~ @ ' # mean is really confusing or even knowing they exist
07:59Licenserhell yea! somnium you're my hero, it freaking works :D
08:00somniumtry reading the source for 'for ;)
08:02Licenser^^
08:02Licensernow to understand how the ssh library hands stuff
08:02Licenserit's crazy you create a ssh object a session object and a channel objectg o.O
08:18febelingcoming back to static field access through name... http://clojure.pastebin.com/f32856ff9 anything dodgy with that?
08:26chouser,(clojure.lang.Reflector/getStaticField "java.lang.Integer" "MAX_VALUE")
08:26clojurebot2147483647
08:27chouserfebeling: Clojure has to do dynamic access at various points automatically. You can manually use the same Reflector class it does.
08:28febelingchouser: thanks, i guess thats what i'm after
08:28chouserbut yours is a macro, so now I'm confused.
08:29febelingmine would not give warnings on reflection use, would it?
08:29chouserdo you know the name of the class and field at compile time?
08:30febelingthe class yes, the fields only at runtime
08:30febelingor the one field
08:30chouserah, I see
08:31chouserusing Reflector to do the same thing won't generate a reflection warning either.
08:32febelingok, so then it would be more natural to use that
08:32chouseryour 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.
08:33chouser(esp. when 'case' is available)
08:33febelingso a slight optimization, but probably not needed for confi/startup of an app, as in my case
08:34febelingthanks for the pointer :)
08:34chouseryeah, 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.
08:41febelingbtw: is reflector usage of reflection then generally exempt from the warnings, or how are the rules?
08:42chouseryou 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.
08:43chouserso (.foo bar) will get a warning if at compile time it doesn't know what class bar is.
08:47febelingand reflector does get around this in cases like the MAX_VALUE one above?
08:48chouserright. 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.
08:49chouserthen 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.
08:50febelingok, i get it
08:53febelingso 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?
08:54febeling(i mean at runtime now)
08:56chousergenerally 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.
08:56chouserso if you turn on the warnings it ought to be pretty obvious where there will be runtime reflection
08:57chouserin 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.
08:57febelingok
08:59Licensernice
09:00Licenserhttps://gist.github.com/c9ef95778338d3c7da5a <- it's working :D
09:12febelingchouser: if that wasn't my conviction, i wouldn't use clojure actually :)
09:13chouserfebeling: ah, not in favor of static typing then? :-)
09:13febelingnope :)
09:16febelingstill like to have the option where it matters
09:17chouserI'm still ambivalent, but I'm happy I'm never forced to specify types and rarely need to for improved performance.
09:20febelingso much more to be gained from the time-memory tradeoff, in many cases
09:21Chousukeand no-one knows what the future will bring.
09:24ChousukeI 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...
09:25Chousukebut 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
09:25chouserand for error checking at compile time.
09:25chouserI think that's actually what I want, but yes I can't really imagine how it would work.
09:25chouserI'm hopeful something similar is in rhickey's head and we'll all get to use it some day. :-)
09:26chouserI'm under the vague impression that's part of the point of the datalog work, but I don't understand how it all relates.
09:27somniumI wonder if some day a compiler will be written better than any human programmer, and all 'programming' languages will look like cucumber
09:27rhickeychouser: 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
09:27febelingthat sounds interesting, i'll have to look into datalog
09:27chouserrhickey: ah!!!!
09:29chouserwith access to any bits of assertion or requests for checking that I might happen to tuck away in form metadata here or there.
09:31rhickeychouser: right, basically it becomes completely extensible from the get-go
09:31rhickeyand people can do what they consider important, rather than what I do
09:33chouserwith appropriate libraries of "normal" things available to start with and then extend as needed
09:34Chousukeclojure.contrib.optimizations :P
09:35rhickeyChousuke: not really about optimizations
09:46ambientbtw rich's JVM summit 2009 keynote is up http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey
10:23rhickeyshould I put this on the wiki?
10:23rhickeyhttp://groups.google.com/group/clojure/msg/330c230e8dc857a9
10:24rhickeyended up being a bit of a manifesto
10:27patrkrisrhickey: i can't see why you shouldn't
10:28djpowellI 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:29Chousukeyou can put the implementation in a map
10:29Chousukeand then give that map to anyone who might want to use it as a basis for their implementation of the protocol.
10:32ambientso do a lot of other people who like oop
10:33djpowellChousuke: ah, cool - that would work for the operations. I suppose there isn't an equivalent for the fields in deftype
10:33rhickeydjpowell: not the fields, right
10:35djpowellrhickey: protocols now dispatch to subclasses - is there anything that they could do with derive?
10:37rhickeydjpowell: If it were up to me, they wouldn't. This is strictly there for interop. Protocols do not use the derive/hierarchy sytem
10:37rhickeysystem
10:38rhickeyfor your fields thing, a mixin could specify it needs a certain set of fields and access them in its implementation fns
10:39rhickeynot the same as inheriting fields, but might be enough
10:42djpowellrhickey: sorry, I don't understand what you mean by mixin?
10:43rhickeydjpowell: as Chousuke mentioned - mixins are fn maps you can reuse in extend calls
10:44rhickeyso 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:45djpowellrhickey: ok - i'll take a look at how that would work out
10:45rhickeythis 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:51djpowelltbh - 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:51rhickey sweet
11:06chouserrhickey: so, my finger trees are slower now than they were.
11:06chouseradding back some gen-interfaces to put the protocols :on could buy back some of that performance, right?
11:08rhickeychouser: right, should be identical with :on
11:08chouserdid you say there as a possibility of eventually generating interfaces from defprotocol?
11:08rhickeyI'm hoping to play with call-site caches for protocols to make that unnecessary
11:08chouseroh, ok.
11:09rhickeybut I don't know that they will match until I do so
11:09chouserok
11:14djpowelltwo protocols defined in the same namespace mustn't use the same names for methods?
11:14chouserright
11:15djpowell'extenders' is cool
11:17Kjellski~rhicker
11:17clojurebotTitim gan éirí ort.
11:17Kjellski~rhickey
11:17clojurebotexcusez-moi
11:18Kjellskirhickey : Are your clojure presentations made with LaTeX?
11:29rhickeyKjellski: no, Keynote + OmniGraffle
11:30Kjellskirhickey: Okay, that´s a pitty... I´m pretty frustrated with latex listings right now...
11:30rhickeychouser: so I've got that patch in here, but really dislike the warning (vs, say, an error)
11:31Kjellskirhickey : 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:33chouserrhickey: really!? it seems like there are several dynamic situations where an error would be inappropriate.
11:34bradford,(into (sorted-map) {:b 2 :a 1})
11:34clojurebot{:a 1, :b 2}
11:34bradford now how do i do something like this: (into (sorted-map-by #(compare (second %1) (second %2))) {:b 2 :a 1})
11:34rhickeythe warning basically says - you've (already) messed up your environment
11:34bradfordproduce a sorted map from an unsorted map?
11:34chouserrename 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:35rhickeywhy would you have to restart the JVM?
11:36chouserif you got an error when trying to rename your protocol, what else would you do?
11:36rhickeyoh, well we need a rename/remove protocol and a bunch of other things still
11:36chouserI guess you could manually unmap all your protocol-generated methods.
11:36chouseroh, ok.
11:37chouserso you want an error before anything's been changed, forcing some kind of manual un-def'ing first?
11:38rhickeyI've just been waiting to se what they might be, certainly nuke an entire protocol, and remove an impl (unextend, retract?)
11:38rhickeychouser: right, like:
11:38rhickey,(def String 42)
11:38bradfordso what would be the easiest way to produce a sorted map from an unsorted map given a cparator?
11:38clojurebotDENIED
11:39rhickeyargh
11:39chouserheh
11:39chouserok, I can print DENIED
11:39rhickeyheh
11:39rhickeyI've got your patch in, so I'll change it to a throw here
11:40chouserprobably need to move the assert to before alter-meta! too
11:41rhickeythe metadata flow has to be better overall, I'd like to preserve meta through to fn var
11:41Kjellskibradford : What you´ve written is not working?
11:41Kjellski,(doc sorted-map-by)
11:41cemerickit 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:41clojurebot"([comparator & keyvals]); keyval => key val Returns a new sorted map with supplied mappings, using the supplied comparator."
11:42cemerickI mean, totally aside from the impl. details in the background.
11:42chouserbradford: 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:42rhickeycemerick: which, defprotocol? The names there flow through a lot of stuff, so just a quality of implementation thing
11:43rhickeybradford: or you want a sorted set of the paris
11:43rhickeypairs
11:45cemerickrhickey: 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:46cemerickrather than a proliferation of def*, un-def*, tweak-def*, etc.
11:47rhickeycemerick: when people write those specific things they are just trying to get out of using the composable thing
11:47rhickeymetadata maps
11:48cemerickYeah. That's frustrating to me :-)
11:48patrkrisis it considered more idiomatic to use doseq than dorun?
11:48drewr,Keyword
11:48clojurebotjava.lang.Exception: Unable to resolve symbol: Keyword in this context
11:49drewr,clojure.lang.Keyword
11:49clojurebotclojure.lang.Keyword
11:49drewrshouldn't that Keyword import automatically?
11:52bradfordgetting sorted pairs is no problem
11:53bradford,(sort #(compare (second %1) (second %2)) {:b 1 :a 2})
11:53clojurebot([:b 1] [:a 2])
11:53bradfordthe prblem is you can't follwo that with into {} of you lose sorted order gaurentee
11:53bradfordso you avhe to use sorted-map-by in order to inejct your own comparator if you want to compare values
11:54bradfordbut that doesn't play nicely with the (into foo bar) interface
11:55bradfordso 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:01rhickeybradford: a sorted map means sorted keys, not sorted values or pairs
12:01technomancyI 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:01rhickeygetting map-like performance and arbitrary sorting of values is wanting 2 different things at once
12:08Chousuketechnomancy: (get themap key notfound)?
12:09Chousuke,({:a 1} :b :FAIL)
12:09clojurebot:FAIL
12:15bradfordrhickey: 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:16bradfordChousuke: i don't like that overriding return behavior because it messes with another idea i had about map of fns.
12:17chouserdrewr: java.lang.* is imported automatically, but not clojure.lang.*
12:17bradfordbut its convienient :-) 6 of one, half dozen of the other
12:18technomancyChousuke: 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:19Chousukebradford: sometimes, a nil is a valid value and you NEED some other "not-found" value :/
12:28arohnerwow, 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:28the-kennyIs there something like filter, that lists the result of the predicate and returns a list of them instead of the original input-values?
12:29arohnerthe-kenny: map?
12:29the-kennyarohner: Yeah, but I want to filter for (pred x) = nil
12:30the-kenny...maybe a (filter (comp not nil?) (filter pred lst)) will do it.
12:31irumihahi 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:32irumihai thought thiws would be equivalent to (def s "somevalue")
12:32arohnerirumiha: def is a special form. it doesn't evaluate the first argument
12:32irumihaah, ok... didn't know that
12:34arohneryou can write a macro that will do that, if you need to
12:34arohnerthough usually that isn't done
12:34arohnerwhat are you trying to do?
12:35chouserthe-kenny: (remove nil? (map func coll))
12:35Chousukeit's pretty easy, actually... (defmacro defstring [string & rest] `(def ~(symbol string) ~@rest)) ... but not very useful :P
12:35irumihai am writing a macro that should up in (defn something...) with something being a String
12:35the-kennychouser: Ah, thats more beautiful than my version. Thanks
12:39irumihaChousuke: thanks, that pushed me in the right direction, now I'm off to create more problems :)
12:42drewrchouser: weird, I could have sworn I'd used bare clojure.lang classes before
13:45Kjellski,(doc proxy)
13:45clojurebot"([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:47IsaacL(doc fmap)
13:47clojurebot"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:47IsaacL(doc map)
13:47clojurebot"([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:48stacktraceris there a spelled-out equivalent of ` (backtick)?
13:48stacktracerthe way "quote" is equivalent to '
13:58chouserstacktracer: no
13:58chouserstacktracer: there may be eventually
14:00KjellskiHow can I make a Javaish cast in clojure?
14:00chouserKjellski: mostly you don't need to
14:01KjellskiActually I don´t know wethere I need that cast or not... but it seems like: FromHeader from = (FromHeader) req.getHeader("From");
14:01chouserwell, you don't need to declare locals, so for that line all you need is (let [from (.getHeader req "From")] ...)
14:02chouserdeclare the types of locals, I mean.
14:02tomojwhy does java need that cast, I wonder?
14:02tomojclearly we want a FromHeader, we already said so at the beginning of the line
14:03stacktracerchouser: okay, thanks
14:03Kjellskichouser : That´s what I did, just thought that calling methods on that uncasted thing would be dangerous...
14:04chouserKjellski: nope, not dangerous at all. You may want to type hint for speed, but that's strictly for performance not required at all.
14:04Kjellskichouser : Okay, thanks again... =)
14:07KjellskiCan I nest a function with an argument in the (.. macro ? Like a.b().c(foo).g; ?
14:07chouseryeah, but I recommend -> instead
14:07chouser(-> a .b (.c foo) .g)
14:08Kjellskichouser: *pressingthethankschouserbutton*
14:13ordnungswidrigre
14:18chouserordnungswidrig: good luck. but you won't need it. ruby->clojure is like going home.
14:23weissjis there a simpler way to predicate if an item is in a list besides (some (= item) list)
14:24chouser(some #{item} list)
14:24BjeringHi, 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:24weissjchouser: i was thinking there'd be a contains? pred, but i guess not?
14:24weissjjust for maps?
14:24chouserweissj: maps and sets.
14:25weissjchouser: ah ok i can use a set in this case. thx
14:26cemerickooh, something just clicked for me on protocols
14:27ambienthmm, how did i check channel max users?
14:27cemerick~max
14:27clojurebotIt's greek to me.
14:27ambient~maxusers
14:27clojurebotIt's greek to me.
14:27cemerick,max
14:27clojurebot#<core$max__4506 clojure.core$max__4506@1c39cb2>
14:27hiredmanclojurebot's max users is kind of broken atm
14:27cemerickah-ha
14:27hiredmanclojurebot: max users?
14:27clojurebotIt's greek to me.
14:27ambientit just peaked over 200
14:27chouserweissj: 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:27cemerickthat's pretty hefty for a language-focussed channel
14:28hiredmanclojurebot: how much do you know?
14:28clojurebotI know 474 things
14:29chouserweissj: if you're really sure you want to do a linear seach across a list you can use the .contains method.
14:29chouser(.contains '[a b c d] 'c)
14:29chouser,(.contains '[a b c d] 'c)
14:29clojurebottrue
14:29chousercemerick: just watch the google go video, it explains most of what you need to know about protocols.
14:29chouser:-)
14:30cemericklol
14:30cemerickchouser: you're really steamed about it, eh?
14:30chouserno, actually, that part amuses me quite a bit
14:30chouserclearly an idea whose time has come
14:30chouserthe rest of it just makes me tired
14:31jeremy_____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:31cemerickI've not watched the video. I don't imagine I'm going to bother. Things are getting busier, amazingly enough.
14:31hiredman~max people
14:31clojurebotmax people is 202
14:31chousercemerick: yeah, I was kidding. don't watch the video.
14:32chouserjeremy_____: there's partition-all in contrib
14:32hiredmanmaybe the max people thing isn't broken
14:32jeremy_____chouser: ah thanks!
14:33chouserjeremy_____: depending on what exactly you're trying to do, you might also look at split-at
14:34stuarthallowayokay if I create a branch on the official clojure-contrib to experiment with converting my contribs to deftype?
14:34stuarthallowayor should I hide out in my own corner of github
14:37chouserstuarthalloway: if the branch is for 'new' in general rather than your contribs in particular, then we can all share it
14:37stuarthallowaythat was my thought
14:37stuarthallowayI have one gen-class to convert to deftype
14:37stuarthallowaybut others probably will as well
14:44piccolinostuarthalloway: in an old clojure list post you mention that you were working on CSV parser. Did anything ever become of that?
14:45stuarthallowaypiccolino: not much. got busy and used SuperCSV instead
14:46hiredman(yay code re-use)
14:46piccolinoAh, OK.
14:46piccolinoI guess I should have done that instead of writing my own.
15:15lisppaste8stuartsierra pasted "Simple deftype/defprotocol example" at http://paste.lisp.org/display/90329
15:18hiredmanstuartsierra: nice
15:19chouserstuarthalloway: yeah, that's solid, thanks.
15:20stuarthallowaychouser: huh? ...
15:20chouserstuarthalloway: sorry, wrong stuart
15:20stuarthallowaychouser: I mean, yeah, thanks, I am the coolest Stuart around...
15:20chouserstuartsierra: that's solid, thanks.
15:20chouser:-)
15:21stuartsierrachouser: thx
15:21stuartsierraIt doesn't support mixing reals & complex's, not sure how that should work.
15:22weissjgiven a function that takes no args, how do i simply call it?
15:22weissjapply doesn't work here, afaict
15:22stuartsierraweissj: (foo)
15:22chouserto make it fit protocols you'd have to pull something like the kind of crazyness that is in the clojure.lang.Numbers
15:22technomancyso 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:22weissjso if i had a list of functions, i can do (map #(%) list) ?
15:22technomancyit's a one-line change and would really help w/ build scripts etc.
15:22technomancythoughts?
15:23stuarthallowaytechnomancy: agreed
15:23stuartsierratechnomancy: There's a patch is marked ready to test on assembla.
15:23stuarthallowaythough I am still hoping to just use circumspec
15:23technomancystuartsierra: awesome; I somehow missed the followup on that.
15:23stuarthallowaytechnomancy: you in SF Bay area next week?
15:23cemerickthere's already a map containing an :errors slot you can check, no?
15:24technomancystuarthalloway: yeah, I'll be at rubyconf. was hoping to say hi there.
15:24stuartsierracemerick: run-tests doesn't return anything by default
15:24stuartsierraThe patch changes that, and adds a "successful?" predicate.
15:24stuarthallowaytechnomancy: please do. Also I am running the 5k if that is your kind of thing.
15:24technomancystuarthalloway: I wish. =)
15:25technomancystuarthalloway: I've been building a tool around lancet that I'd like your feedback on: http://github.com/technomancy/leiningen
15:25cemerickstuartsierra: ah, I had written my own run-tests long ago that does merge-with + across the results of test-ns.
15:25stuartsierraweissj: yes
15:26weissjstuartsierra: thx
15:26stuartsierracemerick: that's what run-tests does internally, it just doesn't return the result, patch fixes that.
15:26stuarthallowaytechnomancy: did you see my email question about http client?
15:27cemerickonce test-is gets ripped out, I'll make myself drop all of my old testing code :-P
15:27stuarthallowaytechnomancy: feedback #1 on leiningen: no need to compare with lancet. It is clearly just a spike
15:27technomancystuarthalloway: yeah, I'm a bit backlogged on email. I think your change looks solid.
15:28technomancyerr, your idea for the change
15:28stuarthallowaytechnomancy: conjure is using lancet -- you should reach out to him as a key alpha user of leiningen instead
15:28technomancyah, good idea.
15:29technomancyI 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:30technomancyooh; this test patch would allow clojure-test-mode to be come simpler too; sweet.
15:31stuarthallowaytechnomancy: you should write a blog post about how lancet sucks, pillory me personally, recommend leiningen
15:31chouserwhat's a spike?
15:31technomancystuarthalloway: it's the guaranteed way to get readership!
15:31stuartsierraI guess truly general arithmetic would have to use multimethods anyway. (defmethod add [:Real :Complex] ...)
15:31technomancyI would need to put ads on my site first though.
15:31stuarthallowaychouser: http://www.think-box.co.uk/blog/2006/01/spike.html
15:32chouseroh, man. That's all I ever write!
15:32stuarthallowayat 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:32chouserexcept for my day-jobs I suppose.
15:33stuartsierraIn other words, 99% of what all programmers produce.
15:33stuarthallowaychouser: find a free six weeks and come write some spikes here!
15:33chouserstuarthalloway: ask me again when the kids are too old to notice I'm gone.
15:34dakroneis 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:34weissji thought lancet was pretty useful - couldn't find any other way to use any from clojure like that
15:34cemerick"why do you look so sad, little one?" "I'm a clojure-orphan."
15:34weissjs/any/ant
15:35cemericksorry, it was funny in my head
15:35stuarthallowayweissj: useful, but not fully thought out
15:35technomancyweissj: it's useful as a library, but not as a build tool... check out leiningen for that. =)
15:35chouserhehe
15:35weissjtechnomancy: no i just wanted the equivalent of AntBuilder in groovy
15:35weissjstuarthalloway: unfortunately it is the only alternative i'm aware of :)
15:37cemerickI'm worried I might have to break down and give in to the maven hordes for dep. mgmt.
15:37stuartsierradakrone: I think you need to break down and use a loop/recur
15:37rhickeyhrm, protocols are not golang interfaces...
15:38chouserrhickey: hehe
15:38dakronestuartsierra: okay, I'll try that
15:38stuarthallowayweissj: another alternative: http://twitter.com/stuarthalloway/status/5690154628
15:38technomancycemerick: 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:38chouserit's taken a while, but I'm finally learning some ways to tweak rhickey.
15:38stuartsierraMaven is easy. Just do everything "The Maven Way." :)
15:38technomancystuarthalloway: uh oh, I better get going whip this thing into shape!
15:38cemerickchouser: what's great is that the round trip on that one was at least ~an hour :-D
15:39fogus_chouser: His irrational fear of clowns?
15:39weissjstuarthalloway: ok, i meant to say at the time i needed lancet there was no alternative :)
15:39cemericktechnomancy: well, then you just have ivy, essentially.
15:39cemericki.e. insofar as ivy and maven use the same repos
15:40stuarthallowaykeeping 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:41technomancycemerick: 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:41woobyhas anyone played with using simple build tool with clj?
15:42rhickeystuart vs stuart - love it!
15:42cemericktechnomancy: yeah, I've only cared about the ant targets
15:43chouserstuarthalloway: you couldn't use proxy because you needed a named class?
15:44arohnerlisppaste8: url
15:44lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
15:44lisppaste8arohner pasted "invalid args?" at http://paste.lisp.org/display/90338
15:44arohneris that the error you get when you call a java fn with the wrong arguments?
15:47hiredmanarohner: there are only clojure fns
15:47arohnerfine. java method
15:47hiredman,(.foo nil)
15:47clojurebotjava.lang.NullPointerException
15:48arohnerI understand how normally NPEs can be generated. I'm surprised at the <init> and Unknown Source
15:49chouserarohner: I doubt that's the whole of the backtrace
15:49hiredman<init> is maybe a static block?
15:49lisppaste8arohner annotated #90338 "untitled" at http://paste.lisp.org/display/90338#1
15:49chouserI think <init> is the name given to instance constructors internally
15:49stuarthallowaychouser: not sure if it has to be named or not -- probably
15:50michaeljaakahi
15:50michaeljaakacan anybody give me an usage of function clojure.set/select ?
15:51michaeljaakais there also any simple way to call select method without clojure.set namespace?
15:51michaeljaakais there any import with :as x or something like this?
15:51michaeljaakaI'm trying to call (clojure.set/select #(= 2 %1) [ 1 2 3 4] )
15:51michaeljaakabut without success
15:52hiredman
15:52michaeljaakawhat is pred ?
15:52michaeljaakawhen I looked into set.clj
15:52chousermichaeljaaka: you probably just want 'filter' for that
15:52michaeljaakaI can see if (pred x )
15:52chouser,(filter #(= 2 %1) [1 2 3 4])
15:52clojurebot(2)
15:52michaeljaakano I'm just trying to figure out how to call select
15:52hiredmanmichaeljaaka: and what exception did you get?
15:53stuarthalloway(select #(< (.length %) 2) #{"a" "quick" "example"})
15:53michaeljaaka#<CompilerException java.lang.ClassCastException: clojure.lang.LazySeq cannot be cast to clojure.lang.IPersistentSet (NO_SOURCE_FILE:0)>
15:53hiredmanmichaeljaaka: what does that suggest about the input to select?
15:53michaeljaakathat arguemnt in function is not a seq
15:54chouser(use '[clojure.set :only [select]])
15:54stuarthallowayalmost: argument is a seq, but it not a set
15:54chouser(select :good #{{:name "C++"} {:name "Clojure" :good true}})
15:54stuarthalloway(swap! snark inc)
15:55michaeljaakaok
15:55hiredmanstuarthalloway: well, it's not a seq
15:55michaeljaakai see now
15:55michaeljaakathanks
15:55hiredmanclojure.*set*
15:56michaeljaakathanks!
15:56dakroneI 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:57tomojrecursion
15:57dakroneI understand recursion, but recursion with *what* is what I can't make the mental leap to yet
15:57hiredmanyou can use reduce to create map of n => instance count of n
15:59chouserdakrone: 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:59tomojare you trying to chop chunks off the list, run each of those chunks through a function, and then combine the results?
15:59dakronechouser: 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:00dakroneso giving more weight to numbers farther left in the list
16:00dakronetomoj: yea, that's basically it
16:01tomojwell, I don't really understand your pastie at all
16:01dakronethe (w-avg ...) function does what I want, if I wanted it segmented by 2 each time
16:01tomojbut you can do like (recur (take 3 seq) (drop 3 seq) <maybe an accumulator here>) to do what I described
16:01dakronebut if I want to segment by 3 each time, it doesn't do it
16:01tomojer, except without the first parameter
16:02tomojjust (recur (drop 3 seq) (<use (take 3 seq) and fold the result into the accumulator here>))
16:03dakronetomoj: okay, I'll try that, thanks
16:03tomojI don't actually know if that will help you.. don't understand weighted averages
16:03dakroneI think it will help me understand how to do what I'm trying to do more
16:04chouserI think partition and reduce will suffice
16:05tomojyeah better to use the helpers than to manually recur if you can avoid it
16:06dakronechouser: I'm not sure how to partition and carry through the average to be used for averaging again
16:06stuarthallowaytechnomancy: does leiningen help me if I am on non-released versions of stuff (e.g. named git commits)?
16:06dakroneso 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:07chouserdakrone: what's the correct answer to your example?
16:07dakronethe [1 2 3 4 5]?
16:08stuarthallowayare the higher weights at the beginning?
16:08dakrone7/3
16:08dakroneso it does 3 + 4 + 5 = 12, 12/3 = 4
16:08dakronethen 1 + 2 + 4 = 7, 7/3
16:09chouserhm... I think I'm close, but I must have a bug.
16:09dakroneexpanded it's (1 + 2 + ((3 + 4 + 5) / 3)) / 3
16:19lisppaste8Chouser pasted "for dakrone" at http://paste.lisp.org/display/90343
16:19chousera bit messy, I'm sure there's a cleaner way.
16:20maravillasah, partition-all
16:21chouseroh, sorry, left out the 'use' bit
16:21chouserI hate it when people do that.
16:21chouser(use '[clojure.contrib.seq-utils :only (partition-all)])
16:23chouserthe 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:25dakronechouser: I'll read and learn, thank you for the help :)
16:27technomancystuarthalloway: 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:28lisppaste8Chouser annotated #90343 "maybe cleaner" at http://paste.lisp.org/display/90343#1
16:30lisppaste8maravillas annotated #90343 "my contribution" at http://paste.lisp.org/display/90343#2
16:31maravillasalthough i guess there's a better method than (concat [%1] %2)
16:31maravillaslike cons :)
16:33maravillasoops, didn't use n
16:33lisppaste8maravillas annotated #90343 "size fix" at http://paste.lisp.org/display/90343#3
16:34stuarthallowaytechnomancy: makes sense
16:34chousermaravillas: that works for you?
16:35maravillasseemed to
16:35maravillasdid i miss something?
16:35chousernot sure, I'm just getting an exception
16:36maravillasoh, maybe the args? mine are reversed relative to yours
16:36chouseroh, yep, just found that.
16:37chouserI like yours better (if you were to use cons instead of concat anyway :-)
16:37maravillas:)
16:38dakronemaravillas: very readable, thank you much!
16:38maravillaswelcome
16:39maravillasit's funny how often i need something fairly basic, and then find it in contrib
16:39maravillaslike partition-all
16:40technomancystuarthalloway: I may revisit it if the jar repo thing doesn't take off.
16:41chousermaravillas: 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:41chouseruntil we do, we've got contrib. :-
16:41chouser:-)
16:41technomancyI wonder if there would be room for clojure.io in a future release.
16:42stuartsierraI've wondered the same.
16:42arohnerduck-streams is pretty great
16:42stuartsierraI've also wondered if clojure-contrib should be packaged into each Clojure release.
16:42technomancyI use duck-streams in probably 1 out of every 5 namespaces, and java-utils/file all over the place.
16:43chouserI use seq-utils, repl-utils, and str-utils2 quite a bit
16:43technomancy(only a slight exaggeration)
16:43maravillasyeah, i can understand that. i was mostly musing that i start to put together something just before i think to check contrib.
16:43hiredmanI should use contrib, I mean, I have it sitting there, compojure requires it, so it's like getting it for free
16:44lisppaste8stuarthalloway pasted "separate reduce/weight" at http://paste.lisp.org/display/90345
16:45stuarthallowaymaravillas: loved yours, just posted a slight mod
16:46fradiavaloxb
16:46the-kennyIt is possible to have two repls connected to the same clojure instance in emacs?
16:46the-kenny*Is it
16:46arohnerthe-kenny: yes, using swank
16:47the-kennyarohner: Can you tell me how?
16:47maravillasah yes, nice
16:47arohnerdownload swank-clojure
16:48arohnerstart it up in your process
16:48arohneroh wait, I'm answering a slightly different question
16:48arohneryou can make a clojure process than can serve multiple repls
16:48arohnerI don't know about one emacs process with multiple swank connections
16:49arohnerI'd be surprised if it's not possible, but I don't know how to do that
16:49the-kennyarohner: I have a running swank-clojure setup. I just want to create two repls pointing to the same clojure instance :)
16:50arohneroh, just try M-x slime-connect
16:50arohnerwhen it asks if you want to close the other connection, say no
16:51the-kennyhm.. what's the default port?
16:51arohner4005
16:51the-kenny4005 isn't working
16:51the-kenny"make process client failed"
16:51the-kennyew "make client process failed"
16:52arohnerI can tell you I manually start swank-server in my process, so I can access it all the time
16:52arohnerthat might be different than how clojure-mode does things
16:53drewrhas anyone experimented with using contrib as a submodule in clojure core in order to keep versions in sync?
16:53the-kennyLooks like clojure uses a local file
16:54stuartsierradrewr: yes, I did for a while
16:54drewrstuartsierra: no good?
16:55stuartsierraIt worked, but I decided it was easier to use Maven snapshots.
16:55drewrk
16:56stuartsierraMost libs in contrib are not tightly coupled to core, anyway.
16:57arohnerugh. Anyone have any good articles on implementing a stateful java API in clojure?
16:57stuarthallowaystateful how?
16:57arohnerinstance.loadData(data); instance.processData();
16:58stuarthallowaylooks done already, except for refactoring away instance :-)
16:59stuarthallowayare you implementing existing Java interfaces?
16:59arohneryes
16:59hiredmangoogle likes to use "Builders" where all the methods return this
16:59arohnerand I think I might have to extend a concrete superclass
16:59stuarthallowaygen-class is pretty straightforward
17:00hiredmandid defclass vanish into thin air?
17:00stuarthallowaysimple genclass example: http://github.com/stuarthalloway/programming-clojure/blob/master/examples/tasklist.clj
17:00arohneryeah, it looks fine. I'm mainly interested advice about style
17:00chouserhiredman: yes
17:00hiredmanneat
17:00chouserhiredman: deftype ate it
17:01stuarthallowayarohner: keep all state (if you need any) in a single object
17:01stuarthallowayother than that pretty trivial
17:01arohnerstuarthalloway: thanks
17:01hiredmanloadData should obviously return a FutureTask which processes the Data when you call .get
17:02hiredmanbut if you are implementing some api, :(
17:02arohnerhiredman: yeah :-(
17:02arohnerI'm doing some machine learning stuff. I have my own implementation already working, and in good clojure style
17:03arohnernow I'm trying to shoehorn my classifier into WEKA
17:03arohnervery Java-y API
17:03arohnerthe contrast is stark
17:03hiredmanmight be a good place to explore the new types and protocols stuff
17:03chousercan I use (are ... (thrown? ...)) somehow?
17:04arohnercan protocols implement an interface?
17:05chouserarohner: yes! using :on
17:05arohneroh, nice
17:05chouserand it makes them run faster too
17:06arohneroh, you can extend a class too!
17:06hiredmanI'm not clear on how that works, so feel free to lisppaste some examples
17:08stuartsierrachouser: (are ... ) expands to (do (is ...) (is ...)) so it should work
17:10stuartsierraarohner: in my experience, WEKA is easy to understand but very procedural, not to mention inefficient
17:16stuarthallowaystuartsierra: while on the subject of are--I find myself wanting each expansion to include a description
17:17stuarthallowayi.e. (are [desc a b c...] (something that reports desc on failure))
17:26froogsilly question, how do I check the length of a list?
17:27tomoj,(count '(1 2 3))
17:27clojurebot3
17:28froogtomoj: thanks
17:28froogI had used .length until now, but that doesn't work on lists
17:29tomojif you ask counted? on something it will tell you whether count will quickly give you the length
17:29tomoj,(counted? '(1 2 3))
17:29clojurebottrue
17:29froogthat's clever
17:29tomoj,(counted? (range 100))
17:29clojurebotfalse
17:30tomojyou can still count ranges but it won't be very fast
17:31tomoj,(time (count (range 100000)))
17:31clojurebot100000
17:31clojurebot"Elapsed time: 357.762 msecs"
17:31tomoj,(time (count (range 1000000)))
17:31clojurebot1000000
17:31clojurebot"Elapsed time: 362.483 msecs"
17:31tomojwat?
17:31tomojhow'd clojurebot do that so fast?
17:32_mstchunked seqs? (random guess)
17:32tomojI have chunked seqs I believe..
17:32tomojfor me it takes nearly 10 times longer to count (range 1000000) as it does (range 100000)
17:32Chousukemaybe it was a jvm fluke
17:32_atoit could be a JIT effect
17:33hiredman~clojurebot
17:33clojurebotclojurebot is like life: you make trade-offs
17:33_ato,(time (count (range 100000)))
17:33clojurebot100000
17:33hiredman~clojurebot
17:33clojurebot"Elapsed time: 31.894 msecs"
17:33clojurebotclojurebot is amazing
17:33Chousuke:D
17:33_atohaha
17:33tomojoh, I see
17:33tomojso yeah, linear
17:33hiredmanthere is another one, but I always feel bad spamming the channel trying to get clojurebot to say want I want
17:34_mst*chuckles*
17:42krumholt,(counted? (range 10000))
17:42clojurebotfalse
17:43krumholtthat returns true on my repl :)
17:44frooghere too
17:45krumholtmaybe that changed on some clojure version
17:46krumholt,(clojure-version)
17:46clojurebot"1.1.0-alpha-SNAPSHOT"
17:47krumholtstrange :)
17:54IsaacL(doc counted)
17:55clojurebotTitim gan éirí ort.
17:55krumholt,(doc counted?)
17:55clojurebot"([coll]); Returns true if coll implements count in constant time"
18:45michaeljaakaHi!
18:45michaeljaakaI have problem using inspector
18:45michaeljaakaI do
18:45michaeljaaka(require '(clojure.inspector))
18:45michaeljaaka(clojure.inspector/inspect #{ "hello" })
18:45michaeljaakaand get exceptino
18:45michaeljaakauser=>
18:45michaeljaakanil
18:45michaeljaakauser=>
18:45michaeljaaka#<CompilerException java.lang.ClassNotFoundException: clojure.inspector (NO_SOURCE_FILE:448)>
18:45michaeljaakauser=>
18:46michaeljaakawhat is wrong?
18:49tomojmichaeljaaka: it's (require 'clojure.inspector)
18:50michaeljaakawow, it works!
18:50michaeljaakathanks!
19:17michaeljaakahi
19:17michaeljaakaI would like to process two sequences
19:17michaeljaakawithin doseq
19:17michaeljaakato do that
19:17michaeljaakaI have to make
19:18michaeljaaka(doseq [ x y (map vector '(1 2 3) '(4 5 6))] and here goes body )
19:19hiredmannope
19:19michaeljaakais there any simpler way so I don't have to map sequences with vector function?
19:19michaeljaakathe real code is
19:19michaeljaaka(doseq [ [x y] (map vector (take 5 (iterate inc 0)) (take 5 (iterate inc 2))) ]
19:19michaeljaaka (println x " " y))
19:21tomojwell, you could do
19:22tomoj(dorun (map #(println %1 " " %2) (take ..) (take ..)
19:22tomojI would like for and doseq to be able to go through multiple seqs in parallel in a pretty way, though, hm
19:26michaeljaakawell with dorun is ok too
19:26michaeljaakabecause one of the sequences have side-effects
19:26michaeljaakaand it blocks on I/O
19:27michaeljaakabut dorun is prepared for such sequences
19:51slyrus_does anyone around have/use anything like a clojure-y slitex for making presentations/pdfs?
20:00chouser'range' changed
20:00chouser(class (range 100))
20:00chouser,(class (range 100))
20:00clojurebotclojure.lang.LazySeq
20:01aaron__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:02tomojwhat did range used to be?
20:02tomojaaron__: I think the idea I've heard most for serialization is to just prn and read
20:02tomojand I think there are some bindings you can use to make it better
20:03aaron__hmmm. well, i'm doing the serialization work in Java
20:03aaron__(my Java code uses some Clojure code for utility stuff, then runs with the output)
20:03aaron__so maybe i want to use the output from an addtl. prn to send across the wire?
20:04aaron__what i'm currently doing as a workaround is new HashMap(theMapIgotFromClojure)... but that's a lot of extra work to
20:05aaron__(too)
20:05tomoj~def pr
20:06tomojman those huge blobs on github make my browser cry
20:07aaron__tomoj: me too
20:08aaron__i wonder which is "better": serializing a new HashMap(theMapIgotFromClojure), or sending what i get back from prn
20:09tomojI have no idea
20:09aaron__hmmm... i have to juggle an extra stream it looks like, if i go the pr route. a little awkward
20:25chousertomoj: (range) used to return a Range object
20:27chouserI think
21:20kanakI 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:22devlinsfkanak: there's a flatten function in clojure contrib. Check the namespace clojure.contrib.seq-utils
21:23devlinsfkanak: it has some trouble with sets, btw...
21:23_ato,(apply concat [[1 2] [3 4] [5 6]])
21:23clojurebot(1 2 3 4 5 6)
21:23kanakdevlinsf: thanks. Checking it out right now. I'm not using sets so that shouldn't be a problem.
21:23_atoif it's just two levels that you want to flatten
21:23kanakI didn't want to do an apply because I don't want to have these seqs evaluated all at once.
21:25devlinsf,(str "Clojruebot???")
21:25clojurebot"Clojruebot???"
21:25_mst,(take 10 (apply concat [(range 1 5) (iterate inc 1)]))
21:25clojurebot(1 2 3 4 1 2 3 4 5 6)
21:25devlinsfcool
21:26kanakwait does this mean that apply doesn't force the evaluation of seqs?
21:26hiredmancorrect
21:27kanakcool :) I can just use apply concat then :)
21:35mtfcan anyone tell me how to load a .jar into a running clojure instance if i did not specify it in the classpath?
21:35mtfis there a repl command?
21:37chousermtf: you can try add-classpath, but it may not work depending on your context
21:37_ato~add-classpath
21:37clojurebotadd-classpath is bad, avoid it. I mean it!
21:37_ato:p
21:37_atoyeah it'll usually work for basic things
21:37drewr,(doc add-classpath)
21:37clojurebot"([url]); Adds the url (String or URL object) to the classpath per URLClassLoader.addURL"
21:37drewrmtf: better is to extract the jar's class files in a path already on the classpath
21:38mtfok thanks
21:38mtfand the path to the .jar file is a string right?
21:38mtfnot #P"/blah" like common lisp
21:38chouserString or URL
21:38drewr(add-classpath "file:///path/to/foo.jar")
21:38_ato(add-classpath "file:///some/dir/")
21:38mtfok
21:38mtfthx
21:47hiredman,(doc add-classpath)
21:47clojurebot"([url]); You are crunchy and taste good with ketchup"
21:48chousermuch better
21:48tomojwho is a french fry?
21:49tomojhmm, maybe "what would you say to me if I were a french fry?" ?
21:54devlinsfdo not meddle in the affairs of dragon
21:54devlinsfhttp://www.buzzymultimedia.com/meddle-not-with-dragons.html
22:07burnycan you nest transaction's? (send-off (some function that also sends-off))
22:07chouserthose aren't transactions
22:08chouserbut yes, you can send from inside an agent's action fn. The send will be held until the action completes.
22:09hiredmansame if you send from inside a transaction
23:17michaeljaakaHi
23:17michaeljaakaI want to create Thread
23:18michaeljaakaand watch how a println "Hello Wolrd" is executed
23:18michaeljaakaI have written somehting like this
23:19michaeljaaka(doto (proxy[Thread] ('run[] ( println "Hello World " )))
23:19michaeljaaka(.start))
23:19michaeljaakabut gets #<CompilerException java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to java.lang.ThreadGroup (NO_SOURCE_FILE:0)>
23:19michaeljaakauser=>
23:19michaeljaakaDo you know why?
23:23_atoyou don't need proxy: (doto (Thread. #(println "Hello world")) (.start))
23:24_atobut as to why, proxy takes two vectors before the methods, not one
23:24_atoand you dont need to quote run
23:25_atomichaeljaaka: there's some examples of using proxy here: http://en.wikibooks.org/wiki/Clojure_Programming/Examples/API_Examples/Java_Interaction
23:27george__is clojure faster or slower than java ?
23:28chouserhow could it be faster?
23:28george__taking slower time to run a program
23:28george__in JVM
23:30_atotechnomancy: ha! http://gemcutter.org/gems/clojure
23:32michaeljaaka_ato: thanks