#clojure logs

2011-03-15

00:10sproustHelo Clojurians, haven't been here in a while. I have a quick question:
00:10sproust,(let [a (range 1 12)] (format "%s" (str a)))
00:10clojurebot"clojure.lang.LazySeq@f49de165"
00:11sproust,(let [a (range 1 12)] (format "Values: %s" (str a)))
00:11clojurebot"Values: clojure.lang.LazySeq@f49de165"
00:11sproustWhat's the idiomatic workaround for this?
00:12sproust(I'd like to see the %s expand into a list of values.)
00:14brehaut&(let [a (range 1 12)] (format "%s" (apply str (interleave " " a)))
00:14sexpbot⟹ 1 ; Adjusted to (let [a (range 1 12)] (format "%s" (apply str (interleave " " a))))
00:14brehautthats differently wrong
00:15brehaut&(let [a (range 1 12)] (format "%s" (apply str (interpose " " a))))
00:15sexpbot⟹ "1 2 3 4 5 6 7 8 9 10 11"
00:16sproustThx brehaut; I understand I can manually concatenate; just wondering if there's any way to automatically get a good default representation without having to do it manually (as in Python).
00:17brehautsproust: i dont think so.
00:17sproustThx.
00:17brehautsproust: best i could think of for 'automatic' would be ##(let [a (range 1 12)] (format "%s" (apply list a)))
00:17sexpbot⟹ "(1 2 3 4 5 6 7 8 9 10 11)"
00:19sproustAh... I see. (format) will do the right thing if this isn't a seq. I'd love a version of (format) which does this automatically, for quickly printing stuff for debugging (where I don't care for precise output).
00:21brehautsproust: pr and prn
00:21brehaut&(prn (range 1 12))
00:21sexpbot⟹ (1 2 3 4 5 6 7 8 9 10 11) nil
00:22sproustRight, but goes to stdout, we need (fr) I guess :-)
00:23brehaut&(with-out-str (prn (range 1 12))
00:23sexpbot⟹ (1 2 3 4 5 6 7 8 9 10 11) ; Adjusted to (with-out-str (prn (range 1 12)))
00:23sproust,(defn fr [x] (with-out-str (pr x)))
00:23clojurebotDENIED
00:23sproust(defn fr [x] (with-out-str (pr x)))
00:23brehautyou cant def with the bots
00:23sproustHa! You beat me to it.
00:23sproustThx.
00:24brehaut(def fr (comp with-out-str pr))
00:25sproustThat won't work; with-out-str is a macro.
00:25brehautsproust: may is suggest https://gist.github.com/c93c37345c49c47dcfa2 as something to look at too
00:26brehautstink
00:28sproustNice.
00:28sproustbrehaut: I think we've been redefining (pr-str).
00:29brehautha
00:30sproustThat's what happens to my rotting brain when I go do some C for two months and then I come back. I forget.
00:32brehautyeah dont do that :P
00:32waxrose:D
00:48phenom_oh jeebus ... i've got some clojure code that's beginning to look very imperitive with lots of mutable state :(
00:48phenom_i need a mentor or something
00:48phenom_bah
00:49brehautdont we all
00:49waxroseme too
00:49waxrosebrehaut, You should be my mentor! :P
00:49brehauthaha i dont think should be anyones mentor
00:49waxroselol why not?
00:50brehautdo you really want to be mentored in regexp abuse, unnecessary point free and misunderstanding monads?
00:50waxroseEhh, depends on how much alcohol is involved.
00:51phenom_anyone know how much clojure/core is charging :P
00:51waxroselol
00:52tomoj"unnecessary" :D
00:52brehaut:D
00:52waxroseI've been configuring files more than I have been reading. So you're not the only one in need of a mentor.
00:54phenom_yea ... ive got about 500 loc ... i need a checkpoint review
00:54phenom_ill post it on github and request on the list or here
00:54waxrosewhat's your github?
00:54phenom_it's not up yet :P
00:55waxroseoh okay haha
00:55waxroseDarn, now I can't stalk your commits.
00:55phenom_if you're interesed in helping out, that's always welcome
00:56waxroseMaybe :)
01:00phenom_well then I'll let you know when it's up
01:03waxroseCool. :P
01:17sproustIs there a way to terminate all the threads I started in my VM/REPL?
01:20tufflax,(. String getName)
01:20clojurebotjava.lang.NoSuchFieldException: getName
01:20tufflax,(. (identity String) getName)
01:20clojurebot"java.lang.String"
01:20tufflaxI don't get it. :P
01:27tomojdon't use . anyway
01:27tufflaxOk may I do get it now.
01:27tufflaxtomoj I'm just trying to understand what's going on.
01:28tufflaxs/may/maybe
01:28tomojsure
01:28tomojhave you read http://clojure.org/java_interop ?
01:28tufflaxI'm reading now
01:29tufflaxMaybe I should have read further before I started asking, but it just looked so strange to me. :P
01:30tomojstrange indeed
01:31tomoj. deserves its 'special' title
01:31tufflaxhehe yeah
05:00angermananyone mind lending me a hand with library packing?
05:01angermanCurrently I build the jReality package with https://github.com/angerman/planarity/blob/master/mkjr/Makefile
05:02angermanit's actually getting pretty large and packages up all the native libs for all architectures in one package. Can that be broken apart?
05:04angermanIt also gives this: [WARNING] POM for 'org.clojars.angerman:jreality-native-deps:pom:2011-01-29:compile' is invalid. It will be ignored for artifact resolution. Reason: Not a v4.0.0 POM
05:35xkbhi all
05:37xkbA colleague and I are thinking about organizing the first european Clojure conference. We are trying to find a way to see how many ppl would be interested. Any hints/tips?
05:42mduerksenxkb: i'm not sure, but what about hackernews?
05:42xkbmduerksen: hmm good idea, just to see whose interested
05:43xkbthere's no such thing as a clojure developers directory right?
05:43xkblike haskell has
05:43ejacksonxkb: I'd to LauJensen or cgrand, as they've been doing Clojure training and will have the pulse of european clojure
05:43ejacksons/to/talk to/
05:44xkbfor now it's more of a wild idea, but it might be good to include as many ppl as possible, early on
05:44xkbwe spoke at dyncon2011 in sweden this weekend, and there was quite alot of interest in clojure
05:44xkbso that's where the idea was born
06:05pyrhi
06:05pyrfor a given agen i have the guarantee that no two functions will be executed in parallel, right ?
06:05pyrs,agen,agent
06:06xkbpyr: an agent will queue functions send to it, as far as I know
06:06pyrok
06:06xkbwhy do you ask?
06:07pyri have an agent that i use to serialize access to redis
06:07xkbah ok
06:07xkbSo it's an agent without state?
06:07pyrpretty much
06:08pyri use this because Jedis the java redis library i'm using isn't thread-safe
06:08pyrbut i still end-up with boggled data in redis
06:08xkbso did you use send or send-off and to one agent or multiple? :)
06:09xkbsend-off is for potentially blocking functions
06:09pyrwhich is why i use it
06:09xkbnot that it would matter, as the redis lib wont block
06:10xkbyou could still get into trouble with multiple agents and send-off doing the same work
06:10pyrthere's only one agent
06:10xkbok..
06:10pyri'll try using send instead
06:12pyrwell send just barfs on me
06:13xkbodd.. any error?
06:13pyrearlier on, which'll help me find what happens
06:13xkbis the agent in an error state?
06:13pyryep, and i wired up a backtrace to failed agents
06:13pyrso i'll have smth to look into
06:14xkbok :) Good luck
06:51pyrxkb: heh, thx
07:16fliebeldammit, I never see to be able to get the brackets right in the require/use syntax. How obvious… (:require [clojure [set :as s]])
07:18clgvfliebel: I know that problem. when using the square brackets I always forget one of them or a bracket ;)
07:19ejacksonfliebel: you and me both, I can never seem to remember which way it goes around
07:23angermanwhat's wrong with https://gist.github.com/870608
07:25angermanI always get Can't embed object in code, maybe print-dup not defined: clojure.lang.Atom@f2f8f5f
07:30clgv angerman: skip the unquote before atom and it works
07:30ejacksonclgv: beat me to the punch :)
07:30clgv:P
07:31angermanhmm… thanks clgv. (& ejackson) … trying to wrap my head around that.
07:33ejacksonangerman: I'm no macrologist, but in your version I think it evals the (atom 0) call and splices that into the code using print-dup (hence the misleading error), whereas you really don't want anything evaluated at macroexpansion time.
07:34ejacksonmacroexpand-1 of the original:
07:34ejackson(clojure.core/binding [user/*node-counter* #<Atom@4d0948bd: 0>] (clojure.core/deref *node-counter*))
07:34angermanejackson: that's what I'm "guessing" as well… been using macroexpand a little…
07:34fliebelHm, is there any elegant way of getting to the squares of a sudoku puzzle? So for a seq of 81 items, that would be positions 1, 2, 3, 10 11 12, 19, 20 ,21, and then 4, 5, 6, 13… It gets a mess of take-nth-partition really quick.
07:34ejacksonand the unsplice free:
07:34ejackson(clojure.core/binding [user/*node-counter* (clojure.core/atom 0)] (clojure.core/deref *node-counter*))
07:35ejacksonfliebel: i'd use modulo and friends
07:36fliebelejackson: How? Which friends?
07:37clgvfliebel: write an adressing function addr [square-idx, field-idx] -> field
07:38ejacksonto turn an index in a 1D structure that represents a 2D structure you use side*x + y to go from 2D to 1D, and to reverse you get x = (round (mod (1D-index)) and y = 1D-index - x*side
07:38ejacksonoff the top of my head, could have error, but you get the idea.
07:39ejacksonshouldn't be much of a leap from that to [square-idx] -> 1D-indices
07:40angermanOk, I've another question https://gist.github.com/870623
07:40angermanwhy does (:render (Node. 0 0 0)) return nil?
07:40fliebelejackson, clgv: Thanks, but that sounds just as complex if not more complex than what I have now.
07:40opqdonutangerman: why :render and not render
07:41opqdonut(:render (Node. 0 0 0)) tries to access the field named :render in (Node. 0 0 0)
07:41clgvfliebel: you could also organize the square in data structures in advance
07:42angermanopqdonut: ok, how do I get the render symbol?
07:42ejacksonangerman: I think your want (.render ...) ?
07:42clgvno. he wants (render (Node. 0 0 0)) - I'd say ;)
07:42opqdonutyes
07:43clgvit's clojure so you don't need that dot afaik
07:43angerman… if only (render (Node. 0 0 0)) would work .. :(
07:43ejacksonaah, yes.
07:43angermanit complains about not knowing about render. and .render doesn't work either.
07:43clgvit works here
07:43clgvbut you have an error in it: java.util.IllegalFormatConversionException: f != java.lang.Integer (repl-1:13)
07:44clgvit's the floating number template "%f" you have ints here
07:44angermanclgv: yes.. that 0 0 0 was just a sample…
07:45angermanshould have been 0 0.0 0.0
07:45angermanstill need to figure out why it doesn't work for me...
07:45clgvangerman: I copy and pasted your gist and simply called: (render (Node. 0 0 0))
07:45angermanweird.
07:45clgvmaybe you should make sure you recompile everything
07:46angermanif i juts copy it into the repl it work. if I try to call it from it's namescape it doesn.t
07:46clgvoh that might be a problem indeed. I had some weird behavior with namespaces and protocols as well.
07:47clgvangerman: you are about to write a Clojure Layer for TikZ?
07:47angermanyes. A second one ...
07:48angermanthe first one was to rigid.
07:52clgvsounds interesting. I did some "programming" in TikZ which was really hard to do, since there isnt much more than that foreach-statement and latex definitions ;)
07:53angermanthat's right. but you can get quite far with that already.
07:53clgvyeah. and I did, but it took some time ^^
07:53angermanCurrently I need 3d stuff though. and tikz doesn't do 3d well.
07:59clgvI think I consider a Clojure TikZ DSL next time, I want to do some complex animation ;)
08:15fliebel$findfn {:a 1 :b 2 :c 3} [:a :c] 1 3
08:15fliebel$findfn {:a 1 :b 2 :c 3} [:a :c] [1 3]
08:16fliebel&(println "Sorry, I was sleeping")
08:16clgvhe seems to be on vacation again
08:17fliebelping amalloy_, Raynes
08:17fliebelHm, then I'll never know the name of that function...
08:17clgvdoes findfn search for a function that fulfills your testcase?
08:18fliebelyea
08:18clgvcool^^
08:18fliebelif I tell it 1 1 2 it will list all the functions that return 2 given 1 1 as argument
08:20fliebelIt's select-keys I was lookign for
08:31clgvis there a better way for parallel computation than pmap, if I do not want the sequence to be lazy?
08:31clgvand do not need the sequence to be lazy
08:48fliebelclgv: I think pcalls and pvalues uses pmap under the convers as well, so a thread pool or a future could work.
08:48clgvfliebel: threadpool was what came to my mind as well
08:50chouserclgv: there's been some work to integrate the forkjoin lib which I think would get you what you want. Not sure about the state or availability of that work though.
08:50clgvyeah that sounds like what I might need. but with current java it was not working a while ago
08:52fliebelchouser: Oh! I really want parallel reduce :)
08:53chouserIn my work, I rarely have use for it, but the integration of forkjoin and clojure vectors sounds really clean and powerful.
08:55mecIs there a way to do def- like defn- ?
08:57sattvikmec: (def ^{:private true} myvar …), there's also a contrib lib
08:58cemerickmec: or if you're on 1.3, (def ^:private varname …) is all you need.
08:58sattvikdefvar- from clojure.contrib.def
08:59mecIs this not normal since it isnt in core?
09:00cemerickThere are just too many desirable variations of var metadata for there to be macros for all of them.
09:00sattvikI think its common enough. There has been some debate as to why defn- is in core but def- is not.
09:00cemerickdefn- is probably considered a mistake in retrospect.
09:00meccemerick: why's that?
09:01cemerickmec: especially given the easy metadata syntax in 1.3, there's not a lot of value in it.
09:01mecah
09:02clgvhow can I type hint function parameters to be double? ^double does not work
09:02clgvis ^Double right?
09:05sattvikclgv: I think so. At least in 1.2.
09:05clgvyeah 1.2 it it
09:05clgv*is
09:12fliebelIs there something like index-of in Clojure?
09:13chouser(doc map-indexed)
09:13clojurebot"([f coll]); Returns a lazy sequence consisting of the result of applying f to 0 and the first item of coll, followed by applying f to 1 and the second item in coll, etc, until coll is exhausted. Thus function f should accept 2 arguments, index and item."
09:14fliebelchouser: Yea, I'm using that now.
09:30tufflaxHm how do I specify an encoding to slurp? The doc doesn't say.
09:34mids(slurp f :encoding enc)
09:46tufflaxthank you
09:55tufflaxI'm trying to read a file that contains the letters åäö, but it just comes out as "???". Anyone got any idea of what I should be doing? I'm saving the file with encoding UTF-8 and giving :encoding "UTF-8" to slurp.
09:55cemericktufflax: your terminal / REPL is probably not using a suitable encoding itself.
09:56tufflaxIf I just type "åäö" in the repl it comes out as "<e4><f6>" etc, not "???"
09:57cemerickwhat does (System/getProperty "file.encoding") return for you?
09:59tufflax"Cp1252"
10:00cemerickAnd your terminal's encoding is?
10:01TimMctufflax: First step is to check the actual bytes on disk.
10:01tufflaxcemerick hm I dunno, I'm in vim...
10:02tufflaxnot run through a terminal
10:03TimMcOpen the file in vim, what bytes do you see?
10:03Chousukeit might help to set java's encoding to utf-8 using the -D switch to the JVM
10:03Chousukeit uses weird archaic encodings by default :(
10:03chouserthere are a dozen places where encoding can go wrong. It's best to do something approaching a binary search if at all possible.
10:04tufflaxTimMc i see åäö if that's what you mean
10:06TimMcCan you switch to a hexedit view?
10:07TimMcvim might be guessing encoding
10:07tufflax-D did the trick
10:07tufflaxthank you
10:18raektufflax: and easy way to verify that everything works is to eval something like (seq "köttfärssås") and check that the number of characters returned is right.
10:18tufflaxok :)
10:20raek(it also helps when determining if the problem is in the decoding of the input or in the encoding of the output)
10:21raektufflax: are you from sweden too?
10:21tufflaxyes
10:30raektufflax: in case you live in the Linköping area, you might be interested in that Linköping Clojure User Group will have a meeting next wednesday
10:31tufflaxI don't live there :P
10:31tufflaxI live in Stockholm
11:06angermanwow. the geometry -> TikZ render works.
11:06angermanfinally. After getting the transformation wrong multiple times :D
11:11TimMcangerman: Coordinate transforms?
11:12angermanTimMc: yes.
11:12TimMcTricky little buggers, they are.
11:13angermanAt first I got it almost right. It just felt completely inverted...
11:14angermanrunning circles, until i figured out that the z coordinate was negative and caused the inversion. Being negative was anticipated, just didn't make sure that x and y got divided by -z instead of z...
11:40angermanI'm always happy to find new strange errors :/
11:41angerman,(clojure.contrib.string/join "/" ["foo" "bar"])
11:41clojurebot"foo/bar"
11:41angermanand what I get is: "wrong number of args (3) passed to string$join"...
11:45jeffthinkam looking at the api docs, but can someone explain the difference between "->" and "-->" functions, and is the difference between those and ".." that the latter operates specifically on java objects?
11:45angerman,(doc —>)
11:46clojurebotI don't understand.
11:46angerman,(doc -->)
11:46clojurebotExcuse me?
11:46angermanjeffthink: what is -->?
11:46angermandid you mean ->>?
11:46jeffthinksorry, typo...yes
11:47angermanwell. -> puts the the form in position one while ->> puts it last.
11:47angerman(->> some-list (map some-fn))
11:47angermanthat's where you want ->> for example.
11:47angerman(-> some-value (cons some-list))
11:47angermanthat's where you might want to use ->
11:48jeffthinkah..yea, that makes some....thanks...and is ".." specifically for java op?
11:49angermanI would say so… but what does that mean :D
11:49jeffthinkhaha...good question :)
11:51jeffthinkso, I've been using the ".." syntax to chain together a set of java functions on a java instance (.. instance method1 method2)...would that also be possible with "->"
11:52angerman(-> instance (.method1) (.method2)) ?
11:52angermanI guess.
11:53jeffthinkyea, ok...so not as nice looking, but doable...not going to use that in this case, but am just trying to wrap my ahead around the different macros and how they relate
12:01TimMcjeffthink: macroexpand-1 might help
12:01nickik,(macroexpand-1 '(-> 5 (cons '(6 7 8 9)))
12:01clojurebotEOF while reading
12:01angermananyone has a magic mouse that's losing bluetooth most of the time?
12:01nickik,(macroexpand-1 '(-> 5 (cons '(6 7 8 9))))
12:01clojurebot(cons 5 (quote (6 7 8 9)))
12:01angermanIt's been going on/off the whole day… very confusing.
12:01nickikmmh
12:02nickik,(macroexpand-1 (-> 5 (cons '(6 7 8 9))))
12:02clojurebot(5 6 7 8 9)
12:02jeffthinkTimMc - thanks, didn't know about that
12:02nickik,(macroexpand (-> 5 (cons '(6 7 8 9))))
12:02clojurebot(5 6 7 8 9)
12:03nickikcant i expand this to (cons 5 ' (6 7 8 9))
12:03TimMcnickik: jeffthink: Use syntax-quote: ##(macroexpand `(->> foo (bar qux) baz))
12:03nickikah sorry i already did with quoting it
12:04angerman,(macroexpand-1 '(-> 5 (cons '(6 7 8 9))))
12:04clojurebot(cons 5 (quote (6 7 8 9)))
12:04angermanah yea.
12:04TimMcHmm, why didn't ##(+ 3 4) that work...
12:05TimMcOh, sexpbot is missing.
12:05TimMc,(macroexpand `(->> foo (bar qux) baz))
12:05clojurebot(sandbox/baz (clojure.core/->> sandbox/foo (sandbox/bar sandbox/qux)))
12:07TimMcnickik: The argument to macroexpand has to be syntax.
12:07TimMc,(macroexpand (+ 3 4)) ; the args are eval'd
12:07clojurebot7
12:10TimMcHuh... I thought macroexpand would get the inner ->> as well.
12:14chouseris there a function that resolves all class names the way type hints are resolved?
12:15chouserfor example: 'Integer -> java.lang.Integer, and 'bytes -> [B
12:16hiredmanthe bytes thing and similar are special cased
12:17hiredmaneverthing else is just resolve I think
12:17chouserthey haven't been pulled out into a commond function yet?
12:17hiredman,(resolve 'Integer)
12:17clojurebotjava.lang.Integer
12:17chouserYeah, I'm using resolve now, but I would like to support bytes, etc.
12:18TimMc,(class (int-array 2))
12:18clojurebot[I
12:18hiredmanhttps://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L981
12:18TimMcAh, but you want 'ints -> "[I"
12:18chouserhiredman: ugh. thanks.
12:19TallAdamhas anyone had a their main thread of execution just die (no exception)?? I use pmap to go http-fetch some pages and about half way through (the 6000 pages), it just stops. no exception. nothing???
12:19chouserTallAdam: how do you know it's dead?
12:20TallAdamchouser: its not dead (the repl still works), but it only makes it a random percentage through the job
12:20mecIs there a better way to express (fn [arg f] (f arg))
12:20TallAdamthen it just stops
12:22TallAdamI don't think its the heap getting too big either
12:30amalloyTallAdam: have you considered that your threads may be choking due to server failures???
12:30TallAdamI have the http fetch wrapped in a try - would it miss anything?
12:30amalloymec: my little utility library has an invoke function (fn [f arg] (f arg)) and a reorder function, so i would define that function as (reorder invoke)
12:36amalloyuser=> ((reorder invoke) 1 inc) ;; results in 2
12:41amalloyfliebel: hm, i see. i'll go kick him
12:43amalloyfliebel: that said, i don't think your findfn was going to return anything
12:44amalloyjuxt would have required ((apply juxt [:a :b]) m) which he certainly wouldn't find, and select-keys would return a map, not a vector
12:45TimMcamalloy: reorder assumes a binary fun by default?
12:45amalloyTimMc: it reverses the args by default
12:45TimMcah
12:45amalloyatm invoke is in amalloy/utils, and reorder is in hot-potato/hot-potato (maven artifacts). that's kinda silly so i'm going to merge them shortly
13:03mecwell apparently -> works as (reorder invoke) too bad you cant pass it like a function
13:05amalloymec: like (-> 1 inc)? sure, but as you note it's a macro
13:06amalloyand wouldn't work anyway for functions that aren't literal symbols: (-> 1 (fn [x] (inc x))) is a compile error
13:06mecgotta love findfn
13:07mectrue enough
13:10amalloymec: you can get my reorder and invoke if you want them, by depending on [amalloy/utils "0.3.1"]
13:11TimMc,(-> 1 ((fn [x] (inc x)))) ;-P
13:11clojurebot2
13:12amalloyfliebel: clojure collections all implement Collection, which specifies .indexOf
13:14amalloynickik: sexpbot tolerates mismatched parens like those clojurebot barfed on a while ago: ##(macroexpand-1 '(-> 5 (cons '(6 7 8 9)))
13:15amalloyoh, but probably not for inline
13:15amalloy&(macroexpand-1 '(-> 5 (cons '(6 7 8 9)))
13:15sexpbot⟹ (cons 5 (quote (6 7 8 9))) ; Adjusted to (macroexpand-1 (quote (-> 5 (cons (quote (6 7 8 9))))))
13:17TimMcamalloy: Can you just have it say "closed some parens"? It's shorter and easier to understand, especially since some forms are rewritten.
13:18TimMc&'(no quote here
13:18sexpbotjava.lang.Exception: EOF while reading
13:18amalloyTimMc: i could certainly do that. i thought it might be helpful to have a pastable correct version
13:19TimMchmm
13:19amalloy$mail brehaut why doesn't it work on &'(no quote here
13:19sexpbotMessage saved.
13:20TimMc&(+ 3 4
13:20sexpbot⟹ 7 ; Adjusted to (+ 3 4)
13:20TimMc&(+ '(3 4
13:20sexpbotjava.lang.ClassCastException: Cannot cast clojure.lang.PersistentList to java.lang.Number
13:21TimMcbah
13:21TimMc&(list '(3 4
13:21sexpbot⟹ ((3 4)) ; Adjusted to (list (quote (3 4)))
13:21TimMcWell, nothing obvious.
13:22amalloyTimMc: i bet it just doesn't work if there are meaningful characters before the parens
13:22amalloythe *first* parens
13:24amalloyyeah, i think that's it. i'm not exactly a superhero at reading fnparse nonsense, but it looks like we assume the list will start with an open-paren of some kind
13:30TimMc&(+ 2 3))
13:30sexpbot⟹ 5
13:34amalloyTimMc: that's always worked
13:34amalloy,(+ 2 3))
13:34clojurebot5
13:35TimMc,(+ 2 3) So I guess I can have whatever out here?
13:35clojurebot5
13:35amalloyindeed
13:35amalloy(read) stops as soon as it gets to the end of a sexp
13:35TimMc&(+ 2 3) ##(+ 5 6) maybe...
13:35sexpbot⟹ 11
13:40raek,"clojurebot" ##"sexpbot"
13:40clojurebot"clojurebot"
13:40TimMc,"clojurebot" ##(identity "sexpbot")
13:40sexpbot⟹ "sexpbot"
13:40clojurebot"clojurebot"
13:44TimMcIt's a bot race!
13:45amalloydid sexpbot actually win, or does it just look that way to me because we're sharing a server?
13:45__name__It won.
13:46jcromartiehave you guys seen http://threecrickets.com/prudence/ ?
13:49TimMcI suspect you could map out the IRC topology by sending very long messages between users on different servers and checking how much is lopped off.
13:51choffsteinHey all. I have a quick question -- if I have written a bunch of clojure libraries for personal use, how can I set up a local repo directory to point leiningen towards? Is there a repo format I should follow
13:51TimMcchoffstein: Look into lein install
13:52choffsteinwill do. thanks.
14:09TimMcWhat is the difference between = and ==? Does the latter just enforce numbers?
14:09amalloyTimMc: i guess i'm too late for choffstein, but why not put them on actual clojars? unless they're IP of some kind, this makes it easy to get up and running if you're working from a different machine
14:10amalloyTimMc: yeah, i think so
14:12jcromartie,(doc ==)
14:12clojurebot"([x] [x y] [x y & more]); Returns non-nil if nums all have the same value, otherwise false"
14:20__name__&(== 2 2 2)
14:20sexpbot⟹ true
14:20__name__&(= 2 2 2)
14:20sexpbot⟹ true
14:20nickikit ignors types
14:21nickikso you can do int == float
14:21__name__&(= 2.0 2)
14:21sexpbot⟹ true
14:21__name__&(== 2.0 2)
14:21sexpbot⟹ true
14:21__name__huh?
14:21nickikmmhh
14:21nickik&("test" == "test")
14:21sexpbotjava.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn
14:22nickikoh
14:22nickikhehe
14:22nickik&(== "test" "test")
14:22sexpbotjava.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number
14:22amalloynickik: go put on the Java hat and sit in the corner
14:22nickiki am feeling dirty atm
14:23nickikI was just was doing java
14:23nickik*were
14:23__name__amalloy: What's the use case for ==?
14:23amalloy__name__: it's faster for numbers, i expect
14:24amalloy&(time (dotimes [_ 1e6] (let [[x y] (repeatedly rand)] (== x y))))
14:24sexpbot⟹ "Elapsed time: 1401.258589 msecs" nil
14:25amalloy&(time (dotimes [_ 1e6] (let [[x y] (repeatedly rand)] (= x y))))
14:25sexpbot⟹ "Elapsed time: 1763.939619 msecs" nil
14:25__name__Thank you amalloy.
14:25nickikIf i can do this in java Runtime.totalMemory() i should be able to do (Runtime/totalMemory) in clojure right?
14:26nickikor do i have to import runtime from somewhere
14:26amalloynickik: that's hoping that totalMemory is a field
14:27amalloy(. Runtime (totalMemory)) is the way to be explicit about it being a no-arg method, i think
14:27nickikamalloy, its a static method with no arguments
14:27nickik,(. Runtime (totalMemory))
14:27clojurebotjava.lang.IllegalArgumentException: No matching method: totalMemory
14:27tsdhHi
14:28__name__&(. Runtime totalMemory)
14:28sexpbotjava.lang.NoSuchFieldException: totalMemory
14:28tsdhIs there something like `doto' which returns the last expression's result?
14:28__name__&(Runtime/totalMemory)
14:28sexpbotjava.lang.NoSuchFieldException: totalMemory
14:28amalloytsdh: are you looking for ->?
14:28nickik&(Runtime.)
14:28sexpbotjava.lang.IllegalArgumentException: No matching ctor found for class java.lang.Runtime
14:28TimMcYou can't instantiate Runtime.
14:28TimMcYou have to get the current one.
14:28__name__Ah.
14:29__name__&(.. Runtime getRuntime totalMemory)
14:29sexpbot⟹ 17592320
14:29nickiksure you can, http://stackoverflow.com/questions/1885487/how-do-i-find-out-javas-heap-size-on-my-computer
14:29__name__Thanks MC Tim.
14:29nickikah
14:29amalloy(.totalMemory (. Runtime getRuntime))
14:29TimMcLike I said, you can't instantiate it.
14:30tsdhamalloy: Oh, thanks. :-)
14:30amalloynickik: have you actually *tried* that guy's suggestion in java? totalMemory is not a static
14:30amalloyso there's no reason his code should work
14:31amalloythe guy with fewer upvotes is more right
14:31nickikTimMc, right (not= instantiate get_back_an_object) mixed that up
14:32nickikamalloy, both work
14:32amalloyblurg, really? well they shouldn't :P
14:32tsdhamalloy: Ah, -> is not what I want. I don't want to chain the result through a pile of functions, but I want (doto java-obj (.foo) (.bar) (.baz)) and have the result of (.baz java-obj) returned.
14:33amalloy(-> java-obj (doto (.foo) (.bar)) (.baz))
14:33tsdhamalloy: Oh, indeed. That's pretty cool. :-)
14:33amalloydoto and -> are powerful magic
14:35tsdhYes, but it still returns java-obj. :-(
14:36tsdhArgh, sorry, paretheses match error when reading your example.
14:37amalloyindeed
14:38amalloy&(-> 1 (doto println) inc)
14:38sexpbotjava.lang.IllegalArgumentException: Bad binding form, expected vector
14:38amalloydang it
14:38amalloy,(-> 1 (doto println) inc)
14:38clojurebot1
14:38clojurebot2
14:38amalloyRaynes: please fix my clojail bug, it's making you look bad
14:39tsdhWow, now I can write java code in clojure in half of the lines I wousd need in "native" java.
14:41amalloytsdh: code that automates writing code will speed things up a lot
14:41amalloy(if it really takes you half as many lines there's a lot of room for improvement)
14:42amalloyfor example check out the other way you can combine -> and doto: (doto obj (-> .getSummaryList (.addSummary s)))
14:43tsdhamalloy: What's that s?
14:43amalloysome local variable
14:43amalloyi'm just demonstrating that you can modify nested mutable objects as well
14:44tsdhI see, although in that example the doto is not really needed, right?
14:44amalloytsdh: well, it makes you return obj instead of the result of .addSummary
14:44tsdh(-> obj (.getSummaryList (.addSummary s))) is equivalent
14:45tsdhOh, right.
14:45amalloybut yes, it's more interesting if you have other fields to set
14:45amalloy(doto obj (.setSize 10) (.setName "ffgdga") (-> .getFriends (.add steve)))
14:46tsdhNice
14:53tsdhI've heared there was some special syntax for defmultis that dispatch on the type of the first parameter: (fn [c & _] (class c))
14:53amalloytsdh: not exactly. there are protocols, which are similar to multimethods but (among other things) dispatch on class of first param
14:56tsdhOk, then I'll stick to the simple anonymous dispatch functions until I find some time to read about protocols.
14:59amalloyyou can just write (defn class-dispatch [c & _] (class c)) and make your multis dispatch on class-dispatch. no need to keep writing the same function
14:59tsdhRight.
15:00tsdhWhen recuring in a defmethod, will that recur to that exact defmethod or to defmethods with different dispatch value, too?
15:01amalloytsdh: even wrap it up in a macro: (defmacro ez-multi [name] `(defmulti ~name ~'(fn [c & _] (class c))))
15:01amalloyit will have to go to the same method. recur is just goto; it can't leap over function boundaries
15:04tsdhHm, ok. The usecase is that I want to unpack into native clojure sequences from a Java union type. There I have basic classes, for which I only need to call (.toObject), and collections, where I iterate the contents and call the (unpack) on the elements.
15:04tsdhSo this is a kind of mutual recursion.
15:04amalloytrampoline?
15:04clojurebottrampoline is http://groups.google.com/group/clojure/browse_thread/thread/6257cbc4454bcb85/3addf875319c5c10?#3addf875319c5c10
15:04amalloy~o/
15:04clojurebot\o ... High five!
15:05tsdhFound it in the docs.
15:06tsdhSo I simply say (def unpack (trampoline unpack-internal)), where unpack-internal is the multimethod?
15:07rata_hi
15:08amalloyi'm not sure trampoline will do you any good if you need to iterate over contents. you really need a whole stack
15:08amalloyjust (defmethod unpack j.u.Collection [c] (map unpack c))
15:09tsdhOh, right, that is much better.
15:11rata_does anybody know how can I make the get-activities fn faster? it takes ~70% of the time of my program https://gist.github.com/871248
15:15amalloyrata_: you could avoid some overhead by writing (into {} (for ...)) instead of (let [v (for...)] (zipmap ... v))
15:17amalloyi think it comes out to something like (into {} (for [{:keys [lhs rate] :as a}] [(inner for) a]))
15:23edwjs
15:23rata_oh thanks amalloy, it's even cleaner code now... I'll test how it performs as soon as I finish another fn I'm writing in the same file
15:23edwD'oh. Sorry.
15:25tsdhamalloy: Wow, I'm done for simple values, collections and now for maps: (apply hash-map (mapcat (fn [e] [(jvalue-unpack (.getKey e)) (jvalue-unpack (.getValue e))]) (.entrySet jv)))
15:26amalloytsdh: (into {} (map (fn [e] [(...) (...)]) jv))
15:27amalloyavoiding the messy apply hash-map
15:29tsdhYes, that's even better.
15:29amalloyinto {} is a fabulous idiom once you use it often enough to remember it
15:30tsdhOh, I have several intos in my code, not with empty literals, but anyway.
15:30pyramalloy: especially when working with java libs
15:31pyramalloy: love it
15:31amalloysee, intos with *non* empty literals is something that i always forget to think of :)
15:33tsdhWow, just verified that my multimethod works for JValueMaps from Object to JValueMaps to JValueTuples. And that in 23 lines of clear, self-explaining, functional code.
15:34amalloyof course!
15:35RaynesHeh, sounds like you're translating Real World Haskell to Clojure or something.
15:35amalloythat's just how clojure rolls
15:35rata_what's an empty literal?
15:35amalloyrata_: he means {} and [] and such
15:35amalloyliteral empty collections
15:35tsdhYep
15:36rata_oh ok
15:37rata_yes, I always forget to use into with non-empty collections... yesterday I found myself changing a (into {} (cons [:foo :bar] ....) to (into {:foo :bar} ...)
15:40raekI would like to take this opportunity to advocate using 'for': (into {} (map (fn [e] [(...) (...)]) es)) --> (into {} (for [e es] [(...) (...)]))
15:41RaynesThis has been a public service announcement brought to you by Svenson Enterprises.
15:41rata_hahahaha... I also find for better here
15:41rata_it's cleaner
15:42tsdhraek: Oh, that's even nicer. Can anyone come up with a one-char-er? ;-)
15:42choffsteinIs there a function similar to ruby's 'zip'? Basically, if I called [1,2,3].zip([4,5,6]) in Ruby, I would get [[1, 4], [2, 5], [3, 6]]. Zip in clojure seems to be for trees.
15:42amalloymap
15:43amalloy&(map vector [1 2 3] [4 5 6])
15:43sexpbot⟹ ([1 4] [2 5] [3 6])
15:43choffsteinPerfect. Thanks!
15:46amalloyclojure's map is more general, allowing it to take the place of several usually-disparate functions
15:47angermanIs someone willing to help me with optimizing a package for clojars? It is currently build using this Makefile: https://github.com/angerman/planarity/blob/master/mkjr/Makefile
15:47angermanBut it creates a rather huge pacakge, containing all native libraries for win32/win64/osx/linux32/linux64
15:55amalloysritchie: ping
16:00amalloysritchie: never mind. i was trying to duplicate nmarz's cascalog demo and hadn't realized i should be in the cascalog.playground namespace
16:01tomojseems funny how rarely the right namespaces are revelead in the docs
16:02tomojer, how often they aren't, maybe
16:13choffsteinis there a way to perform a map in clojure and pass in a variable as if it were a reduce? so basically I want to carry an accumulator through, but retain a list of the accumulators along the way
16:13amalloy&(doc reductions)
16:13sexpbot⟹ "([f coll] [f init coll]); Returns a lazy seq of the intermediate values of the reduction (as per reduce) of coll by f, starting with init."
16:13amalloysee also iterate
16:14choffsteinamalloy, you're like my personal clojure API :D
16:18Rayneschoffstein: I taught him everything he knows.
16:19amalloythis explains why i'm so good at claiming credit for stuff i didn't do
16:22tomojbravo
16:25chouserWhat kind of methods is this?? "tried to access method com.mongodb.CommandResult.()V"
16:25chouser s/methods/method/
16:25chouser.()V ?
16:25amalloyno args, returns void
16:25amalloymaybe?
16:26chouserno name?
16:26chouserno name, no args, returns void?
16:27amalloyi'd guess inner local, but then it should have a different classname
16:27raekas a descriptor (from the class file spec), "()V" does indeed mean no args, returns void
16:28raeklooks like the method name is missing between the class name and the type descriptor, or something
16:34bhenryany clojure developers currently residing in maine?
16:35choffsteinis there any way to globally alias a keyword to a macro? For example, can I map 'try' to a special macro?
16:35amalloyno
16:35choffsteinFigured.
16:36amalloyyou can't even do it locally without wrapping the whole thing in a macro. special forms can't be redefed
16:36amalloyand try is a special form
16:36choffsteinSo I wrote a macro that basically injects code into a try block, called 'my-try'. This works great for all my code, but if I import a library, they all use 'try'. Is there a way to hook into their code?
16:36amalloy(or maybe try* is)
16:38raekno. try is a (real) special form and is hard-coded into the clojure compiler
16:40choffsteinherm. bummer.
16:40choffsteinso if I wanted to execute an action anytime an exception was caught, anywhere, be it in my library or someone elses library ... I probably couldn't do that without hacking the clojure code itself, huh?
16:41mattmitchelli am trying to mock a function in another namespace using clojure.contrib.mock
16:41amalloyyuck. if you want to do that you're probably wrong. a lot of exceptions get thrown and caught that you just don't care about
16:42mattmitchellusing "expect", shouldn't this be as simple as (expect [blah/fun (times once)]) ?
16:42raeksounds like this is something that would be part of a debugger rather than a library...
16:44raekchoffstein: so, what is your use-case for this anyway? :)
16:44angermanhttp://dl.dropbox.com/u/281539/temp.pdf
16:44choffsteinraek: I am just playing around, learning clojure.
16:44angermanHmm I guess that has some "artistic" value
16:44angermanbut that's not really what I intended...
16:45raekchoffstein: well, you're deep into JVM/Java-land when you want to override behaviour of the exception mechanism... :)
16:45choffsteinraek: I was playing around with the exceptional library (getexceptional.com) for rails. I am thinking about tearing down my rails web-apps and replacing them with clojure ones, so I was seeing how easy it was to replicate the getexceptional functionality. I realized I could write a macro to wrap around try for my own code
16:46raekchoffstein: have you tried the good ol' top-level catch block approach?
16:47choffsteinraek: haha, yeah, I have. That works, of course. I just also wanted to catch all exceptions, whether caught or bubbled to the top.
16:47raekchoffstein: also, note that java code some times use exceptions for control flow
16:47choffsteinraek: yeah, I think I might get in trouble there.
16:47raekso caught exceptions might not be errors...
16:48raek(for instance, Integer/parseInt is often used when you want to try to interpret something as a number, but fall back to sometihng else)
16:48choffsteinYeah. Whatever. Good learning experience at the end of the day I suppose.
16:48amalloychoffstein: like i said, a lot of exceptions get thrown and then caught. i really doubt you want to see them
16:48choffsteinMaybe it is good that it is just for my own code and anything that bubbles to the top level
16:48raekchoffstein: sounds like the ideas of getexceptional.com could be turned into a great ring middleware
16:49mfexhi all, in emacs how do i "paste" an s-expr to the repl? Instead of running C-x e to eval, just paste to repl?
16:49raekthe wrap-stacktrace does the job, but does not exactly have a lot of features
16:51choffsteinraek: It would be nice if wrap-stacktrace allowed you to pass your own dispatch functions
16:53raekmfex: C-c C-p does something similar. (I have looked for the feature you described myself)
16:53tsdhHow do I refer to the class java.util.Map.Entry for the usage as a type hint?
16:54amalloymfex: you can C-M-<SPC> to mark a whole sexp, copy it, and paste manually :P
16:54raek(also, I like to use C-M-x for eval)
16:54choffsteinIf a library uses a defed *variable* for configuration, say a delimiter, how do I change that variable if I have the library as a jar?
16:54amalloytsdh: Map$Entry
16:54tsdhamalloy: Thanks.
16:54amalloywhich is the way to import it too
16:55mfexthanks all
16:58raekmfex: just found this: http://bc.tech.coop/blog/070424.html
16:58technomancychoffstein: vars like that are meant to be changed using binding.
16:58choffsteintechnomancy: I'm a moron -- can you explain that?
16:59chouseraw, shoot. I think it might be a bug in proxy.
16:59mfexraek: thanks, will have to dig through that, but looks to contain what I'm looking for
16:59technomancychoffstein: something like this: (binding [*warn-on-reflection* true] (my-code-goes-here))
17:00choffsteingotcha. awesome. thank you.
17:00technomancyyou don't actually change anything other than inside the context of binding
17:02raekmfex: just tried it myself. works great! (though, I had to change copy-region-as-kill-nomark into copy-region-as-kill-nomark as the note at the bottom of the page said)
17:10patrkrisis there an easy way to get a seq of pairs from a seq of an even number? i.e. ["a" 1 "b" 2 "c" 3] => [["a" 1] ["b" 2] ["c" 3]]
17:10patrkris*seq of an even number of elements
17:10opqdonut,(partition 2 ["a" 1 2 "b" :hello #{}])
17:10clojurebot(("a" 1) (2 "b") (:hello #{}))
17:11patrkrisoh yeah! thanks!
17:11raekalso, note ##(partition 2 [1 2 3])
17:11sexpbot⟹ ((1 2))
17:12raekand compare with ##(partition-all 2 [1 2 3])
17:12sexpbot⟹ ((1 2) (3))
17:12patrkrisyes - i guess it's fine since the number of elements is guaranteed to be even
17:12chouseroh, not really a bug. Just can't use proxy to create an instance of a class whose only ctor is non-public. Ugh.
17:13raekhrm. can you even do that in Java?
17:16rata_amalloy: it didn't help, get-activities still takes upto 80% of the time https://gist.github.com/871248
17:17rata_can typehinting help there?
17:18chouserraek: not from outside, I imagine. It's the JVM that's complaining
17:36BennylIs there a way to define an un parses string? Like @"/w" = "//w"
17:38amalloyBennyl: ##(java.util.regex.Pattern/quote "\\w") maybe?
17:38sexpbot⟹ "\\Q\\w\\E"
17:38amalloynot really sure what your actual goal is so it's hard to answer :P
17:38amalloyraek: you certainly can do that in java
17:39brehautBennyl: are you meaning like dotnet's verbatim strings?
17:39amalloypublic class Singleton {private Singleton() {} public static Singleton get(){return inst;}} // needs some code for actually creating the instance
17:40chouserright, but you have to be within scope
17:40raekI assumed you had to call a constructor of the superclass in any constructor, which might not be the case
17:41chousercom.mongodb.CommandResult is a concrete class with only a private ctor
17:41raeka/any/every/
17:41amalloyraek: you do have to. i think my definition makes Singleton de facto final
17:41chousernot private, sorry -- non-public, so I think the caller has to be in the package
17:41amalloyew
17:42amalloydefault/package visibility is so gross
17:42amalloyit is hard to imagine any good reasons for it
17:42amalloybut who am i to judge
17:42chouserand there are places that cast things to CommandResult
17:43chouserI have a reify instance that is ending up in some of those places
17:43chouserSo -- I'm stuck. I can't create a CommandResult or derive from it, but I must provide one.
17:43chouseramalloy: I'm willing to judge. :-)
17:43chouserTime to go home.
17:44Bennylbrehaut: yes exactly like verbatim string
17:44clojurebotCool story bro.
17:44brehautBennyl: then no, you cant
17:45Bennylbrehaut: well worth the try :)
17:46amalloychouser: (in-ns 'com.mongodb.blah) (proxy ...)?
17:47amalloythe fact that this is a viable solution is one of the reasons package is so dumb
17:47tomojviable?
17:47brehautBennyl: however (str #"\w")
17:47amalloyi guess it couldn't work if you proxied it
17:47brehautbah ##(str #"\w")
17:47sexpbot⟹ "\\w"
17:47tomojis it even a solution?
17:48amalloyyou'd have to gen-class
17:48tomojoh, to sneak it into the package?
17:48brehautBennyl: but thats horrible because its tunneling your string through the regexp implementation
17:48amalloytomoj: right
17:49sattvikchouser: It seems like there are two options: 1. Try a variation of amalloy's suggestion, or 2. use reflection to suppress access checks
17:50tomojsucks there are so many weirdnesses in java libraries that make trouble for clojure interop
17:50amalloytomoj: that's a weirdness that makes trouble for anyone
17:50sattvikThe second works so long as there is no security manager that disallows that from happening, which isn't true in all deployments.
17:52dnolenbrehaut: I tried out the monkey banana in miniKanren last night, pretty short, https://github.com/swannodette/bratko-logos/blob/master/src/bratko_logos/monkey_banana.clj
17:53brehautdnolen: cool :) i'll go have a read
17:53dnolenbrehaut: it'll be about as terse as Prolog when I wrap up the pattern matcher.
17:54brehautdnolen: i'll be interested to see the changes
17:54brehautdnolen: its still pretty clear nonetheless
17:54dnolenbrehaut: there's a preview at the bottom.
17:54brehautah so there is
17:57brehautdnolen: thats cool :)
18:00dnolenbrehaut: curious how quickly does your implementation solve the problem?
18:04brehautdnolen: 10000 runs takes 15000 msec (clj 1.2)
18:04brehautdnolen: logos should be much faster right?
18:05fliebelbrehaut: You have an miniKanren implementation?
18:05brehautfliebel: nope, monads
18:07fliebelUh, oh. So what is this about? I'm late to the party :( I see monkeys and logos, so it got to be great :)
18:07dnolenbrehaut: miniKanren version takes ~7s for 10k runs. clj 1.3, 2.66 i7 MBP
18:07brehautfliebel: https://github.com/brehaut/monkey-and-banana/tree/master/src/monkey_and_banana
18:08brehaut2.53 i5 MBP here
18:08brehautfliebel: im trying to learn more about logical programming but working towards it from a naive functional perspective
18:08fliebelah so you;re comparing monads to logos for a monkey problem? Lets see if wikipedia has a page that explains the problem...
18:09fliebelyup: http://en.wikipedia.org/wiki/Monkey_and_banana_problem
18:09dnolenfliebel: gotta run, but I'm porting bits of Bratko's Prolog Programming for AI to miniKanren, https://github.com/swannodette/bratko-logos
18:10fliebelsounds cool :)
18:11brehautfliebel: monkey and banana is a pretty simple problem so it's not resulted in a huge naive clojure solution which has helped me a lot :)
18:13fliebelbrehaut: Cool. I'm working on a regular and logos version of sudoku at the moment.
18:13brehautfliebel: cool :) have you read Bird's Functional Pearl on solving it via proof in haskell?
18:16brehautfliebel: http://www.cs.tufts.edu/~nr/comp150fp/archive/richard-bird/sudoku.pdf
18:17fliebelbrehaut: no, I do not read programming books much. I read TRS recently, now I have 5 other books, but the book before that was a Java book, that is before I did PHP, and that is before I did Python and that is before I did Clojure. ;)
18:18brehautfliebel: i dont get to read as many as i would like. that paper lost me once it got real clever, but its pretty amazing
18:19fliebelbrehaut: I did try to read a few prolog solutions, but they all use all_different, which uses negation, both are not yet present in logos.
18:20brehautfliebel: interesting. my prolog-fu is very weak; ive forgotten almost all i learnt at uni
18:30amalloysritchie: you might be interested in https://github.com/nathanmarz/cascading-thrift
18:31amalloywhich it looks like nmarz open-sourced just after i asked him if there was a thrift tap for cascalog
19:18Frssssay, what's the word on CLR clojure?
19:25fliebelFrsss: The word?
19:25Frsssis it being actively developed?
19:25Frsssdoes it use CLR specific advantages
19:25fliebelI believe so, it has 1.3 stuff at least.
19:25Frsssor is just just bare bones port
19:26fliebeldunno, I only know it does not run Mono :(
19:26FrsssI would imagine yield keyword being useful in language that has lazyness
19:27Frsssit also has "var" variable type
19:27Frssssomething java doesn't
19:27fliebelFrsss: Have a look at the github page, it will tell you the latest commit, and chances are the author is in here.
19:29FrsssI really wanna test the performace of Clojure vs Clojure CLR
19:30Frssslargest sticking point of clojure right now tbh
19:30technomancyis var like invokedynamic or more of a compile-time type inference?
19:30brehautFrsss: yield is implemented as a compiler transformation; its not a runtime feature
19:31brehauttechnomancy: compiletime inference
19:31brehauttechnomancy: dymanic is the invokedynamic equiv
19:32fliebelweee, my iterative sudoku solver is done: https://gist.github.com/871708 Now the logos version...
19:32technomancyso that wouldn't really affect Clojure then
19:32FrsssI hope for clojure to be one day performing at least half as fast as java
19:32RaynesClojure is insanely fast compared to how slow it could be.
19:33technomancylanguages aren't fast or slow; programs are.
19:33FrsssI didn't really use java until it got it's performance to factor 2 compared to C
19:33RaynesYou can do some performance optimizations and get near-Java performance.
19:33fliebelRaynes: Define 'could'. Is inserting Thread.sleep every other line 'could'?
19:34Frsssoptimize all you want, you aren;t getting near 2:1 with java
19:34Raynesfliebel: My point is that Rich Hickey and friends think performance is important. It's a goal.
19:35fliebelRaynes: I figured that, with all these nth/get performance guarantees.
19:35technomancyFrsss: sounds like you may have some catching up to do: http://meshy.org/2009/12/13/widefinder-2-with-clojure.html
19:35brehautFrsss: CLR Clojure has a greater impedance mismatch with the host platform (remedied somewhat by dynamic types in 4) than JVM clojure
19:35RaynesFrsss: No, seriously, people do it. Easily.
19:35Frsssbrehaut Interesting
19:35FrsssI would assume CLR was more suited
19:35Frsssbecause it has several features stolen from LISP :P
19:36brehautFrsss: nope; type errasure in JVM means that its a more friendly host for dynamic languages
19:36Frsssah k
19:36brehautCLR 4 still has relatively small deployment
19:36Frsssfunny.... I hate generics in java
19:36FrsssC# ones are better
19:37brehautFrsss: additionally the CLR VM and JIT is tuned quite differently to the JVM - out of the box CLR feels nicer for desktop applications: it starts relatively hot. JVM starts slow but as it heats up it becomes super fast, which suits long running services better
19:37brehautFrsss: it is very hard to make claims about the relative performance of each platform as a result
19:39brehautFrsss: and dont confuse features of C# with the CLR and Java with the JVM
19:40Frssstechnomancy: isn't that benchmark IO bound?
19:40brehautfliebel: that looks quite reasonable
19:40fliebelbrehaut: The sudoku? okay, good to hear.
19:40technomancyFrsss: depends on your implementation, disk speed, encoding, and many other factors.
19:40brehautfliebel: yeah, although im no guru!
19:41technomancyonce again: programs are fast or slow, not problems, languages, or VMs.
19:42Frsssstill I think that you wont get much difference from CPU usage when benchmark is IO bound. Clojure's problems are mainly with CPU and memory
19:42Frssstechnomancy if that were true, people would be making computer games in clojure instead of C++
19:43Frsssor any other expressive language
19:43brehautFrsss like GOAL ?
19:44FrsssGOAL?
19:44technomancyyeah, let's take a deep dive into the turing tarpit here...
19:44technomancywhat could go wrong?
19:44brehaut(inc technomancy)
19:44sexpbot⟹ 8
19:44brehautFrsss: http://en.wikipedia.org/wiki/Game_Oriented_Assembly_Lisp
19:45Frsssjust saying... C/C++ are used in giant majority of cases for games. having 30 FPS instead of 15 FPS with java implementation is a deal breaker.... that being said it doesn't matter for most apps, but to say that languages don't matter is silly
19:46brehautFrsss: go read about why sony stopped using GOAL, it wasnt performance; the crash team were producing some of the best performing games on the PS1.
19:47brehautFrsss: non-technical reasons dominate almost all technology choices
19:47rlb(and naughty dog used scheme, etc. -- though for the planner, not the renderer afaik)
19:55Frsssthis is weird: "Early on, when I was fighting a memory leak, Rich Hickey suggested using a smaller heap size. I did that, and was astounded."
19:56Frsss"But as I watched the program run, I could see that as the program built up its heap to the ceiling (set via java’s -Xmx argument), it was running much slower, as slow as a tenth of that speed."
19:56Frssswhy would having bigger heap make program run slower lol
19:58brehautguessing: more garbage to deal with when it hits the ceiling?
19:59Frsssthat;'s it...he says it gets faster when it hits ceiling
19:59Frsssthat's the counterintuitive part
19:59brehautwelcome to the science of garbage collection
20:12zoldaris there a more succinct way to write something like this: http://paste.lisp.org/display/120548 ?
20:13brehautzoldar: quick english summary?
20:14brehautzoldar: also does that ever return? (not v) is always false for any vector (empty or otherwse)
20:14zoldarsubstitute subsequent occurences of given value in one sequence with values from the other one
20:16brehautsorry im still now follow. examples of input and output?
20:16amalloybrehaut: that should terminate eventually
20:16amalloyv won't really be a vector, i think
20:16zoldar[1 3] , [nil 2 nil] -> [1 2 3]
20:17zoldarit works, rest from empty vector gives nil
20:17brehautamalloy: oh right. huh
20:17amalloybrehaut: ##(let [[x :as all] nil] [x all])
20:17sexpbot⟹ [nil nil]
20:17amalloyit essentially binds all to the actual value, then binds subelements to (vec value)
20:19amalloyi wonder if macroexpand shows that... ##(macroexpand '(let [[x :as all] nil] [x all]))
20:19sexpbot⟹ (let* [vec__10212 nil x (clojure.core/nth vec__10212 0 nil) all vec__10212] [x all])
20:20amalloysweet
20:26amalloyzoldar: i'd write it more as something like a lazy-seq of two seqs. (fn nil-fix [[a & morea :as as] [b & moreb :as bs]] (lazy-seq (if a (cons a (nil-fix morea bs)) (cons b (nil-fix as moreb)))))
20:27amalloynote untested, probably broken, but a rough draft
20:31zoldarthanks, this would be probably more elegant...
20:32waxroseWhich build tool do you all use, or is suggested? Leiningen? Cake? ..?
20:33brehautwaxrose: i use lein
20:33waxrosebrehaut, Any particular reason instead of the others?
20:33brehautwaxrose: i started using it before cake existed and i haven't needed anything else. also technomancy supports it ridiculously well
20:34waxroseOkay great, thanks.
20:36ieureI also use leiningen, because it is great.
20:36waxroseIt seems to be the most supported, I guess I'll stick to it. :P
20:40brehaut$findfn [1 2 1] [:a :b :c :d] ((:a) (:b :c) (:d))
20:40sexpbotjava.security.PrivilegedActionException: java.lang.IllegalArgumentException: Wrong number of args passed to keyword: :a (NO_SOURCE_FILE:0)
20:40brehaut$findfn [1 2 1] [:a :b :c :d] '((:a) (:b :c) (:d))
20:40sexpbot[]
20:42zoldar$findfn [1 2] 3 [1 2 3]
20:42sexpbot[clojure.core/conj clojure.core/merge]
20:42zoldarwow, nice feature
20:43sproustIs slime-interrupt supposed to work with a Clojure VM? It doesn't seem to have any effect in my setup.
20:43technomancysproust: not all operations can be interrupted
20:43sproustWhich ones can, and which ones cannot?
20:46technomancysproust: I/O is the main one I think: http://download.oracle.com/javase/1.4.2/docs/guide/misc/threadPrimitiveDeprecation.html
20:46technomancy(slime-interrupt is built on Thread.stop)
20:46brehaut$findfn 1 [:a :b :c] '((:a) (:b :c))
20:46sexpbot[clojure.core/split-at]
20:47sprousttechnomancy: Thx.
20:48technomancysure
20:58sprousttechnomancy: Why not just substitute it with (.interrupt thread)?
21:01sproustAhhh I think the same problem would occur.
21:01sproustNever mind.
21:02technomancyfirst rule of swank-clojure: don't assume anything is the way it is for a good reason =)
21:02mecIs set O(n)?
21:02technomancythere are places in the codebase that use refs where you think to yourself "that should be an atom!"
21:02technomancythen you look at the git log and realize "oh wait, atoms hadn't been implemented when this was written."
21:02technomancytrue story.
21:03sproustHaha, great... No I think in this case this is a problem without a solution. You can't forcibly kill a thread in a VM, because of the resources it holds. Sure Thread.stop() is deprecated, but Thread.interrupt() probably does similarly (InterruptedException instead of ThreadDeath).
21:03brehautmec: a datastructure generally doesnt have a big O for the whole thing; each operation will have its own. eg adding to the end is different adding random access or whatever
21:04mecI meant the function set, specifically applied to a sequence
21:04brehautoh right. at best its O(n), but i think it may be O(n log n)
21:05brehautas adding to a set is O(log n)
21:05brehautand it has to do that n times
21:05tomojthat's log32, though, right?
21:05brehauttomoj: oh good point
21:05brehautso O(n) then
21:06tomojeh..
21:06tomojseems like cheating even though it's practically true
21:06tomojhow big does the set have to get before it matters, I wonder?
21:07brehautthats an interesting question
21:07mecWell i've got the infinite primes sequence and im trying to turn it into a prime? predicate, but I'm not sure how to make sure it contains enough primes for the tested number without making a new set each time
21:08brehautmec: memoize or similar
21:08TimMcInfinite sets... has anybody made those in Clojure?
21:08tomoj(complement #{}) ?
21:08brehautmec, run (source memoize) in your repl and crib ;)
21:09brehauttomoj: haha
21:09tomojdoesn't behave like a set, though..
21:09TimMctomoj: :-P
21:11TimMcOK, trying to write a parser for assembly files written in a subset of MIPS -- best approach? It's a regular language.
21:11TimMcI'm comfortable with regexes, but I'm wondering if there's a better tokenizer or something.
21:13brehautTimMc: personally i'd lean toward fnparse with a simple tokenizer even if it is regular; it makes it very easy to build the AST on the fly
21:14brehautactually i probably wouldnt even use a regexp tokenizer
21:14TimMcAh, I've never looked into fnparse. I'll read your blog entry.
21:15brehautcool :)
21:15brehautits pretty simple
21:15brehautim just a bit verbose
21:16TimMcThat's good, I tend to skim. >_<
21:16brehautheh
21:16brehautthe headings and code snippets should be all you really need
21:20sproustDoes slime's compile support have any meaning for Clojure?
21:21ieuresproust, Sure, it’ll tell you if you have syntax errors.
21:21ieureI also use it to hack on code in the slime REPL.
21:22ieureC-c C-k will compile it and load it up into the repl, so you can (ns 'blah) and dick around with whatever code you’re editing.
21:23sproustThx! I guess the meaning is reduced to "load file."
21:44technomancysproust: there's no interpreter in Clojure, so C-c C-l is overloaded to mean "load this file, but force a reload of all its dependencies"
21:44technomancy(this is very new; a few days old maybe)
21:58TimMcbrehaut: This is pretty nice, but I'll still need a lexer.
21:58brehautTimMc: not really
21:58TimMcDo it as a char seq?
21:58brehautyeah
21:58brehautits only a problem if you are processing stupidly massive text
21:59TimMcNah, not for this.
21:59TimMcI'll give that a try in the morning. Thanks for the pointer!
21:59brehautno worries
22:08benglerthey everyone, recently i have started packaging up a clojure program as a JAR using "cake uberjar". only problem is, it depends on an external data file which it reads in and parses from the filesystem using slurp
22:08benglerti was wondering if there's anything i can put into project.clj to have it put the data file into the jar, and also what i can use to read the data file from within the JAR - i assume it's some kind of InputStream so slurp won't work
22:10mecI swear emacs never makes a backup of a buffer when it crashes, but leaves backups at all other times
22:17waxrosemec, Works for me.
22:17brehautbenglert: in lein you can put files into a Resources directory in your project
22:18waxrosebrehaut, Do you build Clojure from Github or do you install from your distro's package manager?
22:19brehautwaxrose: i install it via my projects project manager; ie as a lein dependancy
22:19waxrosehmm
22:19brehautid only build from source if i was working on clojure itself
22:21tomojbenglert: one helper is clojure.java.io/resource
22:21benglertbrehaut: okay. is there any nice clojure shorthand for reading data out of the jar file or is it going to be the usual java mess with inputstreams
22:21tomojthe return value of which is slurpable
22:21benglerttomoj: i'll take a look, thanks
22:21brehautbenglert: some of that mess is cleaned up for you in the clojure.java namespace
22:22brehautbenglert: http://clojure.github.com/clojure/clojure.java.io-api.html
22:22brehautbenglert: or what tomoj said
22:25technomancybrehaut: just be sure not to capitalize Resources, or it will only work on case-insensitive FSes
22:25technomancycase-insensitivity bugs are the worst =\
22:26brehautoh man :S
22:26brehautthats horrible
22:26tomojdo macs also come with case-insensitive tab-completion? I can't remember
22:26technomancyyeah, next time you format your OS X machine be sure to pick a sane filesystem
22:27brehauttomoj: not out of the box, despite being case insensitive
22:27technomancyunless you use Adobe products, which require the annoying FS
22:27brehauttechnomancy: we have a choice?
22:27benglerttechnomancy: you're joking, right? adobe CS won't install on a case sensitive FS?
22:27technomancybrehaut: yeah, as long as you choose it before you format
22:27technomancybenglert: as of a couple years ago, yeah
22:27technomancybrehaut: they don't make it obvious though
22:28brehauttechnomancy: yeah apparently so. what are the other choices?
22:29brehautzfs had been the only other FS i had heard about on modern OS X and thats in the can now i think?
22:34mechttps://gist.github.com/871908 my implementation for prime? is there any way to improve this, there are a couple spots that seem iffy
22:35mecI'd prefer to use take-while and drop-while but then im doing the same thing twice
22:36mecWould it be better to duplicate that effort and conj an atom with a bunch of values at once, or the values individually
22:38benglertbrehaut: tomoj: clojure.java.io/resource works great. thanks much for your help
22:38brehautbenglert: did you catch technomancy's comment about case?
22:38benglertbrehaut: indeed, thanks
22:39brehautmec if you are using take-while and drop-while you could consider split-with
22:39mecoo thank you
22:39mecoh that does both anyway, is that not inefficient?
22:40brehautmec no its real easy
22:40brehautactually my bad it does just do both :P
22:41brehautbut it could be written more efficiently
22:41brehauti'd still use it if it was clearer
22:42mecgood idea, if it's too slow ill rewrite, but that should make the code a lot clearer
22:42brehautyeah
22:44brehauthuh. im not actually sure how you would write it to be both lazy and only process it once
22:45mecgood point
22:52mecIt seems redundant to have to do (apply swap! atom conj seq)
22:54mecwhich also doesnt work
22:55brehaut&(set [1 2 3])
22:55sexpbot⟹ #{1 2 3}
22:55brehaut&(use 'clojure.set)
22:55sexpbot⟹ nil
22:55brehaut&(union #{1 2 3} (set [2 4 6]))
22:55sexpbot⟹ #{1 2 3 4 6}
22:56brehautif you want to pour seqs into sets
22:56brehautconj if you just want to add one item
22:56mecok, but how come this is saying wrong number of args to conj?
23:01brehauthmm
23:01brehautgood question
23:02brehautwhat is atom bound to?
23:02mec#{}
23:03brehautah worked it out; your seq is becoming empty at some point
23:03brehaut&(apply swap! (atom #{}) conj [])
23:03sexpbotjava.lang.IllegalArgumentException: Wrong number of args (1) passed to: core$conj
23:03brehaut&(apply swap! (atom #{}) conj [1])
23:03sexpbot⟹ #{1}
23:03mecthat was an off by 1 error i just fixed
23:04mechttps://gist.github.com/871908 how does that one look
23:04brehautbetter :)
23:04brehautwhy do you have two atoms?
23:05mecso i dont have to start over with the primes sequence?
23:05brehautif you capture the head then you wont need too
23:06brehautim not sure i understand what you are doing with it
23:06brehautoh are you walking along primes?
23:06mecya
23:06brehautok fair enough
23:07mecif I didnt hold onto it i would have to walk the whole thing each time, and this way i can see if N is possibly in the set before checking
23:07mecI still hope theres a better way, this still feels clunky
23:07brehautmems (set mems)
23:08brehautid drop that from thelet and inline the expression into swap!
23:08mecHow do you think the performance would be using (@mem n) vs (mems n) ?
23:09brehauti wouldnt think it would matter
23:09mecfair enough
23:09brehautswap! returns the new atom anyway
23:10brehautreorder it so that you do the reset! on primes first
23:10brehautand you can do ((swap! mem union (set mems)) n) as your tail
23:11mecdone
23:11brehautis this a toy?
23:12brehautbecause it has a race condition
23:12mecwheres that?
23:13brehautyou have two atoms and their values are dependant
23:13brehautits probably really minor
23:13mecdo atoms block until they return?
23:13brehauti think they might spin?
23:14brehautits syncronous anyway
23:14brehautanyway if you have syncronous coordinated references you should use STM
23:14mecok, it should be easy enough to use refs
23:14brehautyup, trivial
23:19mecim not sure I can see the race condition, but I changed to refs anway, it does seem better symantically
23:23brehauti think there is potential for the walk along primes could occur without updating mem
23:24brehautbecause atoms dont have any coordination
23:24mecI can see that
23:25amalloymec: ninjudd/clojure-useful has a do-it-only-once version of split-with
23:25amalloyor he might not have taken the months-old pull request, in which case it's in amalloy/clojure-useful :P
23:26amalloyand brehaut, it's lazy too :P
23:26brehautamalloy: i didnt say it wasnt possible; only that i was sure how it would work
23:26amalloybrehaut: i don't remember how it work either
23:27brehautim going to assume magic
23:27amalloybut it starts with (let [classified (map (juxt identify pred) coll)])
23:27amalloyor similar
23:27amalloy*identity
23:28mecis it separate?
23:28amalloyyes
23:28brehauthaha he has one open pull request ;P
23:28mecit maps [x (pred x)] first and then filters
23:29amalloyyeah
23:29amalloywhich really should have been (juxt identity pred)
23:30amalloyso that causes it to only call pred once per item in the input seq, anyway
23:31mecthat map map is hurting my brain
23:31amalloybrehaut: https://github.com/amalloy/clojure-useful/blob/master/src/useful.clj#L50 if you're trying to follow along
23:32amalloymec: it's really just [(map first (filter second coll)) (map first (remove second coll))]
23:32amalloybut without repeating anything
23:32brehautamalloy: thats not the same function as split-with though
23:32amalloybrehaut: oh right, haha
23:32amalloyno, it's like separate
23:32mecis it not?
23:32mecoh its not
23:33amalloy$source split-with
23:33sexpbotsplit-with is http://is.gd/Iw2auQ
23:33amalloylame
23:33meci would think you could do splot-with using this method
23:34brehautamalloy: i think deep magic would be needed; and it could cause some fun realisation behavior
23:34amalloymec: go do your real work, i'll put together a split-with that doesn't call pred too many times
23:34amalloybrehaut: sure. you have to realize the whole first chunk of the seq if you want to get any of the last bit
23:34brehautyes
23:34amalloynot much you can do about that
23:34brehautnope
23:35mecworked on prime? so long i cant remember what it was for
23:35amalloyso there's nothing *wrong* with c.core's version, which allows you to consume the second half of the seq without realizing the whole first half
23:35amalloybut if that's not part of your plan you might as well call pred less often
23:38brehautamalloy: http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/GHC-List.html#span
23:39amalloybrehaut: i don't speak crazy-alien
23:39amalloyexecutive summary plz
23:40brehautits time to learn :P
23:40amalloylol, i try, i try
23:40brehautit works via the magic of tail call removal and pervasive laziness
23:40brehautspan always returns a pair
23:41amalloyxs' is just xs*, right? "prime"?
23:41brehautyeah
23:41brehautthe @ notation is equivalent to :as in destructuring
23:41brehautonly backwards
23:41technomancyanyone have opinions re: archiva vs nexus?
23:42amalloyi think i see the algorithm
23:42brehautxs@(x:xs') ~= [x & xs* :as xs]
23:42amalloyi'll have to translate it to clojure to really grok it though
23:42phenom_what;s the functino to add multiple keys to a map in one assoc ?
23:42amalloyphenom_: it's called assoc :P
23:42brehautphenom_: assoc
23:42amalloy&(assoc {} :a 1 :b 2)
23:42sexpbot⟹ {:b 2, :a 1}
23:42phenom_:P i need to go the repl before coming here and looking stupid :P
23:43brehautphenom_: doc is useful
23:43brehaut&(doc assoc)
23:43sexpbot⟹ "([map key val] [map key val & kvs]); assoc[iate]. When applied to a map, returns a new map of the same (hashed/sorted) type, that contains the mapping of key(s) to val(s). When applied to a vector, returns a new vector that contains val at index. Note - index must be <= (count vector)."
23:43amalloyphenom_: or ask sexpbot:
23:43amalloy$findfn {} :a 1 :b 2 {:a 1 :b 2}
23:43sexpbot[clojure.core/assoc]
23:43mecI cant imagine programming in any other language anymore with doc source and findfn
23:43mecr/with/without/
23:44brehautmec add to your tools clojure.repl/apropos and find-doc
23:44brehaut&(apropos 'split)
23:44sexpbotjava.lang.Exception: Unable to resolve symbol: apropos in this context
23:44brehaut&(use 'clojure.repl)
23:44sexpbot⟹ nil
23:44brehaut(&apropos 'split)
23:44brehaut&(apropos 'split)
23:44sexpbot⟹ (split-args split-with split-at split-str-at split-cmds split split-lines split split-lines re-split)
23:45brehautturns out it works better if you arent a munter
23:45amalloybrehaut: i asked my mate jason about munted. he was like, i guess i know what it must mean, but i'm not sure i'd ever say it. is it a new-zealand-only thing?
23:45mecwow apropos is what i wanted instead of find-doc
23:45brehauti didnt think it was but maybe
23:46brehautapropos is super great
23:46amalloylooking it up on urbandictionary was pretty funny though
23:46meci stopped using find-doc because there are so many definitions that contain function names everywhere
23:47brehautamalloy: haha thats pretty great
23:48amalloybrehaut: what is "in" doing?
23:48brehautits syntax demarkating the local variables from the expression they are in
23:49brehaut(let [[ys,zs] (span p xs*)] [(cons x ys) zs])
23:49brehautwould be the clojure eqiuv
23:50amalloyokay. that makes sense but is somehow hard to keep in my head no matter how many times i figure it out
23:51brehauti find let a bit horrible in haskell, its where form is much nicer
23:51amalloyugh i keep forgetting i'm trying to implement split-with, not separate
23:51brehauthaha