#clojure logs

2011-09-26

09:37BlafaselTotally new, playing with 4clojure.com right now. At one point I'd like to get a number (int?) from a char. I guess I could resort to the java parsing methods. Is there an alternative? A 'clojure way' or some sorts?
09:37kzar,(Integer "12")
09:37clojurebot#<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: Expecting var, but Integer is mapped to class java.lang.Integer>
09:37kzar,(Integer. "12")
09:37clojurebot12
09:38kzarBlafasel: I think that is the normal way to go about it, I've seen it done like that in bits of code I've been reading
09:38BlafaselThanks a lot
09:40khaliganyone use lamina? i can't seem to find the receive-all function
09:41kzarBlafasel: I found it suprising too, the rule seems to be if the Java way works OK it's idiomatic to use it.
09:41Blafaselk, that simplifies the learning curve for some things here. Dear god, I hope no one is looking at the code I'm submitting to that site. :)
09:43kzarBlafasel: Heh, me and you both
09:48fdaoudBlafasel: which problem are you working on?
09:50Blafaselfdaoud: Uhm - already past it, no idea how to get back to the original thing.. It was something like 'multiply two numbers and return the product as a sequence of single digits.
09:51BlafaselI could show you my approach (feedback would be great), but I don't want to spoil the question for anyone?
09:53kzarBlafasel: IIRC I did something like this:
09:53kzar,(map (comp #(Integer. %) str) (seq (str "12345")))
09:53clojurebot(1 2 3 4 5)
09:53kzar(Oops of course I didn't mean to quote that 12345 number)
09:55fdaoudI love Clojure, but the number one thing with which I get burned is when something is lazy and I was expecting it to get called
09:57raekfdaoud: then use 'doseq' instead of 'for' and (dorun (map ...)) instead of 'map'... :-)
09:57fdaoudraek: you're right.. and doall (repeatedly ...)
09:58fdaoudI got burned on that last one because the first time I used repeatedly, it so happened that it was being passed as an arg and consumed so it got called
09:59BlafaselHmm. My lisp exposure so far is near zero, my functional experience limited to F#. I get a headache clicking on any 'source' link in the clojure docs so far.
10:09fdaoudBlafasel: another resource: http://java.ociweb.com/mark/clojure/article.html
10:21BlafaselHrmpf. This feels like butchering the language. I can solve ~most~ problems so far, but ..
10:30kzarHmm it seems to work OK including the old contrib with Clojure 1.3
10:36pdk1.3 released
10:37pdkmy world is rocked
10:37pdkis contrib updated too
10:38kzarpdk: In a sense, they've changed it around a bit http://groups.google.com/group/clojure/browse_thread/thread/c00088794dfdeaf5
10:38pdkhm
10:38pdkdo you have binaries for all of the contrib repos packaged together
10:46kzarHas anyone used the couchDB library Clutch with Clojure 1.3 yet? I'm getting this error "clojure.lang.KeywordLookupSite.<init>(ILclojure/lang/Keyword;)V
10:46kzar [Thrown class java.lang.NoSuchMethodError]" when I try and require com.ashafa.clutch
10:49kzarcemerick: Just saw you join, any idea how to get clutch working with Clojure 1.3? I get an error when I try and require it now (both 0.2.4 and 0.2.5-SNAPSHOT)
10:51cemerick0.2.4 is not 1.3 compatible. 0.2.5-SNAPSHOT is.
10:52cemerickmake sure you flush your project's lib directory and do `lein deps` again when you change dependencies (assuming you're using lein)
10:54kzarcemerick: Hmm so I did `lein clean`, made sure I've got 0.2.5-SNAPSHOT in project.clj, did `lein deps` again. Started REPL but I'm still getting an error when requiring clutch
10:56kzarcemerick: http://paste.lisp.org/display/124879
10:56gfredericksI'm trying to write a simple http proxy that simply adds a few headers to requests, then forwards them to another server. I tried this with ring + clj-http, but the difference in the interfaces is getting hairy. I'm starting to think it's simpler to do it at the TCP level. Would aleph be appropriate for this?
10:58cemerick`lein clean` does not touch lib AFAIK; can you make sure that /lib contains only v0.2.5-SNAPSHOT of clutch, and no other rev?
10:59kzarcemerick: Ah right, hmm looks like it's been cleared anyway: http://paste.lisp.org/display/124879#1
11:01cemerickoh, crud
11:01cemericksomehow, AOT classfiles from clojure-contrib slipped into the clutch 0.2.5 SNAPSHOT jar :-(
11:02IceD^just checking - is there any proper way to use current slime (20110617) with swank-clojure?
11:03kzarcemerick: Balls, sounds like a bugger - although I've got no idea what that means to tell you the truth heh!
11:03cemerickyeah; you shouldn't have to!
11:03cemerickkzar: I'm going to have to ping Tunde and get him to push a fixed build.
11:04kzarcemerick: OK, thanks for looking into it
11:08BlafaselCode works locally, fails with a (cryptic.. *sigh*) error message on 4clojure.com: java.security.PrivilegedActionException: java.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to clojure.lang.MapEntry
11:13BlafaselCan anyone shed some light on potential problems with this code here? Both "My eyes!!" comments as well as explanations regarding that ClassCastException would be greatly appreciated: http://pastebin.com/iyEA1DtZ
11:14IceD^anybody?
11:18lnostdalfunctional programming is a real pain when building macros; don't really need that there
11:21lnostdali guess with-local-vars is the way to go there
11:24TimMcIceD^: I can't tell if cemerick at __:03 was responding to you.
11:24cemerickIceD^: Sorry, no, I was talking to kzar
11:25manutterBlafasel: looking at your code now...
11:25TimMc(same here, unfortunately)
11:26TimMcBlafasel: You are way overthinking that 4clojure problem, for one.
11:27manutterBlafasel: I don't see anything technically wrong with your code -- it might not be optimal, but it should at least work
11:28TimMcBlafasel: Works in my 1.2 REPL.
11:29cemerickIs there a password reset on clojars? Perhaps I'm blind…
11:29gfrederickscemerick: profile?
11:30gfrederickscemerick: but it only works if nobody has ever uploaded a jar with the groupname 'cemerick'
11:30BlafaselTimMc: Same here. Overthinking: Probably... :)
11:30cemerickgfredericks: can't get there if I can't log in :-)
11:30gfrederickscemerick: oh nevermind then :)
11:30TimMcBlafasel: My golf score on that problem is 21.
11:30gfredericksI read "reset" as "change"
11:30Blafaselmanutter: Suggestions for improvements welcome - but you think that it should work as well?
11:30BlafaselTimMc: Ouch.
11:30cemerickgfredericks: yeah, I'll just try to catch ato next time he's around
11:31manutterBlafasel: yeah, should work. Come to think of it, this could be a sandbox bug too
11:31BlafaselI could think of a reduce of some sorts maybe..
11:31kzarBlafasel: Not sure if you saw, I got d/c there. My take on your solution was #(Math/round (reduce + (map-indexed (fn [i d] (if (= \1 d) (Math/pow 2 i) 0)) (reverse %))))
11:32manutterBlafasel: I think (reverse s) should help with something
11:32manutterOf course, if you're going for the golf score, the most "successful" solution might not be the most efficient
11:32TimMcMine is pretty efficient.
11:33BlafaselSure. I like both targets :)
11:33TimMcmanutter: And you could also make a non-deterministic solution by using "random".
11:34manutterTimMc: Heh, I'd like to see that one
11:34TimMcOr use cemerick's equals-everything solution.
11:34kzaroh I replaced Math/round with int and I got a gold score of ~75
11:34TimMcclojurebot doesn't fail on Blafasel's solution
11:35manutterYup, there's a bug somewhere at 4clojure.org I'd say
11:36TimMcWait, cemerick's (or was it chouser's?) trick won't work here.
11:40gfredericks$findfn (promise) false
11:40lazybotExecution timed out.
11:42TimMc$findfn 2 2 4
11:42lazybot[clojure.core/unchecked-multiply clojure.core/+ clojure.core/* clojure.core/unchecked-add]
11:43joly,*clojure-version*
11:43clojurebot{:interim true, :major 1, :minor 3, :incremental 0, :qualifier "master"}
11:46zerokarmaleftTimMc: it was chouser's
11:49BlafaselTimMc: Pfff.. Code Golf Score: 73
11:50BlafaselAnd I thought I'd be clever this time.
11:51BlafaselThe new version.. Not sure about efficiency, but seems more readable even. http://pastebin.com/eLducDuQ Is that the direction I should take?
11:54kzarBlafasel: You could get rid of the brackets around int I reckon
11:55TimMcBlafasel: Do you want a hint?
11:56TimMcBlafasel: Also, use apply instead of reduce.
11:57TimMcI like the use of map-indexed.
11:59BlafaselGood catch. apply and brackets save 3 chars and I get to 70. But still... ;-)
11:59TimMcapply is also more efficient here
11:59BlafaselI'd even consider this readable so far. But my creativity is limited. Let's look at what clojure/core has to offer..
11:59BlafaselWhy's that?
12:00TimMcreduce invokes + repeatedly. apply gives + the whole thing and lets it decide how to do the math.
12:00BlafaselAh. Thanks
12:01gfredericksTimMc: is that definitely more efficent for +?
12:01TimMcCould be.
12:01TimMcIn practice, maybe not!
12:01gfrederickshaha
12:02gfredericksI looked at the source for +
12:02TimMcHowever, reduce is never going to be *more* efficient.
12:02gfredericksactually...
12:02TimMc&source +
12:02lazybotjava.lang.Exception: Unable to resolve symbol: source in this context
12:02TimMc,(source +)
12:02clojurebotSource not found
12:02TimMcmeh
12:02gfredericksit calls reduce :)
12:02TimMcYeah, figured.
12:02gfredericksso I would say reduce is more efficient since you avoid the extra wrapper :P
12:02TimMcha
12:03TimMcBenchmark, benchmark, benchmark.
12:03TimMcgfredericks: And I suppose inlining won't apply here.
12:05gfredericksTimMc: no idea
12:05cemerickTimMc: That was chouser's :-)
12:06TimMcyeah
12:16TimMcWhy does this not print [1 1 1 1 1]? (read-string "#=(vec (repeat 5 1))")
12:16TimMcInstead, I get '[repeat 5 1]
12:16kzarOh, where did source and doc go in Clojure 1.3?
12:17TimMcrepl
12:18manutterTimMc: does (read-string "#=(vec #-(repeat 5 1))") work?
12:19manutteroops, that's #= in the second bit there too
12:19manutternot #-
12:27kzarIs there a way to do something like this? (defn (symbol "bad-example") [] (+ 1 2))
12:29ipostelnikkzar, why?
12:29kzaraka define something with the name of the value of a dynamic string
12:30bsteuberkzar: use a macro
12:31kzarbsteuber: Oh yea, cool that works
12:40amalloyTimMc: #= doesn't evaluate arguments
12:57TimMcamalloy: Fascinating.
13:00TimMcIs that behavior documented?
13:03TimMc,#=(+ 2 2)
13:03clojurebot#<ExecutionException java.util.concurrent.ExecutionException: java.lang.RuntimeException: EvalReader not allowed when *read-eval* is false.>
13:04amalloyTimMc: that #= works at all is only barely documented
13:05TimMchttp://clojure.org/reader is the place, I guess
13:05TimMcIt should be documented quite clearly due to the security implications.
13:05TimMcread-string also needs a note about *read-eval*
13:14TimMc(I have my CA printed out and filled in, but I haven't sent it off yet...)
13:44amalloysuppose i want to write a function that takes any number of args, but unroll a couple of the early cases for performance. say, (defn sum ([] 0) ([x] x) ([x & ys] (+ x (apply sum ys))))
13:44amalloyit's kinda awkward to have to treat x in the last arity specially; it would be nice if i could just have the last arity take [& xs], but not conflict with the other arities
13:45technomancyamalloy: (apply sum x ys)
13:45technomancyonly the last arg of apply is unrolled
13:46amalloytechnomancy: yeah, i know
13:46technomancyoh you're talking more generally
13:46amalloybut i still have to mention x, and if the actual handling is more complicated than just calling apply
13:46technomancyyeah, I don't think there's a way around that unfortunately
13:46TimMcTechnically, isn't [x] the same as [x & xs] for a 1-argument call?
13:47TimMc,((fn [x & xs] xs) 5)
13:47clojurebotnil
13:47TimMcSo that's an example of a potential conflict that is already avoided.
13:47amalloyTimMc: i don't follow
13:48TimMcOh, just that the compiler already knows how to distinguish between potentially ambiguous targets.
13:49TimMcI don't see a reason [], [x], [& xs] shouldn't be allowed.
13:53amalloyTimMc: right, which is what i'd like
13:55amalloyi agree it seems like it should be possible. looking at things, i think you'd have to make fairly significant changes to RestFn and at least some to fn
13:56amalloyand i guess to the compiler too, since it generates instances of RestFn
13:59amalloyin other words, probably not a fun change to make
14:10chouserwhat would be the harm in letting numerator return its arg when it's an integer?
14:10chouserand denominator return 1
14:11hiredmanwell, for anything non-ratio?
14:11chousersure
14:11hiredmansounds good to me
14:14amalloychouser: better to call rationalize instead? then it would work for doubles as well
14:18gfredericksI did not expect aleph to be difficult :(
14:18amalloy$google java nio bytebuffer
14:18lazybot[ByteBuffer (Java Platform SE 6)] http://download.oracle.com/javase/6/docs/api/java/nio/ByteBuffer.html
14:19amalloybut you shouldn't need to create a HeapByteBuffer specifically; it should accept any kind of ByteBuffer? i haven't really used aleph, but it seems weird to even make you deal with ByteBuffers at all
14:20gfredericksamalloy: ah yes I think this is the case.
14:20gfredericksI did not expect that the factory for a HeapByteBuffer would be in the abstract superclass
14:20gfredericksgo OOP
14:20gfredericksamalloy: It is definitely weird to deal with byte buffers
14:21gfredericksI'm not sure if it's necessary for what I'm doing...I'm kind of just being safe I think.
14:21amalloyi mean, they're java's high-performance io, so it's not totally implausible that aleph would let you work with them
14:21gfredericksaleph uses them if you don't specify a frame type
14:21amalloybut it doesn't seem like it would *make* you. mind linking to some code, or something in aleph you're using that needs this?
14:22gfredericksamalloy: I'm trying to make a basic http proxy that adds some headers to all requests
14:22gfredericksI started off trying it with clj-http+ring, but that seemed way too hairy
14:22gfredericksso now I'm trying to do it at the TCP level
14:23gfredericksand I assume that HTTP bodies can contain arbitary binary data
14:23gfredericksso I didn't want to deal with strings
14:24gfredericksI think that is a good summary. I can put together some code if you still want to see it.
14:24amalloynah. i don't really know enough about aleph for it to be worth your time informing me further
14:24gfrederickskay.
14:47sridi eval'ed something in the slime repl that in turn launches threads (via future). where would the stdout of that thread go? I don't see it in the repl at all
14:47bhenry*lein-swank* ?
14:48bhenrysrid that was directed for you to check that buffer.
14:48sridno such buffer. I use `cake swank` (terminal) and M-x slime-connect (emacs)
14:48bhenrydoes the terminal have anything?
14:48bhenryi've never used cake
14:48sridno, cake swank spawns the jvm/repl in background and returns immediately
14:48technomancyin swank-clojure 1.3.3 when launched with lein swank it will alter-var-root on *out* so that it will go to the slime buffer of the latest client to connect
14:49sridyou mean the *slime-repl Clojure* buffer? should I update it?
14:50sridoh, you are talking about lein swank.
14:50technomancyright, it will only work in 1.3.3-SNAPSHOT if whatever calls the start-server function passes in the optional flag to redirect output
14:52technomancyit's possible cake would let you pass in arbitrary arguments to that function
14:54ninjuddtechnomancy: cake actually doesn't call start-server directly :/
14:55ninjuddit is hacked to call start-swank-socket-server! so swank doesn't have to run in your project classloader
14:56ninjuddtechnomancy: i should probably put together a patch for swank-clojure allowing you to pass a wrap-fn for socket-serve so i don't have to do evil things like that...
14:57technomancyhm; well as long as opts is passed through then setting the relevant flag should do the trick
14:57technomancyor that
14:57technomancy:repl-out-root true
14:57sridninjudd: any workaround meanwhile? or should I switch to lein swank?
14:58ninjuddyou can run 'cake log' to tail the log. it should have the output you're looking for
14:58dpritchetti'm finding that ~40 lines is the point at which i start thinking any JS file should really be rewritten in coffeescript
14:59dpritchettgotta try clojurescript soon
15:01amalloymanutter: surely you mean one line, with 200k characters on it?
15:01manutteroh well sure, after you minify it
15:01manutterif we dared...
15:02amalloyminification is such a funny concept to me. i guess it makes sense in an interpreted language that you serve over the wire, but it's just so silly
15:02gfredericksamalloy: only thing sillier is maxification
15:03ibdknoxgfredericks: I really like maxification.
15:03BlafaselTimMc: Okay, I _had_ to cheat on that binary thing and even then I only got down to 20.
15:03BlafaselTimMc: Are you seriously telling me that you have a nice, somewhat idiomatic solution in 23 chars?
15:04ibdknoxgfredericks: it's the only way to make sure you have all your bases covered ;)
15:04dpritchettwait are people minifying 4clojure answers somehow?
15:05Blafaseldpritchett: For fun and profit! ;-p
15:05amalloyBlafasel: you were having some problem with 4clojure earlier?
15:05Blafaselamalloy: ~depends~. I had code that worked in the repl but didn't on that site. Does that count?
15:06amalloyhttps://github.com/4clojure/4clojure/issues/71 has been known for a while, and from your paste looks like you ran into it
15:06BlafaselI improved the code a lot afterwards and the _better_ code worked :) So - no problem
15:06amalloybasically, in 1.2.x, you can't (eval (macroexpand '(case ...)))
15:07Blafaselamalloy: Sounds like it, yeah (that eval quote of yours is black magic/voodoo to me so far I've to admit)
15:07Blafaselamalloy: But - in that case a ban (or a 'case probably won't work' warning) would be a great intermediate step
15:08amalloyBlafasel: *nod* we just never found a good way to...mention it, in a place where it would make sense
15:08gfredericks(def maxify (partial wk/postwalk (partial list 'identity)))
15:08BlafaselI've to admit that I tried to solve most of the (tiny) problems so far by typing random things in that input box, looking at the clojure 1.3 docs at the same time. You were my repl and if you say 'Nope, that is crap' although it isn't: Sad panda.
15:08amalloygfredericks: prewalk would really maxify it
15:09Blafaselamalloy: Understood.
15:09amalloy&(macroexpand '(case 1 2 3))
15:09lazybot⇒ (let* [G__13737 1] (case* G__13737 0 1 0 0 (throw (java.lang.IllegalArgumentException. (clojure.core/str "No matching clause: " G__13737))) {0 [2 3]} false))
15:09gfredericksamalloy: you mean both together, or prewalk instead of postwalk?
15:09amalloygfredericks: prewalk instead
15:09amalloyshould expand infinitely, i think. maybe postwalk does too, but that's less clear to me
15:10gfredericksamalloy: definitely blew the stack
15:10gfredericksamalloy: the postwalk one is quite tame
15:10BlafaselGreat. From voodoo to gibberish.
15:10gfredericks,(let [maxify (partial clojure.walk/postwalk (partial list 'identity))] (maxify '(+ 3 (* 4 5) 4)))
15:10clojurebot#<CompilerException java.lang.RuntimeException: java.lang.ClassNotFoundException: clojure.walk, compiling:(NO_SOURCE_PATH:0)>
15:10amalloyBlafasel: basically. case is a macro built into clojure, so it expands into some other code. normally, you can eval whatever code you want, but case has a bug that means the code can't be executed if you've macroexpanded it manually
15:11gfredericks&(let [maxify (partial clojure.walk/postwalk (partial list 'identity))] (maxify '(+ 3 (* 4 5) 4)))
15:11lazybot⇒ (identity ((identity +) (identity 3) (identity ((identity *) (identity 4) (identity 5))) (identity 4)))
15:11BlafaselSo it's like a kettle that only boils if you don't watch it? :)
15:11amalloyhah. yes, something like it
15:12gfredericksunfortunately gzip probably cuts out most of the space the identities take up, so most of the benefit is lost
15:14BlafaselTimMc: If you wake up I'd be curious about your 'codegolf' version. My cheat uses the java classlib now and only shoves off 3 chars of yours, I cannot imagine doing _anything_ meaningful in a functional way in 23 chars for that..
15:15amalloyBlafasel: you should be able to follow him and see it yourself
15:17Blafaselamalloy: He doesn't seem to use the same nick :)
15:17Blafaselamalloy: And there's no feature to look at the codegolf submissions, right?
15:17amalloyshortest solution looks like 17 characters
15:17BlafaselWah?
15:17amalloyassuming we're talking about http://www.4clojure.com/problem/122
15:18BlafaselWe are.
15:18amalloyfollow youz, if you want to see the shortest possible solution for every problem on the whole damn site. that guy is incredible
15:18BlafaselAnd I considered 20 based on java alone cheating already :)
15:19amalloydarren has an equally-short solution, and is usually also pretty short, if you're into that
15:19TimMcBlafasel: Mine is 21 chars.
15:19Blafaselamalloy: Okay, all these guys are cheating like me :)
15:19BlafaselTimMc: 20 here, but - what are you doing?
15:20TimMcI used Integer/parse
15:20amalloynot cheating at all! clojure is hosted, and java is your friend
15:20BlafaselI know, I know..
15:20TimMcIt's not cheating. Using the Java libs is fine.
15:20BlafaselBut - learning clojure is something else :)
15:20TimMcNot using the Java libs is good for the exercise.
15:20amalloythere are some problems where you can do things that are pretty close to cheating, but we encourage these sorts of mild hacks
15:20BlafaselTimMc: #(Integer/valueOf # 2) is 20
15:21TimMchah
15:21TimMcI can get 24 without using Java libs.
15:21BlafaselPics or it didn't .. - erm: paste!
15:22amalloyeg, a fun trick is to have your solution be multiple forms, instead of just a single function. see, for example, youz's solution to http://www.4clojure.com/problem/88
15:23TimMcamalloy: How do you do that?
15:23TimMc(See other users' answers, that is.)
15:23TimMcBlafasel: #(read-string (str "2r" %))
15:23amalloyTimMc: if you've solved the problem yourself, you can see answers from any user you follow
15:23TimMcfollow?
15:23amalloyfollow from the profile page at http://www.4clojure.com/user/youz
15:23amalloythis is a newish feature
15:24TimMcIs this some newfangled Twazzer thingmabob?
15:24amalloyi hope not
15:24Blafaselamalloy: Didn't solve that yet. Vodka and beer on my desk. Let me see..
15:24TimMcor whatever you kids are calling it these days
15:24Blktgood evening everyone
15:26amalloyBlafasel: well, you can see a similar example in amcnamara's (or my) solution to http://www.4clojure.com/problem/23
15:33ibdknoxamalloy: huh, learn something new everyday. I thought you always had to quote to get an empty list, which in retrospect is dumb of me
15:34amalloyibdknox: meh. you do have to in scheme and CL, even though it's equally silly there. not an unreasonable assumption
15:34TimMcibdknox: Amusing result of that decision: #()
15:34TimMc,#()
15:34clojurebot#<sandbox$eval17434$fn__17435 sandbox$eval17434$fn__17435@1d664>
15:34TimMc,(#())
15:34clojurebot()
15:34ibdknoxhaha
15:34gtrak`weird
15:35TimMcThat's how the macro expands.
15:35TimMc(fn [] ())
15:35gtrak`,(fn [] ())
15:35clojurebot#<sandbox$eval17490$fn__17491 sandbox$eval17490$fn__17491@30114>
15:36gtrak`,((fn [] ()))
15:36clojurebot()
15:38TimMcSo (#(constantly ())) is redundant, but (#(constantly 5)) is not.
15:38TimMcamalloy: Could 4clojure make up its mind about www vs. no-www?
15:39gtrak`,(#(constantly ()))
15:39clojurebot#<core$constantly$fn__3684 clojure.core$constantly$fn__3684@1a0476f>
15:39amalloyTimMc: well, we currently accept both. would you like us to do something different?
15:39gtrak`TimMc, not sure what your distinction is there.. maybe you want a fxn that returns an empty list instead of an empty list?
15:39TimMcgtrak`: Erm, never mind.
15:39gtrak`,(())
15:39clojurebot#<ClassCastException java.lang.ClassCastException: clojure.lang.PersistentList$EmptyList cannot be cast to clojure.lang.IFn>
15:39gtrak`yea
15:39TimMcGot some levels confused.
15:40TimMcamalloy: My password manager thinks there are 4 different sites (when you include http/s), and logging in on one does nothing for the others.
15:40TimMcYou effectively have 4 websites with a shared back end.
15:41gtrak`i love that the clojurescript compiler is one file
15:43TimMcgtrak`: I was thinking of identity, not constantly.
15:44dnolengtrak`: ClojureScript compiler is pretty neat all around.
15:44gtrak`yea, just been looking at it, that browser repl is super-powerful, too
15:45amalloyTimMc: yeah, i'm aware that that's the basic behavior. we could 301 redirect one of the domains to the other, i guess
15:45gtrak`,(identity ())
15:45clojurebot()
15:46amalloybut i don't want to force either http or https
15:46TimMcYeah.
15:46gtrak`TimMc, even with 'identity' in place of 'constantly', I'm not sure I get what you're saying
15:47TimMcamalloy: I'd be pretty happy if all you did was change the cookies to always have host=4clojure.com (no www)
15:47amalloyhm
15:47amalloyi don't know how to do that, though
15:47TimMcamalloy: But a 301 (302 at first) redirect would be good too.
15:48amalloywhy 302 at first?
15:48TimMcIn case you want to change your mind.
15:48TimMcI always put in a 302 for the first month or so, in case I have made a mistake.
15:48TimMc301 instructs browsers, proxies, and spiders to permanently update their records.
15:49TimMc(unless I have them reversed)
15:49amalloyTimMc: no, you're right
15:50Blafaselamalloy: Submitted a new twist of the 17 char solution..
15:50amalloyi read somewhere that if we're canonicalizing on one domain, it should include the www. this way we don't have whole-host cookies, and can set up a cookieless subdomain
15:50BlafaselBut .. seems like that's the end of it :)
15:50TimMcI wish we didn't have this www/no-www dichotomy, but the result is that every top-level website has to deal with it. :-(
15:50amalloyTimMc: btw, we actually have 8 servers, not 4 - .org also works :)
15:50TimMc>_<
15:50ibdknoxlol
15:51jaskiratdoes any one know if its possible to declare a java class field annotated as @Autowired using gen-class or some other mechanism?
15:51ibdknoxamalloy: for some DNS's having the www. will also prevent a second look up making the site "faster"
15:51TimMcexcuse me, CNAMEs
15:51TimMcA is address
15:52amalloyBlafasel: i can't really go look at it without knowing your username
15:52BlafaselRight.
15:52amalloyibdknox: yeah, i think our dns is set up so that that's not an issue, but i could be wrong
15:52TimMcBlafasel: My username here is timmcBasis. At home it is TimMc or maybe phyzome.
15:52BlafaselInstead of #(BigInteger. % 2) you can go for #(Long/valueOf % 2)
15:52BlafaselProblem: Same thing -> 17 chars
15:53amalloy*nod* darren's solution, which i pointed you at, does that, i think
15:53BlafaselTried to find anything smaller, but..
15:53Blafaselamalloy: Oh.. The one's I'm subscribed to right now don't. And the shortest is the youz version w/ BigInteger.
15:53BlafaselSry, must have missed that.
15:55BlafaselThere's no way to have something a la '1L' in clojure, right?
15:55Blafasel(not (long 1) please, that's - erm - too long)
15:55TimMc1N...
15:56BlafaselTimMc: Try-Clojure says 'invalid number'
15:56TimMcHow about 1M?
15:56amalloy(a) ew, (b) 1N is new in 1.3
15:56TimMchaha
15:57BlafaselTimMc: 1M is a bigint, works.
15:57TimMc,(class 1M)
15:57clojurebotjava.math.BigDecimal
15:57TimMc,*clojure-version*
15:57clojurebot{:interim true, :major 1, :minor 3, :incremental 0, :qualifier "master"}
15:58gfredericks,(type (numerator 1/2))
15:58clojurebotjava.math.BigInteger
15:58Blafasel,(class 1N)
15:58clojurebotclojure.lang.BigInt
15:58TimMcBlafasel: 1.3 introduces BigInt
15:58BlafaselThat's not available on 4clojure, right?
15:58amalloyright
15:59gfredericks,(count "(numerator 1/2)")
15:59clojurebot15
15:59amalloyi've explored upgrading to 1.3 and it's just a huge pain. i would be deliriously happy to accept a patch from someone else that does it
16:00BlafaselRight. Someone that knows clojure. Any takers? :-p
16:00gfredericksamalloy: break the task up into 4clojure exercises, and...
16:00BlafaselDammit. Wanted to exploit calling a static method on an instance and remove the long with 1l or something..
16:00Blafaselamalloy: gfredericks has a point :)
16:01gfredericksit'll be just like recaptcha
16:05BlafaselThere's a nice short story from Doctorow where someone trains an AI by sending spam and evaluating the response. Better result -> fitter ;)
16:16BlafaselWhy does (.toString 1) work, while (.toString 1 2) doesn't (the latter ~could~ resolve to a static method, no?)
16:17amalloyBlafasel: the ability to call static methods as if they were instance methods is part of javac
16:17Blafaselamalloy: Ah. Dammit, another cheat ruined :)
16:17amalloyyou could add code to clojure.lang.Reflector to make it work, but it's not really a great idea anyway
16:17BlafaselNo, it's not.
16:17amalloyclever idea though
16:17BlafaselIt's just a way to shove of some chars.
16:17Blafasel#(.valueOf 1 % 2)
16:17Blafaselwould've been nice
16:17amalloy*nod*
16:18Blafasel(for certain values of nice...)
16:18amalloyby the way, there is a #4clojure channel. i don't imagine #clojure minds discussion of 4clojure, but you can come hang out with us too if you want
16:23arohnerI have a lein plugin listed in dev-dependencies, and its in checkouts/, but I'm getting "That's not a task". Is that supposed to work?
16:28bhenryarohner you have to lein plugin install org.lein-plugin "version-string" or something like that
16:29bhenry$ lein plugin install lein-clojars "0.6.0"
16:29bhenrythen tasks become available
16:30ljosHi - I'm wodering something. I have a project and I have to do some of it in Java, but some parts of it does not necessarily need to be Java and I would like to use Clojure for it. What I'm wodering is what is the easiest way of making a mixed project? What IDE/editor would you use? Are there any best practices for this kind of projects that are written some where? Do I need to package the Clojure code into a jar to call it from Java or is it possible to do in
16:30arohnerbhenry: I know the "normal" way to do it, I was hoping to avoid the install + deps cycle because I'm writing the plugin
16:30arohnerbut symlinking the plugin's src into my project's source worked
16:30technomancyarohner: plugins have to be known before the outer JVM launches, so you can't calculate them within clojure code.
16:32arohnertechnomancy: then how come symlinking the code into my project worked? symlinking lein-foo/src/leiningen into my-proj/src/leingen/ works just fine
16:34technomancyarohner: src/ is always on the classpath
16:35choffsteinIf I create an uberjar, is there a way to make sure the .clj files don't get added?
16:35arohnertechnomancy: ok, now I'm confused. "lein classpath" showed that my checkout plugin was in the path too. Was it lying?
16:35technomancy"lein classpath" tells you your project's classpath
16:36BlafaselStupid question: Why are the 'source' links in the clojure docs still linking to Rick's github repository, which is outdated according to the header/readme?
16:36technomancytasks in plugins must run in leiningen's own JVM, the classpath for which must be calculated in bin/lein
16:36BlafaselIs that a recent change?
16:36arohnertechnomancy: ah. ok, thanks
16:36technomancydoc/PLUGINS.md explains more
16:37amalloyBlafasel: that github repo has been defunct for ages. if you see anywhere that you can replace them, go for it
16:37technomancyljos: mixed-source projects are not hard; just add a :java-source-path key to project.clj and leiningen will pick them up
16:37belunhello
16:38belun(defrecord Comment [text]
16:38belun2.
16:38belun
16:38belun3.
16:38belunNodeStreaming
16:38belun4.
16:38belun(stream [node strategy out]
16:38belun5.
16:38belun(write out "<!--" text "-->")))
16:38belunwhat is 3. here ?
16:38clojurebotNo entiendo
16:38belunprotocol ?
16:38belunNodeStreaming
16:38belunsu bot :P
16:38amalloyjesus. never do that. please put huge code snippets on gist.github.com or some similar paste service
16:38belunaaah the snippet again
16:39amalloyto answer your question, it is either a protocol or an interface
16:40belunok thx. so when howard
16:40belunhttp://java.dzone.com/articles/changes-cascade-and-cautionary#comment-form
16:40belunsays that the inners of a record
16:41belunare carried as vals
16:41beluninside protocol definition
16:41belunwho does that ?
16:41belunthe record or the protocol
16:41beluninside protocol declaration
16:41belun**
16:42RaynesSentences can all be on one line.
16:43belunhuh ?
16:43belunnea timestamp ubbers it :P
16:43belunif u have it...
16:47belunso anyone understand my question or i'm talking gibberish ?
16:47TimMcIt's hard to tell what your question is -- use more punctuation!
16:48amalloyclojurebot: punctuation is preferred to a torrent of newlines
16:48clojurebotRoger.
16:48RaynesLess enter, more period.
16:53belunso, if you create a protocol and attach it to a record, when delaring the record you have to implements its methods (corresponding to the protocol). now inside the body of these methods, apparently you have vals created for you
16:54belunthose vals are representatives of the record's fields (as seen in the post http://java.dzone.com/articles/changes-cascade-and-cautionary#comment-form)
16:55belunso, who created these vals for me, the defrecord or the defprotocol ?
16:59belunand an example on gist https://gist.github.com/1243395
16:59dnolenbelun you don't attach a protocol to a record, you extend a type to a protocol.
16:59dnolenbelun: an by vals do you mean access to the fields?
16:59belunyes
17:01belundnolen: so the term is not "attach", but "extend", right? the technique is the same, though
17:01dnolendefrecord is a fancier version of deftype, deftype supports, 1) defining fields, 2) implementing methods of a protocol
17:02bhenryhow would one check for equality in value and type?
17:02amalloybhenry: .equals is usually enough, i think
17:02amalloy,(.equals () [])
17:02clojurebottrue
17:02amalloyhm
17:03amalloy&(every? true? (apply map = ((juxt identity class) [] ())))
17:03lazybotjava.lang.IllegalArgumentException: Wrong number of args (2) passed to: core$identity
17:04belunso if i want to put that gist on clojuredocs, where should i put it? on defrecord or defprotocol? (my guess is defprotocol)
17:04amalloymeh. that's probably too complicated anyway; just check if the classes are equal and then if the objects are equal
17:06beluneeem, functions inside protocols are methods or functions ?
17:09TimMcbelun: protocols create functions
17:10TimMcIn your example, "drinky-drinky" is a function.
17:11belunTimMc: but it is attached to a protocol :( doesn't it have a special name ?
17:12TimMcNot sure what you're asking.
17:13TimMcThe protocol has a name, and the functions have names. The protocol manages dispatch of calls to those functions based on what types it has been extended to cover.
17:14belunTimMc: like in Java, a function that is defined inside a class is a called a method of that class. and same goes for a procedure. in clojure, a function attached to a protocol is called ... ?
17:14upwardindexahhhh forward declarations?! the clojure gods have cursed us! why oh why?
17:14TimMcupwardindex: declare?
17:14upwardindexyes that is the cause of my sadness
17:15amalloythere are a number of good reasons clojure requires forward declarations. not least of these is that, if you need a declare, you are probably doing something wrong anyway
17:15TimMcbelun: Java doesn't *have* functions -- they're just called methods.
17:16upwardindexi can't seem to find any good reasons besides the JVM, please enlighten me amalloy
17:16belunTimMc: java's functions are methods (i learned pascal first). i have to abstract upwards :P
17:17hiredmanupwardindex: why would the jvm require it?
17:17amalloyit means the compiler can treat a program as a stream of characters, instead of a big interconnected mess of files
17:17upwardindexamalloy: we might want to communicate these good reasons for forwards decls to the people working on the next common lisp standard, that feature is lacking
17:17TimMcamalloy: Like a REPL. :-)
17:17hiredmanupwardindex: clojure is not common lisp
17:18amalloy(defn foo [x] (bar x)) is an error RIGHT NOW unless bar is already defined
17:18amalloyin CL, it's just fine, cause who knows, maybe you'll define bar later
17:18dnolenupwardindex: has nothing to do w/ the JVM, long threads about it on the mailing list, plus the kind of nastiness that is avoided by lacking them.
17:18gtrak`yay spelling errors!
17:19upwardindexdnolen: thanks I'll have a look there for more information
17:19gtrak`upwardindex, early binding
17:20upwardindexHowever it does prevent from using a top-down approach in programming which you can't in many languages but is so sweet
17:20gtrak`what's top-down mean in this context?
17:20amalloyupwardindex: lisp encourages bottom-up anyway
17:21TimMcgtrak`: bottom-up is when you define your building blocks first
17:21jolyboth should refer to how you approach solving the problem, not the order you define the functions
17:21upwardindexcodinghe high level functions first
17:21upwardindexamalloy: really? I always thought the opposite
17:21gtrak`you can use protocols and define interfaces to your functions... is that not it?
17:21TimMcWhen LISPers pick up a novel, they always skip to the end of the book first and work backwards.
17:21amalloyupwardindex: have you read On Lisp?
17:22upwardindexamalloy: No unfortunately, I read PCL though
17:22upwardindexanyways, I still love clojure
17:23amalloyin the intro: "The theme of this book is twofold: that Lisp is a natural language for programs written in the bottom-up style, and that the bottom-up style is a natural way to write Lisp programs"
17:23upwardindexI'm just saddened that its not as DRY as I first thought
17:23TimMcupwardindex: declare is kind of a last resort
17:23amalloyupwardindex: it is. don't repeat yourself: write your primitives first
17:23TimMcYou don't have to use it!
17:24amalloyupwardindex: also, On Lisp has a gorgeous writing style. PCL is useful, but i really enjoyed On Lisp
17:24upwardindexamalloy: reading the primitives first is not always the best way…
17:24amalloyso skip to the bottom and read going up
17:24amalloyreading (declare) first is *definitely* not the best way
17:25brehautupwardindex: then write your primatives in another namespace
17:25amalloythat too
17:25upwardindexamalloy: ah so what TimMc said about lispers was really about clojurians! :P
17:25amalloysigh
17:25upwardindexjust having fun here, don't take me too seriously
17:26TimMcupwardindex: Clojure is a LISP.
17:26upwardindexbrehaut: that is very clever, thanks for that suggestion i like it a lot more than declare
17:27amalloyanyway, book is at http://lib.store.yahoo.net/lib/paulgraham/onlisp.pdf in case you were not aware. well worth spending some time on even if you never write CL
17:27amalloyi certainly don't
17:28dnolenupwardindex: if you've ever dealt w/ CL symbol interning, Clojure tries to avoid that. So we lose something and we get something.
17:30dnolenthe other big benefit is capturing common typo errors w/o requiring whole program analysis - worth the price of admission IMO.
17:32upwardindexOn another note, what are the best sources of news for clojure besides planet clojure?
17:32brehautrelated: benefits of F#'s significant compile order http://cs.hubfs.net/forums/13172/ShowThread.aspx#13172
17:33brehautupwardindex: http://disclojure.org/
17:33dnolenbrehaut: nice
17:35dnolenbelun: re: deftype/protocols. Methods in Java are not first class. Clojure gives polymorphism w/o losing the power of functions.
17:36amalloyupwardindex: also the google group, and irc
17:37belunwill videos from last strangeloop be available anywhere ?
17:37gtrak`belun, they will gradually be released over time on infoq
17:38dnolenbelun: will take a long while from what I hear. But I suspect they'll put keynotes up first.
17:41sridi have a bunch of modules with "initialize" function (that spawns a future and what not). see example - http://dpaste.com/621560/
17:41sridwhat is the recommended way to "manage" these futures so I can shutdown or restart on them?
17:42sridI use REPL to development, so I really must shutdown existing components (read: futures and what not) before launching them again
17:43vojdwin 7
17:43technomancyman... if only there were a restart-agents function.
17:43vojdsorry :( irssi fail
17:43sridone solution is to use atoms to store futures, http://groups.google.com/group/aleph-lib/msg/18df7972f68cd3ed but I don't if this accepted
17:43sriddon't know*
17:45sridi am forced to do 'cake killall', relaunch swank and everything :(
17:45gtrak`can you force them to get garbage collected by re-binding the vars?
17:46ibdknoxsounds like you should be using a pool
17:47sridis pool a language construct or external library?
17:49ibdknoxhttp://stackoverflow.com/questions/5397955/sleeping-a-thread-inside-an-executorservice-java-clojure
18:42mjg123Hi all. I'm trying to find a way to take a zip file (on the classpath) and unzip its contents to a given directory
18:43mjg123is there anything you know of that can help me?
18:43mjg123or just bash through with java interop
18:47ibdknoxmjg123: I don't know of any real solutions other than Java interop, a quick search turned this up though: https://github.com/ToddG/experimental/blob/master/clojure/doc01/src/doc01/zip.clj
18:48amalloymjg123: java's zip files are pretty awful; you might consider shelling out to bash instead, if you know that bash will exist and you'll have permissions
18:48mjg123ibdknox, thanks, read that one :)
18:49technomancymjg123: you can do it in about 10 lines; see Leiningen's leiningen.jar/extract-jar defn
18:49mjg123amalloy, that's fine, bash is there. But the file isn't, it's on the classpath (ie inside the jar)
18:49ibdknoxamalloy: yeah looking at that code made me a little sick :p
18:51mjg123technomancy, thanks.
18:52shep-homeSay I had a sequence and I wanted to number each item AND know what the max number was
18:52mjg123technomancy, so I'd have to create a JarFile from the URL given by classpath.getResourceAsStream?
18:52shep-homeI could use something like map-indexed and then find the last item
18:52shep-homebut that seems... inelegant
18:53brehaut,((juxt (partial apply max) (partial apply +)) [1 2 4 3])
18:53clojurebot[4 10]
18:53amalloyshep-home: reduce is your best choice, i think
18:54brehautwhoa, amalloy didnt recommend juxt!
18:54shep-homebrehaut: I'll get back to you in an hour or so when I grok that :-)
18:54amalloybrehaut: i didn't get the impression he wanted to sort them
18:54ibdknoxyeah
18:54ibdknoxthat's not what he asked
18:55technomancymjg123: maybe. try it out.
18:55amalloy&(let [items '(a b c)] (reduce (fn [[i acc] x] [(inc i) (conj acc x)]) [0 []] items))
18:55lazybot⇒ [3 [a b c]]
18:55shep-homeAn example would be [:a :b :c], then I get something like [[:a 0] [:b 1] [:c 3]] and know that 4 would be the next number
18:55amalloy&(let [items '(a b c)] (reduce (fn [[i acc] x] [(inc i) (conj acc [x i])]) [0 []] items))
18:55lazybot⇒ [3 [[a 0] [b 1] [c 2]]]
18:56shep-homeyeah, kind of like that
18:56shep-homeok, now I'ma go sit in the corner and meditate on these solutions
18:56shep-homethanks!
19:01shep-homeTwo questions about that last bit of code, amalloy
19:02ipostelnikis there a quick way to clear names loaded into slime repl?
19:02ipostelnikso if I rename a function the old name disappears from the repl
19:02shep-home1: is using reduce where the types of the two parameters differ normal/idiomatic
19:02technomancyshep-home: very common
19:03shep-home2: is packing two values into a vector like that normal/idiomatic?
19:03shep-hometechnomancy: thanks, I guess I'm a bit limited in thinking of it as the same
19:03amalloyyes, when you need to keep track of multiple things, working with a tuple is the easiest way
19:04amalloyipostelnik: see ns-unmap
19:04shep-homeI suppose that the small scope of the tuple makes it better
19:05shep-homeif it were to be more exposed, would a map be better?
19:05shep-homeand/or more idiomatic?
19:05shep-homenon-homogeneous collections worry me :-)
19:06technomancyit's probably a bit better to assoc it into a map as you go, though it's easy enough to pour a seq of k/v pairs into an empty map when you need it.
19:07brehautshep-home: http://hackage.haskell.org/package/HList
19:08brehautshep-home: theres no reason heterogenous collections need to be unsafe ;)
19:15ipostelnikamalloy, that let's me unmap one thing at a time
19:19amalloyyou didn't ask for anything more specific
19:20ipostelnikwell, is there anything more convenient than ns-unmap?
19:21ipostelnikcan I unmap a whole namespace at once?
19:21grim_radicalin anger, I've used remove-ns
19:21brehautipostelnik: even if theres not, you can write your own
19:22brehauteg (map (comp (partial ns-unmap *ns*) first) (ns-publics *ns*))
19:24amalloybrehaut: he probably wouldn't want to write his own, since he'd keep deleting it
19:25brehautamalloy: it doesnt have to live in the same namespace :P
19:26amalloyaha, but who ever goes on a rampage deleting *just one* namespace? once you get started it's just so exhilarating you wind up with a totally empty jvm
19:27brehautthis must be an emacs users affliction :P
19:29mjg123technomancy, unzip classpath->dir working now, thanks
19:44mabeshow do you kill the swank process that 'clojure-jack-in' creates? killing the slime REPL didn't seem to do it...
19:54technomancymabes: *swank* buffer
19:55mabestechnomancy: ah, right.. thanks! I probably would have figured that out if I didn't have a million buffers open :)
19:59carktechnomancy : did anyone bother you already with swank + clojure 1.3 under windows showing "^M" behind any output in emacs ?
20:00technomancycark: I don't think so.
20:00carkwell you know that clojure changed the way it outputs newline characters in 1.3
20:00carki was able to quickfix this by changing the value of system-newline in my user.clj
20:01carkbut the real problem is in swank i guess
20:01carkthat would not be a problem at all, having ^M behind each output in the repl
20:01carkbut it messes also with the auto-complete-mode
20:02carkmaking it unable to show quick help
20:02carkanyways just to let you know, i personally am good with it
20:05technomancyok, well let me know if you have a patch
20:05carki will not dive into swank =)
21:47shep-hometechnomancy: trying to run tests from clojure-test-mode, I just started getting "error in process filter: if: Wrong number of arguments: nil, 11"
21:47shep-homewhat have I done wrong?
23:04ZolrathI'm trying to download files using clojure.java.io but it seems to crap out and leave the end of most images incomplete.
23:04technomancyshep-home: where'd you get it?
23:04Zolrath(io/copy (io/input-stream url) (io/output-stream desination)) seems like it shouuld work and it almost does.
23:07ZolrathSeems that it works fine on some domains but other domains every single image will have the bottom half blacked out
23:07amalloyZolrath: fwiw, i had to do that myself like half an hour ago, and that worked
23:07amalloythough actually i created the output stream myself using java interop, because i don't use c.j.io very much and forgot
23:14Zolrathamalloy: Hm that makes me even more confused then.
23:15amalloyZolrath: https://github.com/flatland/classlojure/blob/d63c49/test/classlojure_test.clj#L5 is my relevant snippet
23:25Zolrathamalloy: Thanks. Oddly enough that method is getting the missing part of the image that the seeming similar method I used fails to get
23:29sridcan clojure.java.io be used to convert a string into an input stream? reading the docs tell me not. or must I continue using: (-> "foo" (.getBytes) (ByteArrayInputStream.)) ?
23:32Zolrathamalloy: it would appear the output-stream in clojure.java.io is to blame, or at least my usage of it. With your direct call to java.io.FileOutputSream it works perfectly but if I use the io/output-stream I lose the tail end of the images.
23:35amalloysrid: no. in general you shouldn't be trying to treat a string as a sequence of bytes, because it's a sequence of characters
23:35amalloyand depending on the active character encoding, a given sequence of bytes could be interpreted in zillions of different ways