#clojure logs

2009-03-23

00:01durka42it seems this has come up
00:01durka42http://groups.google.com/group/clojure/browse_frm/thread/134642cc76de17f7/90ef52f8f4c68e0a?lnk=gst&q=mevery#90ef52f8f4c68e0a
00:01durka42page down to chouser's comments on mevery?
00:03Mecyup i agree
00:13Mechow does this make sense, i swap the argument names around, and swap the arguments i pass, and get different values
00:15durka42paste?
00:16RaynesI hate spending an hour fixing something that isn't broken.
00:16Mecindeed
00:17Meclooks like its working now who knows why
00:28nascent16ok, let's say i have a map of classes (def classes {:one One, :two Two}). Later on I want to do something like: (let [klass (:one classes)] (klass.))
00:28duncanmwhat's the clojure equivalent of EXACT->INEXACT from Scheme?
00:28nascent16but it doesn't like that
00:28Raynes(-> apply doc)
00:28RaynesThat was aweasome.
00:29Raynesawesome*
00:29duncanmhow do i convert a ratio to a number with a decimal point?
00:29Raynes,(double (/ 3 2))
00:29clojurebot1.5
00:29RaynesLike that.
00:29duncanmoh
00:30nascent16,(/3 2)
00:30clojurebotInvalid token: /3
00:30nascent16,(/ 3 2)
00:30clojurebot3/2
00:30Mec,(double 3/2)
00:30clojurebot1.5
00:30Raynesdouble simply coerces the value to a double.
00:30slashus2,(double (+ 1/4 1/8))
00:30clojurebot0.375
00:31nascent16,(+ 1/4 1/8)
00:31clojurebot3/8
00:31nascent16(+ 1/5 1/8)
00:31nascent16haha
00:31duncanm,(ratio 0.375)
00:31clojurebotjava.lang.Exception: Unable to resolve symbol: ratio in this context
00:31duncanmoh
00:32duncanm,(Ratio. 0.375)
00:32clojurebotjava.lang.IllegalArgumentException: Unable to resolve classname: Ratio
00:32durka42nascent16: you might have to do that as sort of a macro. (eval `(new ~(:one classes)))
00:32duncanmso there's no INEXACT->EXACT?
00:32slashus2,(rationalize 0.375)
00:32clojurebot3/8
00:33Mecyou could do (defn ration [n] (/ n (pow 10 (count (str n))))
00:33duncanmoh
00:33slashus2duncanm: That work?
00:33Mec((fn ratio [n] (/ n (pow 10 (count (str n))))) .375)
00:33durka42nascent16: (.newInstance (:one classes))
00:33Mec,((fn ratio [n] (/ n (pow 10 (count (str n))))) .375)
00:33clojurebotjava.lang.Exception: Unable to resolve symbol: pow in this context
00:33Mec,((fn ratio [n] (/ n (Math/pow 10 (count (str n))))) .375)
00:33clojurebotjava.lang.Exception: Unable to resolve symbol: .375 in this context
00:34Mecsec let me do it in my repl
00:34slashus2,(rationalize 0.123456)
00:34clojurebot1929/15625
00:34nascent16durka42: yeah, that worked
00:34nascent16thanks
00:34duncanmslashus2: yeah, that does
00:35Mecaw boo
00:35duncanmuser=> (rationalize (double 1/4)) ;=> 1/4
00:35slashus2duncanm: To tell you the truth, I found it in the doc as soon as you asked. Pretty neat.
00:35Mec,(rationalize Math/pi)
00:35clojurebotjava.lang.Exception: No such namespace: Math
00:36Mecorly
00:36nascent16Mec: that's exactly what I wanted to try
00:36duncanm,(rationalize Math/PI)
00:36clojurebot3141592653589793/1000000000000000
00:36nascent16boo
00:36Meclol
00:36slashus2right hehe
00:40nascent16,(def m Math)
00:40clojurebotDENIED
00:40nascent16fine
00:41nascent16(let [m Math] m/PI)
00:41nascent16,(let [m Math] m/PI)
00:41clojurebotjava.lang.Exception: No such namespace: m
00:41Mecany shorthand for (map f1 (map f2 coll))
00:41Mechmm #(f1 (f2 %)) lol
00:43Raynes(map (fn [seqstr] (remove #(= % \=) seqstr)) ["lol = haha" "rofl = omfg"]) Fancy.
00:43nascent16,(let [m Math] (ns-resolve m PI))
00:43clojurebotjava.lang.Exception: Unable to resolve symbol: PI in this context
00:45duncanmMec: is that the same as (map (compose f1 f2) coll) ?
00:45nascent16,(let [m Math] (ns-refers m))
00:45clojurebotjava.lang.ClassCastException: java.lang.Class cannot be cast to clojure.lang.Symbol
00:45Mecthere is no compose, but thats how you would define it
00:45duncanmand compose is something like (fn [x] (f1 (f2 x)))
00:45Mec(doc compose)
00:45clojurebotexcusez-moi
00:46duncanm(defn compose [f1 f2] (fn [x] (f1 (f2 x))))
00:46slashus2(doc comp)
00:46clojurebotTakes a set of functions and returns a fn that is the composition of those fns. The returned fn takes a variable number of args, applies the rightmost of fns to the args, the next fn (right-to-left) to the result, etc.; arglists ([& fs])
00:46duncanmoh
00:46duncanmthere we go
00:46duncanm(map (comp f1 f2) coll)
00:47Mecnice
00:52nascent16,(let [m Math] (.get (.getField m "PI") m))
00:52clojurebot3.141592653589793
00:52nascent16There's got to be a better way than that
00:54Mecto do what
00:55nascent16get static members out of a reference to a class
00:55Mec,(Math/PI)
00:55clojurebot3.141592653589793
00:55Mecoh
00:55nascent16yeah, but this doesn't work:
00:55nascent16(let [m Math] m/PI)
00:55nascent16,(let [m Math] m/PI)
00:55clojurebotjava.lang.Exception: No such namespace: m
00:56replacanascent16: that's because you're giving it the name m/PI
00:57replacathat's all one thing, not a reference to the symbol you bound earlier
00:57replacawith the let
00:57nascent16I understand why it doesn't work, but I don't understand how to make it work
00:57nascent16except for that ugly thing i did above
00:58replacathis seems like a pretty uncommon case, but you could write a simple function if you want to do it often
00:58Mec(. Math PI)
00:58Mec,(. Math PI)
00:58clojurebot3.141592653589793
00:58nascent16haha
00:59Mec,(let [m Math] (. m PI))
00:59clojurebotjava.lang.IllegalArgumentException: No matching field found: PI for class java.lang.Class
00:59durka42,(let [m Math] (eval `(. ~m PI)))
00:59clojurebotDENIED
00:59Meci can haz confusion
00:59nascent16so m becomes a generic Class reference, whereas Math is a specific class (java.lang.Math)
01:00Mec,((let [m Math] `(. ~m PI)))
01:00clojurebotjava.lang.ClassCastException: clojure.lang.Cons cannot be cast to clojure.lang.IFn
01:00Mecsay what
01:00nascent16i'm not sure
01:00durka42,(let [m Math] `(. ~m PI))
01:00clojurebot(. java.lang.Math sandbox/PI)
01:01Mec,(let [m Math] (`(. ~m PI)))
01:01clojurebotjava.lang.ClassCastException: clojure.lang.Cons cannot be cast to clojure.lang.IFn
01:01Mec,(let [m Math] (identity \`(. ~m PI)))
01:01clojurebotjava.lang.IllegalStateException: Var clojure.core/unquote is unbound.
01:01Mec,(let [m Math] (identity `(. ~m PI)))
01:01clojurebot(. java.lang.Math sandbox/PI)
01:01Meci quit
01:01nascent16haha... what's this sandbox business?
01:01Mecthats just the namespace instead of user
01:01replacayou keep trying to evaluate a list as a function
01:01nascent16ah
01:01durka42which you need eval for
01:02replacayou really don't ever want backquote outside a func
01:02replacano, even with eval, a list isn't a function. It's a list
01:02durka42you need eval to treat it as code
01:02replacayou can eval the list itself, but that's not a different thing
01:03replaca,('(1 2) 7)
01:03clojurebotjava.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.IFn
01:03replacais basically what you were trying there
01:04danlarkinI'm slightly confused as to why (. Math PI) isn't good enough for you?
01:04nascent16let's say I had a variety of options for which PI was all different
01:04nascent16MyMath YourMath HisMath
01:04nascent16and depending on which Math was chosen, I want to use the correct value of PI
01:04danlarkin,(#(. %1 %2) Math PI)
01:04clojurebotjava.lang.Exception: Unable to resolve symbol: PI in this context
01:05replacaI think that Rich has really special-cased <classname>/<static> and . in a way that doesn't work generally
01:05danlarkinbarf
01:06nascent16,(#(. %1 %2) Math 'PI)
01:06clojurebotjava.lang.IllegalArgumentException: No matching field found: p2__2425 for class java.lang.Class
01:07replacaI think . may be doing some capture at readtime
01:07replacalooking at that error
01:07danlarkin. is a special form
01:08danlarkinso it does fanciness
01:20Mecis there a way to interrupt the currently executing expresion in emacs without haveing to break and restart the lisp connection
01:20replacanascent16: try this:
01:21replaca(defmacro getStatic [c f] `(.get (.getField ~c (name '~f)) ~c))
01:21replacathen, (getStatic m PI) does what you want
01:21nascent16nice
01:22nascent16hardly elegant, but it looks like it'll do the trick
01:22replacaMec: Chouser posted something to contrib a while back, but I don't know if anyone's tested it in emacs
01:22replacaMec: I've been meaning to, but haven't gotten around to it
01:23replacanascent16: the great things about macros is that they can hide various sorts of inelegance
01:23replacaand leave your program feeling nice and clean
01:24technomancylike freshly brushed teeth
01:24nascent16and i suppose that's the point afterall, to make these horrible machines look pretty and well behaved
02:34vagifHello, anyone using slime with clojure ?
02:39arbschtvagif: yes
02:49RaynesI say kill them all and let fate sort out the mess.
03:07vagifarbscht: in emacs when I put cursor on function name, it shows me Evaluation Aborted. Is this how it should behave ?
03:17RaynesNo th... Oh, he's gone.
04:13lisppaste8Rayne pasted "Anyone know how to indent this and make it look good? :\" at http://paste.lisp.org/display/77455
04:17Carkemake a file->seq function and a remove= function
04:18Carkealso i beleive (map f (map g ...)) is like (map (comp f g) ...)
04:35RaynesCarke: Thanks for the input. I don't think I can turn this into a comp in this specific situation however. But splitting it up into several functions makes my code look less crappy, thanks.
04:38Carkmhh yes you could (map (comp stringify remove=) (-> "text.txt" FileReader. BufferedReader. line-seq))
04:38Carkor something like that
04:38Cark,(doc comp)
04:38clojurebot"([& fs]); Takes a set of functions and returns a fn that is the composition of those fns. The returned fn takes a variable number of args, applies the rightmost of fns to the args, the next fn (right-to-left) to the result, etc."
04:39RaynesWell yeah if I split those functions up as well.
04:40Cark(map (comp #(apply str %) (fn [s] (remove #(= \= %) s))) (-> "text.txt" FileReader. BufferedReader. line-seq))
04:40Cark(map (comp #(apply str %) (fn [s] (remove #(= \= %) s))) (-> "text.txt" FileReader. BufferedReader. line-seq))
04:40Carkhum oops
04:41Carkmirc is no good to edit code !
04:41slashus2for the last part can you just not do (line-seq (File. "text.txt"))
04:41Raynesslashus2: No.
04:42Raynes(doc line-seq)
04:42slashus2no.
04:42clojurebotReturns the lines of text from rdr as a lazy sequence of strings. rdr must implement java.io.BufferedReader.; arglists ([rdr])
04:42slashus2oh
04:42slashus2that is line-seq
04:42slashus2I was seeing file-seq
04:42Cark,(doc file-seq)
04:42RaynesCark: Thanks, I tried that, I guess I'm just too tired and screwed something up.
04:42clojurebot"([dir]); A tree seq on java.io.Files"
04:42Raynes<3
04:43Carkyou probably got the order wrong in your composition
04:44RaynesCark: Probably mismatched parentheses actually.
04:44RaynesI can't think very well when I'm tired.
04:45Raynes(-> "Hi" println)
04:46RaynesOops, this isn't my REPL
04:46Raynes:|
04:46Cark,(-> "hi" println)
04:46clojurebothi
04:46slashus2Raynes: We may need sleep.
04:47Cark,(-> "derit" reverse #(apply str %) prinln)
04:47clojurebotjava.lang.Exception: Unable to resolve symbol: prinln in this context
04:47Cark,(-> "derit" reverse #(apply str %) println)
04:47clojurebotjava.lang.ClassCastException: clojure.lang.Symbol cannot be cast to clojure.lang.IPersistentVector
04:48Cark,(-> "derit" seq reverse #(apply str %) println)
04:48clojurebotjava.lang.ClassCastException: clojure.lang.Symbol cannot be cast to clojure.lang.IPersistentVector
04:48Carkahwell
04:49Raynes,(-> "Hi there!" .toUpperCase println))
04:49clojurebotHI THERE!
04:49RaynesOh I see.
04:50RaynesIt's bed time.
04:50RaynesNight, thanks for the help Cark.,
04:50Carkgnight raynes
06:11AWizzArdcd #Foswiki
06:11AWizzArdsorry
08:27MikeSethweee clojure people
08:31leafwjust awaking.
08:54AWizzArdclojurebot: max people
08:54clojurebotmax people is 164
08:55vdrabI'm curious about parallel processing with pmap. Most of the programs I run these days are perl scripts that do perl things... "read lines from a file, do some processing for each line and put the results in a hash" - type of stuff. Given enough cores, is there any performance boost to be expected from wrapping the file in a seq and processing it with pmap, or will the IO overhead and low cost of processing a single line negate the benefits of parall
08:55vdrabelization (say, on a machine with 8 cores and memory to spare)
08:56rsynnottif IO's the bottleneck, it will likely continue to be the bottleneck
08:56MikeSethsounds like a task for hadoop et al.. though dont take my word for it
08:58vdrabyeah... I was just wondering whether there is any clear point at which clojure's parallelization options become really attractive for performance
09:00vdrabI guess it's no silver bullet, but was curious to hear some use cases where you got big speedups from pmap
09:01davatkif you did some performance tests, I bet people would be interested.
09:02vdrabdavatk: hehe... right, point taken.
10:32cconstantine_how do I use pmax? I get a "Unable to resolve symbol: pmax in this context" when I try to just use it, and I can't figure out how to reference into the parallel namespace where it appears to live
10:52Chousukecconstantine_: (use 'clojure.parallel)?
10:53cconstantine_this needs java 1.6 doesn't it?
10:55ChousukeI think it needs an experimental jar.
10:55Chousukeyou should read the parallel.clj file, it's documented there :P
10:56cconstantine_:/
11:05thickeycconstantine_: you need the jar here http://clojure.googlegroups.com/web/jsr166y.jar
11:08cconstantine_thanks
11:08hiredmanerm
11:16cconstantine_has anyone considered a parallel lazy-sequence; ie, start computing the next value when returning the current value?
11:17cconstantine_or even caching up to N values ahead
11:22hiredman,(doc seque)
11:22clojurebot"([s] [n-or-q s]); Creates a queued seq on another (presumably lazy) seq s. The queued seq will produce a concrete seq in the background, and can get up to n items ahead of the consumer. n-or-q can be an integer n buffer size, or an instance of java.util.concurrent BlockingQueue. Note that reading from a seque can block if the reader gets ahead of the producer."
11:23cconstantine_oh
11:23cconstantine_well there ya go :)
11:27cconstantine_wow, so that doesn't always help
11:27MarkVolkmannWhat is the function that returns the first item in a sequence for which a given predicate returns true?
11:29cconstantine_drop-while will ive you the first element that pred returns false on...
11:29cconstantine_(first (drop-while (complement pred) sequence))
11:31hiredman,(some (partial < 3) (range 10))
11:31clojurebottrue
11:31MarkVolkmannAh ... I just found find-first in clojure.contrib.seq-utils
11:31hiredmanhmmm
11:31hiredmanoh
11:31hiredmanright
11:31hiredman,(some #(if (< 3 %) % nil) (range 10))
11:31clojurebot4
11:34hiredman,(some #(and (< 3 %) %) (range 10))
11:34clojurebot4
11:34hiredman,(meta and)
11:34clojurebotjava.lang.Exception: Can't take value of a macro: #'clojure.core/and
11:34hiredman,(meta (var and))
11:35clojurebot{:macro true, :ns #<Namespace clojure.core>, :name and, :file "core.clj", :line 513, :arglists ([] [x] [x & next]), :doc "Evaluates exprs one at a time, from left to right. If a form\n returns logical false (nil or false), and returns that value and\n doesn't evaluate any of the other expressions, otherwise it returns\n the value of the last expr. (and) returns true."}
11:59hiredmanbtw, if you ever want to use binding to bind a macro to another symbol, var is how you do it
12:04cconstantine_(var macro) returns the macro expanded?
12:04cconstantine_no.. the macro as a thing. cool
12:06cconstantine_so, pmax isn't exactly standard because of parallelization stuffs. Is there a non-parallel max that takes a collection instead of a set of things?
12:06hiredman(doc max)
12:06clojurebotReturns the greatest of the nums.; arglists ([x] [x y] [x y & more])
12:06hiredman,(apply max (java.util.ArrayList. [1 2 3]))
12:07clojurebot3
12:07hiredmanlooks like it works on collections to me
12:07cconstantine_right, so how do a take a collection and turn it into an argument list?
12:07hiredmanactually, I think max was faster using reduce then apply
12:08cconstantine_When I call max on a list it just returns the list... do I need to convert it into something else?
12:09hiredman,(binding [doc (var or)] (doc nil :a))
12:09clojurebotjava.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Wrong number of args passed to: sandbox$my-doc
12:09hiredman:(
12:09hiredmanwell, that usually works
12:09hiredmancconstantine_: max does not take a list
12:09hiredmanit takes a series of things
12:09hiredman,(max 1 2 3)
12:09clojurebot3
12:10hiredmanyou can use reduce or apply to apply max to a list
12:10cconstantine_ahh, I see
12:10hiredman,(reduce max (range 10))
12:10clojurebot9
12:10hiredman,(apply max (range 10))
12:10clojurebot9
12:10cconstantine_I missed the 'apply' in your previous thinger
12:10hiredmanform
12:11digash`hiredman: i am wondering, why do you say that reduce max is faster apply max?
12:11hiredmandigash`: because we timed it
12:12hiredmanmax uses reduce internally for more then one arg
12:12hiredmanand the internal reduce produces more calls to max
12:13hiredmanso it is faster (or at least it was) to use your own reduce
12:14digash`hiredman: i guess i missed part of the conversation
12:14hiredmandigash`: it was a few weeks ago
12:17digash`hiredman: it is still faster to call reduce, which is surprising to me
12:18hiredman~def max
12:20hiredmanyeah, so the internel reduce results in something like N*1/2 more calls to max then using reduce yourself
12:22Chousukehm
12:22Chousukewhy?
12:23ChousukeI can't see that from the code :/
12:23hiredmanbecause it calls max twice in the reduce
12:23hiredman(reduce max (max x y) more)
12:23Chousukebut (max x y) is only evaluated once
12:23hiredmanacutally
12:24hiredmanI think it may be more then N/2
12:24hiredmanoh
12:24hiredmanoh
12:24hiredmanyeah
12:24hiredmanhmmm
12:24digash`take a look at this
12:24digash`,(time (apply max 0 0 (range 10000000)))
12:24clojurebot9999999
12:24clojurebot"Elapsed time: 1958.762 msecs"
12:25digash`,(time (apply max (range 10000000)))
12:25clojurebot9999999
12:25clojurebot"Elapsed time: 3589.016 msecs"
12:25Chousukehuh?
12:25hiredmanhah
12:26Chousuke,(time (reduce max 0 (range 10000000)))
12:26clojurebot9999999
12:26clojurebot"Elapsed time: 1923.614 msecs"
12:26digash`something strange in the jit land?
12:38danlarkindigash`: who knows, maybe a cronjob was running... statistical outlier... it's meaningless
12:39hiredman...
12:53cconstantine_speaking of which.. is there an easy way to evaluate an expression multiple times and grab statistics on how long each time took to run?
12:55AWizzArdHow can one access environment variables? (be it Windows or Unix ones)
12:56hiredman,(time (dotimes [i 10000] (reduce max 0 (range 100000000))))
12:56clojurebotExecution Timed Out
12:56hiredman:(
12:57hiredman,(time (dotimes [i 100] (reduce max 0 (range 100000000))))
12:57Carkclojurebot is ronning on a zx spectrum
12:57clojurebotExecution Timed Out
12:57Cark*running
12:57hiredman"On the Java platform, an application uses System.getEnv to retrieve environment variable values."
12:59AWizzArdthx
13:00cconstantine_hiredman: that just gives me the time to execute that many times, I'm thinking things like min, max, avg, etc
13:01cconstantine_or even just give backa list of time to execute
13:02cconstantine_*list of times to execute
13:03hiredman*shrug*
13:03cconstantine_that would be really helpfull for doing timing tests
13:04cconstantine_particularly if you have to interact over a network
13:05cconstantine_or even just get back the time to execute of an expression as an object instead of putting it to stdout
13:05AWizzArd,(first (System/getenv))
13:05clojurebotjava.security.AccessControlException: access denied (java.lang.RuntimePermission getenv.*)
13:06AWizzArdcconstantine_: (dotimes [i 10] (time (print (+ 100 i))))
13:07AWizzArd,(with-out-str (dotimes [i 5] (time (+ 100 i))))
13:07clojurebot"\"Elapsed time: 0.046 msecs\"\n\"Elapsed time: 0.0080 msecs\"\n\"Elapsed time: 0.0040 msecs\"\n\"Elapsed time: 0.0050 msecs\"\n\"Elapsed time: 0.0040 msecs\"\n"
13:07AWizzArdrun a regexp over this result string, collect the times and enjoy
13:07cconstantine_wow
13:08cconstantine_that.... works. but it seems like overkill
13:08cconstantine_not overkill.... overly complicated
13:08AWizzArdmacro this complexity away
13:08AWizzArdwrite a macro (profile (+ 10 5)) or something like that
13:08AWizzArdand a function (report)
13:09AWizzArdor just use an existing profiler
13:09cconstantine_the regex is still happening in the background
13:09dnolen_also time is a fairly simple macro in core.clj (5 LOC), instead of hacking around it just write your own.
13:10pjstadig~def time
13:10cconstantine_dnolen_: that sounds like a much better option :)
13:10Chouser_cgrand: so have you realized yet that zip-filter's not going to cut it?
13:12cconstantine_in CL it's possible to return multiple values, is that possible in clojure?
13:12bitbcktcconstantine_: return a vector
13:12dnolen_or anything, the point is that you can destructure
13:13cconstantine_bitbckt: right, but that means the caller has to look into the returned value. Ok. In the case of my new timing function it would be easier to not force the caller to change they way they handle the return value... I never liked multiple return values anyway
13:14bitbcktdestructuring is idiomatic in Clojure
13:14cconstantine_yeah
13:14dnolen_if you want to include extra info some reason you could always add metadata
13:14cconstantine_ooooo
13:14cconstantine_I like that
13:14pjstadigcconstantine_: jeffery chu posted a (IMO pretty briliant) example of rolling your own in Clojure http://paste.lisp.org/display/68919
13:14cconstantine_add the time to execute as metadata
13:14hiredmanwhen I first showed up in #clojure, someone was rewriting time so it attached the time result as metadata to the result
13:14pjstadigmultiple value return isn't exactly the same as returning a vector
13:15cconstantine_pjstadig: thanks
13:15cconstantine_pjstadig: I think I like the meta-data thing better
13:15Carkquestion : i read on the mailing list that subvec retains the full original vector, is that true ?
13:15hiredmanthe problem with metadata is attaching it to things that don't support metadata
13:16hiredman~def subvec
13:16cconstantine_hiredman: is that a lot of stuff?
13:16hiredmancconstantine_: yes
13:16cconstantine_hiredman: oh :(
13:16hiredmanbut clojure collections support metadata
13:17hiredman~def clojure.lang.RT
13:17hiredman~def c.l.APersistentVector
13:18Carklooks like it does
13:18Carkthis.v = v;
13:18cconstantine_hiredman: yeah... if enough stuff does it shouldn't be too bad
13:26hiredmanclojurebot: botsnack
13:26clojurebotthanks; that was delicious. (nom nom nom)
13:27bitbcktcogito ergo nom
13:31Chouser_you can't put metadata on strings, numbers, or keywords. Only things that inherit from IMeta.
13:32hiredman,(ancestores (class :a))
13:32clojurebotjava.lang.Exception: Unable to resolve symbol: ancestores in this context
13:32hiredman,(ancestors (class :a))
13:32clojurebot#{clojure.lang.Named clojure.lang.IFn java.lang.Object java.lang.Runnable java.lang.Comparable java.util.concurrent.Callable}
13:32hiredman,(ancestors clojure.lang.IFn)
13:32clojurebot#{java.lang.Runnable java.util.concurrent.Callable}
13:33digash``t
13:40cconstantine_ew, refs don't even support metadata
13:40Cark~def concat
13:43dnolen_cconstantine: why do need refs themselves need it?
13:43dnolen_,(meta @(ref (with-meta {:mykey :myval} {:mymetakey :mymetaval})))
13:43clojurebot{:mymetakey :mymetaval}
13:43cconstantine_dnolen: I'm trying to think of something I can wrap non-metadata-holding types in.
14:45cadsfrom inside clj, how may I find out the version of clojure i'm using?
14:52danlarkincads: you can't
14:55cadscould we write a function like that?
14:57danlarkinit's been proposed before... I don't think there was agreement on where the version should come from, or where it should go, at what point.. etc
14:58Lau_of_DKGood evening all
14:58danlarkinHey Lau
15:06tashafa(doc with-meta)
15:06clojurebotReturns an object of the same type and value as obj, with map m as its metadata.; arglists ([obj m])
15:13cads(+ 1 2 3)
15:13clojurebot*suffusion of yellow*
15:15triddell,(+ 1 2 3)
15:15clojurebot6
15:16triddellcads: need a comma above ^
15:27gnuvinceHey, Clojure is at revision 1337!
15:28cgrandChouser: the tricky part is to update a bunch of locs. The other thing is that zip-filter is a fold on the selector while, for Enlive, I'll prefer to fold over paths
15:35hiredman~latest
15:35clojurebotlatest is 1337
15:35hiredmanit sure is
15:36JasonCWarnerHi room. Anyone here working on any compojure stuff?
15:42dnolenJasonCWarner: i'm starting to play around with it, yeah, but haven't got too far into it yet.
15:43JasonCWarnerI'm just starting as well. Hoping to find some people to help with a problem. Can't quite figure out how to configure Jetty to serve static content (public/) with the new ring compojure code
15:44pjstadigi was gonna say check the wiki (because I think they have an example for serving static code, but that's probably not for the ring code)
15:44pjstadigi've played with compojure minimally
15:45dnolenJasonCWarner: there's a Compojure google group, people are relatively responsive, also perhaps the clojure ring project has an example on github?
15:45pjstadigthere's a google group not sure if you've checked that out
15:45pjstadigthey should have a #compojure channel
15:45pjstadigi'd hang out in there
15:56Lau_of_DKCan somebody explains Compojures decorators to me ?
15:56Lau_of_DK-s
16:23JasonCWarnerThanks, pjstadig, joining that room now...
16:51digash`Clojure is the future.
16:55slashus3digash`: Was Rich's tutorial filmed yesterday at the international lisp conference?
16:56digash`yes, there were cameras
16:57slashus3Probably will be released later.
16:58digash`you can probably bug Daniel Weinreb, http://www.international-lisp-conference.org/2009/committee
16:59digash`the whole discussion, is around clojure
17:01hiredmanhow awesome it is? how much they hate it?
17:01digash`i did not here any negative comment yet
17:01hiredmanhow it's a mistake and should just be another doohickey (he he hickey) tacked on to common lisp?
17:01hiredmanexcellent
17:04digash`The first comment negative comment from Pascal "JVM and CLR must die!"
17:04pjstadigmy only concern about all of the attention for clojure at these conferences is that it's taking away Rich's time
17:04pjstadighe's making presentations instead of hacking clojure!
17:04slashus3I am sure it gives him time to think.
17:05triddellagreed... clojure isn't where it is because Rich has been in a vacuum
17:10digash`Kent: "Standardisation is one big mutex."
17:14cconstantineI have no idea what is being said at this conference... but I see Clojure beating CL for one reason; it *has* a standard compiled distribution model (class files).
17:15digash`Sussman: "Language is a medium for expressing ideas clearly"
17:24cconstantineSo what does that say about most perl scripts? ;)
17:25hiredmanyou use a lot of foul language
17:27digash`ouch, somebody just suggested that Lisp is not popular with women.
17:29ChousukeWell, maybe women are just jealous, since lisp has nice curves. :P
17:29hiredmanclojurebot: women?
17:29clojurebotHuh?
17:29hiredmanclojurebot: women is <reply>women are just jealous, since lisp has nice curves. -- Chousuke
17:29clojurebotRoger.
17:29stuhoodoh no
17:30Chousuke;(
17:31hiredmanclojurebot: men?
17:31clojurebotnamespaces are (more or less, Chouser) java packages. they look like foo.bar; and corresponde to a directory foo/ containg a file bar.clj in your classpath. the namespace declaration in bar.clj would like like (ns foo.bar). Do not try to use single segment namespaces. a single segment namespace is a namespace without a period in it
17:31hiredmanHuh
17:32hiredmanI guess that is one for the ages
17:34digash`"Common Lisp is a giant casserole".
17:35bitbcktWow. clojurebot needs a copy editor
17:36Chousukebitbckt: you can always tell it new stuff
17:36bitbcktChousuke: I know.
17:37Chousukemeaning you can also override old definitions :P
17:37bitbcktChousuke: Yes, I know.
17:39hiredmanoverriding that one would be very interesting
17:40hiredmanclojurebot: foo.bar
17:40clojurebotamespaces are (more or less, Chouser) java packages. they look like foo.bar; and corresponde to a directory foo/ containg a file bar.clj in your classpath. the namespace declaration in bar.clj would like like (ns foo.bar). Do not try to use single segment namespaces. a single segment namespace is a namespace without a period in it
17:40hiredmanvery interesing indeed
17:45kefkaHey. I think I may have found a case of insufficient parallelism w/ futures.
17:46kefkaThis should take ~0 sec to return and ~9 to display at the REPL, though it'd take 45 to display with no paralleism at all. In practice, it seems to take 25.
17:46kefka,(map #(future (Thread/sleep (* 1000 %)) %) (range 10))
17:46clojurebot(#<Object$Future$IDeref@1ae9cec: 0> #<Object$Future$IDeref@c08964: 1> #<Object$Future$IDeref@7c06ab: 2> #<Object$Future$IDeref@9a0466: 3> #<Object$Future$IDeref@196de7e: 4> #<Object$Future$IDeref@1e9315f: 5> #<Object$Future$IDeref@a86249: 6> #<Object$Future$IDeref@ccdd53: 7> #<Object$Future$IDeref@1d69fa3: 8> #<Object$Future$IDeref@18ab25b: 9>)
17:46kefkaHuh. The Clojure bot did it in decent time.
17:47kefkaHave futures been altered in the past week in any way that would affect parallelism/concurrency?
17:48kefkaOn my REPL, it takes about 25 seconds to display, indicating that it's getting some (but poor) parallelism
17:48hiredmanerm
17:48hiredman,(doc future)
17:48clojurebot"([& body]); Takes a body of expressions and yields a future object that will invoke the body in another thread, and will cache the result and return it on all subsequent calls to deref/@. If the computation has not yet finished, calls to deref/@ will block."
17:50hiredmanare you sure you didn't leave out a zero on that test
17:51hiredmanfutures are concurrent in the sense that they execute in another thread, but derefing them will block
17:51hiredmanand printing the output at the repl derefs them
17:51hiredmanso print is blocking for each thread/sleep as it goes down the seq
18:00slashus3,(time (first (map #(future (Thread/sleep (* 1000 %)) %) (range 10))))
18:00clojurebotjava.lang.Exception: Unable to resolve symbol: in this context
18:01slashus3,(time (first (map #(future (Thread/sleep (* 1000 %)) %) (range 10))))
18:02slashus3hmm
18:02hiredmanclojurebot: ping?
18:02clojurebotPONG!
18:02slashus3not quite sure what happened there.
18:03slashus3Well anyway, if you retrieve the second one it takes around one second, confirming the case.
18:04slashus3the blocking deference
18:04slashus3dereference
18:04kefkaI think I figured the issue out. It's that map is lazy.
18:04kefkaerr, I mean map returns a lazy sequence
18:05slashus3kefka: Where was the problem?
18:05kefkaif you evaluate the futures as the map runs, they go off sequentially -> poor performance.
18:06kefkaIf you don't force the seq produced by the map to be consumed at time 0 (or as close as possible) the futures aren't instantiated at time 0, so you get poor performance.
18:06kefkaBut this will run in about 0.9 seconds, as it should:
18:07kefkaEdit: never mind. I didn't find it.
18:07kefkaHere's something that should run in 0.9 sec, but takes 4.5
18:07kefka,(time (apply + (map deref (map #(future (Thread/sleep (* 100 %)) %) (range 10)))))
18:07clojurebot45
18:07clojurebot"Elapsed time: 4511.046 msecs"
18:08kefka,(time (apply + (pmap deref (pmap #(future (Thread/sleep (* 100 %)) %) (range 10)))))
18:08clojurebot45
18:08clojurebot"Elapsed time: 1114.229 msecs"
18:09kefkaSo it works properly with pmap, but that shouldn't matter, because the function future should be returning immediately, allowing the next future to start.
18:09slashus3kefka: Running that map on my computer takes 25 seconds too.
18:09Chousukeslashus3: are you sure you have multiple cores? :P
18:10Chousukeah, wait, guess that shouldn't matter ;(
18:10slashus3I don't have multiple cores.
18:10slashus3On this computer.
18:11slashus3If it is derefing the objects one by one shouldn't it be 10 seconds?
18:11slashus3wait
18:11slashus3no
18:12slashus3That is correct.
18:12kefka,(time (apply + (map deref (pmap #(future (Thread/sleep (* 100 %)) %) (range 10)))))
18:13clojurebot45
18:13clojurebot"Elapsed time: 1505.738 msecs"
18:13kefka,(time (apply + (pmap deref (pmap #(future (Thread/sleep (* 100 %)) %) (range 10)))))
18:13clojurebot45
18:13clojurebot"Elapsed time: 1104.012 msecs"
18:13kefka,(time (apply + (pmap deref (map #(future (Thread/sleep (* 100 %)) %) (range 10)))))
18:13clojurebot45
18:13clojurebot"Elapsed time: 1504.964 msecs"
18:13kefka,(time (apply + (map deref (map #(future (Thread/sleep (* 100 %)) %) (range 10)))))
18:13clojurebot45
18:13clojurebot"Elapsed time: 4511.04 msecs"
18:14kefka,(time (apply + (map deref (into [] (map #(future (Thread/sleep (* 100 %)) %) (range 10))))))
18:14clojurebot45
18:14clojurebot"Elapsed time: 902.647 msecs"
18:14hiredman,(time (apply + (seque 10 (map #(future (Thread/sleep (* 100 %)) %) (range)))))
18:14clojurebotjava.lang.IllegalArgumentException: Wrong number of args passed to: core$range
18:14hiredman,(time (apply + (seque 10 (map #(future (Thread/sleep (* 100 %)) %) (range 10)))))
18:14clojurebotjava.lang.ClassCastException: clojure.proxy.java.lang.Object$Future$IDeref cannot be cast to java.lang.Number
18:14kefkaHuh. So I get best performance when I send it right into a vector, instead of using the Lazy-seq.
18:14hiredman,(time (apply + (seque 10 (map #(deref (future (Thread/sleep (* 100 %)) %)) (range 10)))))
18:14kefka,(doc seque)
18:14clojurebot45
18:14clojurebot"Elapsed time: 4513.484 msecs"
18:14clojurebot"([s] [n-or-q s]); Creates a queued seq on another (presumably lazy) seq s. The queued seq will produce a concrete seq in the background, and can get up to n items ahead of the consumer. n-or-q can be an integer n buffer size, or an instance of java.util.concurrent BlockingQueue. Note that reading from a seque can block if the reader gets ahead of the producer."
18:16slashus3,(time (map #(future (Thread/sleep 1000) %) (range 10)))
18:16clojurebot(#<Object$Future$IDeref@1a142ec: 0> #<Object$Future$IDeref@26d149: 1> #<Object$Future$IDeref@76481e: 2> #<Object$Future$IDeref@178c581: 3> #<Object$Future$IDeref@1eea016: 4> #<Object$Future$IDeref@150262b: 5> #<Object$Future$IDeref@f9de08: 6> #<Object$Future$IDeref@600ee8: 7> #<Object$Future$IDeref@72add8: 8> #<Object$Future$IDeref@f36617: 9>)
18:16clojurebot"Elapsed time: 0.474 msecs"
18:16slashus3oh
18:17slashus3Why does that take 5 seconds on my machine to print out?
18:17kefkaYou don't get a useful time unless you time something that requires derefing it.
18:18kefkaOtherwise, it returns immediately though computation is still going on, so your quoted time is short.
18:18kefkae.g. this:
18:18kefka,(time (apply + (map deref (into [] (map #(future (Thread/sleep (* 100 %)) %) (range 10))))))
18:18clojurebot45
18:18clojurebot"Elapsed time: 910.095 msecs"
18:18slashus3kefka: On my machine it takes about 5 seconds
18:18kefkaThe one I did?
18:18slashus3The one I posted.
18:19kefkaYeah, it seems the work-around is to put the futures into a vector and then map deref across that vector
18:19slashus3When I do reduce + and map deref to it it takes 10 seconds.
18:19slashus3So that is correct.
18:19kefkaTry the one I just did. Tell me what you get.
18:19slashus3same
18:19slashus3920
18:20kefkaI get 910.
18:20kefkaYeah, so what's happening is that if you don't force the futures by doing something with the map-- the (into [] %) works-- you don't get the futures to go off immediately.
18:20slashus3Wonder why it is 5 seconds. I don't see where that is coming from on mine.
18:21kefkaIt's because map is lazy.
18:21kefkaSo the futures don't start running until the last one has returned.
18:21kefkaIt's not actually a bug, I don't think, since map is supposed to return something lazy
18:21hiredmanclojurebot: map?
18:21clojurebotmap is *LAZY*
18:22slashus3So that time is inaccurate.
18:22slashus3because of the laziness
18:23kefkaYes, but it still takes 4.5 seconds if you don't force the futures to start immediately.
18:23kefka,(map #(future (Thread/sleep (* 100 %)) %) (range 10)) ;; takes 4.5 seconds
18:23clojurebot(#<Object$Future$IDeref@14563d4: 0> #<Object$Future$IDeref@9d10ab: 1> #<Object$Future$IDeref@1b18970: 2> #<Object$Future$IDeref@b6481e: 3> #<Object$Future$IDeref@138c394: 4> #<Object$Future$IDeref@1b0595c: 5> #<Object$Future$IDeref@bac49a: 6> #<Object$Future$IDeref@1c1902d: 7> #<Object$Future$IDeref@e09a07: 8> #<Object$Future$IDeref@1a07a6f: 9>)
18:23hiredmancalling it inaccurate because it does exactly what the docstrings say it does?
18:24slashus3It is accurate. Just confusing.
18:24slashus3laziness is hard
18:24hiredmanclojurebot: lazy?
18:24kefka,(into [] (map #(future (Thread/sleep (* 100 %) %)) (range 10))) ;; takes ~0.9 seconds
18:24clojurebotlazy is hard
18:24clojurebot[#<Object$Future$IDeref@d547f8: nil> #<Object$Future$IDeref@67fb9f: nil> #<Object$Future$IDeref@1c48403: nil> #<Object$Future$IDeref@b6e2e3: nil> #<Object$Future$IDeref@e9d39c: nil> #<Object$Future$IDeref@143b598: nil> #<Object$Future$IDeref@472c8d: nil> #<Object$Future$IDeref@be0b48: nil> #<Object$Future$IDeref@d6e0df: nil> #<Object$Future$IDeref@1456c99: nil>]
18:24hiredmankefka: generally, to force a lazy-seq people use dorun or doall
18:25hiredman,(doc dorun)
18:25clojurebot"([coll] [n coll]); When lazy sequences are produced via functions that have side effects, any effects other than those needed to produce the first element in the seq do not occur until the seq is consumed. dorun can be used to force any effects. Walks through the successive nexts of the seq, does not retain the head and returns nil."
18:25kefka,(doc doall)
18:25clojurebot"([coll] [n coll]); When lazy sequences are produced via functions that have side effects, any effects other than those needed to produce the first element in the seq do not occur until the seq is consumed. doall can be used to force any effects. Walks through the successive nexts of the seq, retains the head and returns it, thus causing the entire seq to reside in memory at one time."
18:26slashus3doall is appropriate in this case?
18:26hiredmanit depends
18:30hiredmanthis case is just some code that does nothing
18:30hiredmanso dorun would be fine
18:30slashus3If you want to add up all of the numbers returned you would use doall?
18:31hiredmanor just use reduce
18:31slashus3yeah
18:32hiredmanugh, I keep expecting excel to close my parens for me
18:32slashus3hehe
19:04duderdoHello.
19:05duderdoQuick question. Why does "(let [x #{}] (conj x "foo") x)" return #{}?
19:05Chousukebecause it returns x, and x is #{}
19:06duderdoHow do I add "foo" to x then?
19:06Chousukewith conj, but that will no longer be named x
19:06Chousukeclojure has no variables, just names :), in the let binding you declare "x" to be #{}, and that it will be until later rebound in a let.
19:07Chousukethe key word here is immutability.
19:07duderdoSorry, I'm coming from CL :)
19:07duderdoSo if I have a collection and I want to add items to it what do I use?
19:07duderdoAnd yes I will read up on clojure immutabiliy ;)
19:08Chousukeyou don't add items to a collection. You return a new collection with the item added :)
19:09dnolen,(let [x #{}] (conj x 'a))
19:09clojurebot#{a}
19:09Chousukelike that.
19:09Chousukenote, however, that x still remains #{} :)
19:10duderdoRight...
19:10duderdoI need to read more I guess
19:10Chousuke,(let [x #{}, y (conj "foo" x)] (= x y))
19:10clojurebotjava.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IPersistentCollection
19:10Chousukeoops
19:10Chousuke,(let [x #{}, y (conj x "foo")] (= x y))
19:10clojurebotfalse
19:11duderdoI understand it doesn't work but I don't see why yet
19:11Chousukeit starts making sense if you stop thinking of the names you see in code as variables.
19:11dnolenduderdo: x is immutable, you can't change it.
19:12Chousukethey're simply *names*, given to some value.
19:12Chousukelike in maths, x := 3
19:13Chousukenow x = 3, but you can't change the value of x in any way; you can't change "3" to be something else.
19:13duderdoI see. But if I want to modify a collection and use it later, what is the procedure? The examples I see use globals which doesn't make sense to me.
19:13Chousukeone solution is to have a ref or two.
19:14Chousukea reference is something that you *can* change. it's a method of indirection.
19:14Chousukefor example, if you define *today* to be a reference to the current date, the value of *today* will of course change over time.
19:15Chousukehowever, once you read a value from *today*, you get something like "24.03", and *that* can not be changed
19:16Chousuketeh clojure reference type allows you to do this.
19:16duderdoIt's making sense now. Thanks. I'm just use to using LET+PUSH from cl
19:16Chousukethough just for modifying a collection I wouldn't look at refs right away
19:16Chousukejust write functions that return new collections with the values added/removed/whatever.
19:17Chousukeit's fast enough :)
19:17duderdoI'll start thinking in that direction. Thanks Chousuke.
19:17ChousukeYou're welcome.
19:59cconstantineWhat is the equivalent of (reduce and ...) that works?
20:00hiredman,(reduce #(and % %2) ...)
20:00clojurebotjava.lang.Exception: Unable to resolve symbol: ... in this context
20:01hiredmanwell
20:01hiredmanthat is a literal equivilent
20:01hiredman,(doc every?)
20:01clojurebot"([pred coll]); Returns true if (pred x) is logical true for every x in coll, else false."
20:01cconstantineand is a macro... so reduce won't take it
20:01cconstantineevery!
20:01cconstantineI knew tehre was something like that... and failed at finding it in the docs
20:02hiredman,(every? identity [1 2 nil])
20:02clojurebotnil
20:02hiredman,(every? identity [1 2 3])
20:02clojurebottrue
20:03cconstantine,(every? true? (list true true true)
20:03clojurebotEOF while reading
20:03cconstantinebah
20:08durka42,(reduce #(and %1 %2) [1 2 3])
20:08clojurebot3
20:38digash`"Q: What happens when amateur does programming language? A: Phd" -- Guy Steel
20:39selloutYeah, that was a good one.
20:39sellouteven better with the context of the original answer: PHP
20:59Mecanyone know the clojurebox key commands to eval defun or region?
21:06cconstantineI'm not using clojurebox (didn't know there was one), but it's C-c C-e for me
21:07Mechmm that brings up some eval
21:08cconstantineC-c C-z opens clojure
21:08cconstantineagain... for me :)
21:08Mecthat brought up the slime-repl which for some reason isnt the actual repl evaluations go to
21:08cconstantineI followed http://riddell.us/tutorial/slime_swank/slime_swank.html
21:09Mecok let me take a look at that
21:09cconstantineoh wait... that's for my linux box...
21:10cconstantineI did this for my mac http://paulbarry.com/articles/2008/07/02/getting-started-with-clojure-and-aquamacs
21:11Mecc-x c-e executed, but it didnt go to the repl it went to that thing at the very bottom of emacs
21:13cconstantineis there a clojure menu? that might show you the shortcut
21:14Mecthere is, but no shortcuts
21:15cconstantinehmm
21:24Mecbah any thoughts on how to up the heap space size, its only taking 90meg on a 4gig system
21:25cconstantineit's a java param
21:25cconstantinehttp://hausheer.osola.com/docs/5
21:27Mecsays it can be set in the java control panel but i know i didnt see it in there when i looked
21:27Meci wouldnt know where to find the java command line in clojurebox
21:28cconstantinenot sure... search the clojurebox file a file containing "clojure.jar"?
21:29Mecah i found it
21:29Mecwould this be considered applet or application?
21:30Mecwell since application doesnt have a space for runtime param i guess applet
21:31cconstantinethat's an odd distinction to make..
21:32Mecthose are the 2 options under the java control panel
21:32cconstantineyeah
21:33banisterfiendhru bbs
21:34Mecbah i set it to 1gig and it still wont go above 90meg
21:34banisterfiendis scala better than clojure?
21:35Mecthems fightin words
21:36cconstantineMec: modifying my clojure script with the arguments in the last link I gave you worked well for me
21:37cconstantinebanisterfiend: that's an odd question to ask in #clojure... or an odd way of phrasing it
21:37gnuvince_banisterfiend: totally
21:37Meci dont know how clojurebox starts up to add it to the command line
21:38cconstantineas an aside I really hate the way java handles the heap
21:38Mechmm thats the problem, the java control panel wont keep the params i entered
21:38banisterfiendgnuvince, hey vince
21:39cconstantineat the very least a fixed number for max-heap is stupid... and 90 is way low
21:39Meclocal java programs should use all available memory, theres no reason not to
21:40cconstantineyup
21:40banisterfiendgnuvince, hey vincent im downloading an iain m. banks audiobook - in particular the newest sci fi novel: Matter, but im also downloading the Algebraist audio book too.
21:41Mecim at my whits end, java wont accept any of the changes i make
21:42cconstantineMec: Sorry I can't help more... I don't even have access to a windows box right now
21:43Mecno sweat, i shall beat java into submission
21:43cconstantineIt is the kind of thing that must be physically afraid of you.
21:55SethTisuethe whole fixed heap ceiling thing my least favorite thing about the JVM
23:20cemerick~max
23:20clojurebotmax people is 164
23:25cemerick~max
23:25clojurebotmax people is 164