#clojure logs

2009-11-01

01:11Raynes-I set the Paredit cheatsheet as my desktop background. :>
01:48notallamajust redid pointfree library with arrows. everything still works for functions, though. http://github.com/hclarke/pointfree-clojure
02:13piccolinoIs there some way to have a private binding in a namespace? There's no def-, as far as I can find.
02:18tomojpiccolino: (def #^{:private true} foo ...)
02:18piccolinoAh, OK, thanks.
02:18tomojthough, I think there is a def- or something like it in contrib
02:18tomojwell, there's defvar- in clojure.contrib.def
04:10mikem`~re-split
04:10clojurebotIt's greek to me.
04:11mikem`~def re-split
05:09gerry_(defyte Person [name age] [java.lang.Runnable] (.run [] (println (str "hello " name ))))
05:31gerry_how to make repl auto-indent on console?
05:31gerry_i'm using lrwrap
05:32tomojnot an emacs user by chance are you?
05:33gerry_tomoj: sometimes i like using console not emacs
05:34tomojpeculiar
05:34gerry_what's it
05:34clojurebotwhat is wrong with you
05:35gerry_you don't play on console?
05:36gerry_just type clj and hack in clojure,that's not bad
05:40gerry_it seems reify doc dont hooked in new branch?
05:41gerry_ (doc reify)
05:41gerry_java.lang.Exception: Unable to resolve var: reify in this context (NO_SOURCE_FILE:1)
05:43gerry_,(doc reify)
05:43clojurebotPardon?
05:43gerry_,(doc new)
05:43clojurebotPardon?
05:43gerry_,(+ 1 2)
05:43clojurebot3
05:44gerry_,(doc conj)
05:44clojurebot"([coll x] [coll x & xs]); conj[oin]. Returns a new collection with the xs 'added'. (conj nil item) returns (item). The 'addition' may happen at different 'places' depending on the concrete type."
05:44gerry_hmm
05:46gerry_,*clojure-version*
05:46clojurebot{:interim true, :major 1, :minor 1, :incremental 0, :qualifier "alpha"}
05:46gerry_,(doc deftype)
05:46clojurebot"clojure.contrib.types/deftype;[[type-tag constructor-name docstring? attr-map?] [type-tag constructor-name docstring? attr-map? constructor] [type-tag constructor-name docstring? attr-map? constructor deconstructor]]; Define a data type by a type tag (a namespace-qualified keyword) and a symbol naming the constructor function. Optionally, a constructor and a deconstructor function can be given as well, the defaults being
05:46hiredmanwell, reify is not a var, so you can;t have a docstring on it
05:46hiredmanreify is a special form, and I guess it hasn't been added to the special forms list
05:47hiredmanor else you would get similar output to (doc let)
05:47gerry_but, i shouldn't get error msg
05:47hiredmansure
05:48hiredmandoc by default just looks in the vars metadata
05:48hiredmanthere is no var named reify
05:48hiredmanso you get an error if you try to look at the metadata of a var that doesn't exist
05:49gerry_right
05:50hiredmanlet is actually a macro that uses the let* special form
05:50hiredman(doc let*) gets you the same error
05:50clojurebotPardon?
05:50hiredmanclojurebot: dork
05:50clojurebotGabh mo leithscéal?
05:52gerry_newnew seems support define methods which isn't interface bound?
05:53gerry_why reify not support it?
06:07spuzHow do you convert a lazy sequence to a string? At the moment when I try to print the sequence I just get clojure.lang.LazySeq@d1ee3a14
06:07spuzI've tried using (str theseq) but it doesn't seem to work...
06:08spuz,(str "Range: " (range 1 10))
06:08clojurebot"Range: clojure.lang.LazySeq@fe1f9924"
06:08gerry_,(str "range" (doall (range 1 10)))
06:08clojurebot"rangeclojure.lang.LazySeq@fe1f9924"
06:09gerry_,(println (range 1 10))
06:09clojurebot(1 2 3 4 5 6 7 8 9)
06:11spuz,(str "Range: " (with-out-str (println (range 1 10))))
06:11clojurebot"Range: (1 2 3 4 5 6 7 8 9)\n"
06:11spuzis that really the best way to do it?
06:13spuz,(str "Range: " (str (range 1 10)))
06:13clojurebot"Range: clojure.lang.LazySeq@fe1f9924"
06:15gerry_str seems using .toString method inside
06:16gerry_,(.toString (range 1 10))
06:16clojurebot"clojure.lang.LazySeq@fe1f9924"
06:16gerry_(.toString (doall (range 1 10)))
06:16gerry_,(.toString (doall (range 1 10)))
06:16clojurebot"clojure.lang.LazySeq@fe1f9924"
06:17gerry_is this a bug?
06:18spuzgerry_: I don't think so, that looks like the correct toString for a lazy seqence
06:18spuzif the sequence happened to be infinite then toString would never return
06:19gerry_then (doall lazyseq)return what?
06:19gerry_still lazyseq?
06:20spuzdoall will execute any side effects that walking the sequence may have, then it just returns the head of the seqence
06:20spuzah, I know...
06:20spuz(apply str (range 1 10))
06:20spuz,(apply str (range 1 10))
06:20clojurebot"123456789"
06:23hiredman,(pr-str (range 10))
06:23clojurebot"(0 1 2 3 4 5 6 7 8 9)"
06:23spuzor there is clojure contrib's str-join
06:23spuzbut still, a bit cumbersome to write our own to string for sequences
06:23hiredmanit's called pr-str
06:24spuzhiredman: ah thanks
06:27modulushey, i'm trying to apply a function to all the elemtns of a list in turn
06:27modulusi'm sure this must exist, just no idea how it may be called
06:27hiredman,(doc map)
06:27modulussomething like
06:27clojurebot"([f coll] [f c1 c2] [f c1 c2 c3] [f c1 c2 c3 & colls]); Returns a lazy sequence consisting of the result of applying f to the set of first items of each coll, followed by applying f to the set of second items in each coll, until any one of the colls is exhausted. Any remaining items in other colls are ignored. Function f should accept number-of-colls arguments."
06:27hiredman,(doc reduce)
06:27clojurebot"([f coll] [f val coll]); f should be a function of 2 arguments. If val is not supplied, returns the result of applying f to the first 2 items in coll, then applying f to that result and the 3rd item, etc. If coll contains no items, f must accept no arguments as well, and reduce returns the result of calling f with no arguments. If coll has only 1 item, it is returned and f is not called. If val is supplied, returns the r
06:27adityohow do i enable code-completion inside a file (using slime), its available inside the repl buffer bit not when i edit a file
06:27modulusno
06:27hiredman,(doc doseq)
06:27clojurebot"([seq-exprs & body]); Repeatedly executes body (presumably for side-effects) with bindings and filtering as provided by \"for\". Does not retain the head of the sequence. Returns nil."
06:27modulusi need something like
06:28modulus(fun + x l) where it does (+ x ...) for each item in l and returns a new l
06:28hiredman,(map (partial + 1) (range 3))
06:28clojurebot(1 2 3)
06:29modulusah, interesting
06:29modulusthx
06:29hiredmandid you read the docstrings at all?
06:29modulusyes but i think i misunderstood the doc
06:30paocan anyone help me add type tags to this micro bench? http://paste.pocoo.org/show/148086/
06:30paoI'd like to know if it is the fastest solution
06:30hiredman,(seq (reduce #(conj %1 (+ 1 %2)) [] (range 3)))
06:30clojurebot(1 2 3)
06:30modulusin fact i still don't undrestand that docstring now
06:31hiredmanit's map
06:31hiredmanhttp://en.wikipedia.org/wiki/Map_%28higher-order_function%29
06:31hiredmanit has its own wikipedia article
06:33hiredmanhmmm
06:33hiredman,((comp seq reduce) (partial (flip conj) (partial +1)) [] (range 3))
06:33clojurebotjava.lang.IllegalArgumentException: Wrong number of args passed to: core$partial
06:34hiredman,((comp seq reduce) (partial (flip conj) (partial + 1)) [] (range 3))
06:34clojurebotjava.lang.ClassCastException
06:34spuzhiredman: what exactly are you trying to do?
06:34spuzdoesn't modulus just want something like:
06:34spuz'(map #(* % %) (range 10))
06:34hiredman,((partial (flip conj) 1) [])
06:34clojurebot[1]
06:34spuz,(map #(* % %) (range 10))
06:34clojurebot(0 1 4 9 16 25 36 49 64 81)
06:35hiredmanoh
06:35hiredmannuts
06:36spuz,(doc flip)
06:36clojurebot"([x]); takes a function and returns a function that takes arguments in the opposite order"
06:37spuzflip doesn't appear to be a documented function :p
06:37modulusalso is there a function to generate set products?
06:37modulus* works only for numbers it seems
06:38spuzmodulus: take a loop at for
06:38spuzlook* :)
06:38hiredman,((partial (comp seq reduce) (comp (partial apply conj) (juxt first (comp (partial + 1) second)) list) []) (range 10))
06:38clojurebot(1 2 3 4 5 6 7 8 9 10)
06:39hiredmanflip just something that happens to be in clojurebot's sandbox at the moment
06:40hiredman,(doc flip)
06:40clojurebot"([x]); takes a function and returns a function that takes arguments in the opposite order"
06:40hiredmanand it is documented :P
06:44spuzhiredman: are you seeing how complicated you can make a function that returns (range 10)?
06:44hiredmanit's doesn't return range 10
06:44hiredman,(range 10)
06:44clojurebot(0 1 2 3 4 5 6 7 8 9)
06:44hiredman,((partial (comp seq reduce) (comp (partial apply conj) (juxt first (comp (partial + 1) second)) list) []) (range 10))
06:44clojurebot(1 2 3 4 5 6 7 8 9 10)
06:45spuz,(nth (iterate (inc %) 10)
06:45clojurebotEOF while reading
06:45spuz,(nth (iterate (inc %) 10))
06:45clojurebotjava.lang.Exception: Unable to resolve symbol: % in this context
06:45spuz> ,(nth (iterate #(inc %) 10))
06:46spuzdoh :(
06:46hiredmanno
06:46hiredman(iterate inc 0) is what you want there
06:46hiredmanand you want take, not nth
06:47spuz(take 10 (iterate inc 1))
06:47spuzthat's what I meant
06:47paohmmm... I guess #^double type annotation doesn't work with clojure 1.0.0... where do I download a more recent one?
06:47hiredmanyes, but that doesn't add one to every element in a list
06:48hiredmanwhich is what modulus asked about
06:48spuzwell, map + range then
06:49spuzpao: I'm pretty sure 1.0.0 supports #^double
06:49hiredman,((partial map (partial + 1)) (range 10)
06:49clojurebotEOF while reading
06:49hiredman,((partial map (partial + 1)) (range 10))
06:49clojurebot(1 2 3 4 5 6 7 8 9 10)
06:49spuzI'm not sure why you need the partials...
06:50hiredmanyou don't, but it makes a nice pointfree function
06:50hiredmanwhich is what I also did with the reduce version
06:50hiredman,((partial (comp seq reduce) (comp (partial apply conj) (juxt first (comp (partial + 1) second)) list) []) (range 10))
06:50clojurebot(1 2 3 4 5 6 7 8 9 10)
06:51paosputz I get: IllegalArgumentException: Unable to resolve classname: double (test.clj:10)
06:51hiredmanyou don't type hint primitives like that
06:51hiredman(double x)
06:52hiredmanin a let
06:52hiredman~performance
06:52clojurebothttp://clojure.org/java_interop#toc46
06:52spuzAh yes, it's #^doubles not #^double
06:52spuzand yeah, use coersion to force the use of primitives
06:53paohiredman: thanks
06:53paospuz: thanks
06:53Licenser(,doc =not)
06:53Licenser,(doc =not)
06:53clojurebotTitim gan éirí ort.
06:53hiredmannot=
06:53spuz,(doc not=)
06:53clojurebot"([x] [x y] [x y & more]); Same as (not (= obj1 obj2))"
06:54hiredmanor (comp not =)
06:54Licenserspuz: thank you
06:54LicenserI always want to use !=
06:54spuzheh ditto :)
06:55_atoLicenser: then (def != not=) and use it :)
06:55Licenseryes I know but that's against the law
06:55_atohaha
06:55hiredman,((complement =) 1 2)
06:55clojurebottrue
06:56modulusok many thx, map and for work for what i was trying to do
06:57spuzmodulus: cool
06:58modulushow could you use the map without the partial though?
06:58modulusi guess you could do
06:58hiredmanhowever you want
06:58hiredmanit just takes a function
06:58modulus,(map (inc 1) (list 1 2 3 4 5))
06:58clojurebotjava.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn
06:58modulusmaybe not
06:58hiredmananonymous or named
06:58_ato,(map inc (list 1 2 3))
06:58clojurebot(2 3 4)
06:59hiredman,(map #(+ 1 %) (range 10))
06:59clojurebot(1 2 3 4 5 6 7 8 9 10)
06:59_ato,(map (fn [_] 2) (list 1 2 3))
06:59clojurebot(2 2 2)
07:00modulushmm, isn't using the anon function same thing as partial?
07:00hiredmanpartial just creates a new function
07:00hiredmansimilar
07:00hiredmanmore or less, but partial is a nice higher order function
07:00hiredmanyou get can use it to get nice pointfree functions
07:01gbthiredman: I'm new to clojure and functional programming. Are pointfree functions a good thing to learn? You seem to use them a lot :)
07:01hiredmanwithout having to think up pesky variable names
07:01Chousukegbt: it depends :P
07:01gbthehe
07:01hiredmanI just hate having to name variables
07:01Chousukethey're not as nice in clojure as they are in haskell
07:02gbtit was a haskell example I was looking at, but I don't know haskell so its tough going ;)
07:03modulussomehow this sequence things seem a bit odd
07:03Chousukewell, in haskell composition is just f . g and partial is just (f arg1) (if f takes 2 arguments)
07:03Chousukeso it's much more compach
07:03hiredman,(pl (inc · dec 1))
07:03clojurebot1
07:03Chousukecompact :P
07:04_ato,(doc pl)
07:04clojurebot"([& forms]); replaces a $ b with (a b) walking right to left replaces a · b with (comp a b) left to right ⌽a with (uncurry a) left to right ↕a with (flip a) left to right"
07:04hiredmanpl is another thing that just happens to be loaded in clojurebot's namespace
07:04Chousukeyou won't find it anywhere else :D
07:05gbtI'm enjoying the functional side, (coming from c languages) but I still haven't had the eureka moment were I really get it
07:05hiredman,(pl (↕map range $ 10 (call · ⌽+ 1)))
07:05clojurebotjava.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn
07:05hiredman,(pl (↕map range $ 10 (call · (⌽+ 1))))
07:05clojurebotjava.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn
07:05hiredmanbah
07:06paoChousuke: Hi! would you mind giving a look to http://paste.pocoo.org/show/148088/ ? is that the fastest that I can get?
07:07spuzgbt: I don't think there's a moment exactly, but the more you learn about higher order functions the more and more things you realise you can do that you couldn't do in C
07:08Chousukepao: probably not.
07:08hiredman,(pl (↕map range $ 10 call · ⌽+ $ 1))
07:08clojurebot(1 2 3 4 5 6 7 8 9 10)
07:08Chousukepao: handwritten loops are usually faster than lazy seqs
07:09paoChousuke: good I'll try to rewrite with loop
07:09moduluslazy seqs are confusing as hell
07:09tomoj:)
07:09hiredmanmodulus: how so?
07:09Chousukemodulus: only sometimes :)
07:09modulushehe
07:09_ato,(pl (quote pl $ pl))
07:09clojurebot(pl pl)
07:09moduluswell, i've been reading a few docs and i find it hard to remember what the deal is with keeping the head or not etc
07:10_ato,(pl pl ? pl)
07:10clojurebotjava.lang.Exception: Can't take value of a macro: #'sandbox/pl
07:10modulusand when things may not get printed
07:10spuzmodulus: they are just like iterators in java... cursors in SQL, or perhaps you're more familiar with streams...?
07:10modulushmm
07:10paoI'm little bit puzzled ... :-( standard naive python implemetation for that micro-bench is 3 times faster than clojure and 2 times faster than haskell ... I'm desperately trying to get rid of python without success :-)
07:11modulusstrange, python being fast
07:11_atomaybe python has a faster rand?
07:11paomodulus: I was expecting it as well
07:12hiredmanpao: how are you timing it?
07:12paohiredman: with unix time
07:12hiredman*snort*
07:12hiredmanthe jvm takes at least 30 seconds to start
07:13paohiredman: to trigger jit?
07:13_atopao: try: (time (dorun ...))
07:13Chousukepao: no. just to start.
07:13Chousukepao: are you timing both the creation of the array and the summing?
07:13paoChousuke: yep
07:14paohiredman: python runtime isn't fast to startup either
07:14Chousukeit's a lot faster than the JVM.
07:14hiredmanpao: I doubt it takes as long as the jvm
07:14hiredmanthe jvm loads a ton of stuff at start up
07:14pao"Elapsed time: 36836.235 msecs"
07:14paoreal 0m39.620s
07:14paouser 0m56.235s
07:14paosys 0m2.357s
07:15paothe startup was 3 seconds approximately
07:15mikem`what's the clojure way to store data strucutures in a file for future use?
07:15hiredmanprn
07:15paopython:
07:15paoreal 0m14.617s
07:15paouser 0m13.793s
07:15paosys 0m0.477s
07:16Chousukeyou're using a lot of lazines... that will slow you down.
07:16hiredmansure
07:16Chousukelaziness*
07:16Chousukealso try mapping into a vector instead of an array
07:17paoChousuke: I've already tried with vectors and it is _ways_ slower
07:17Chousukeyou're using 1.0.0 still?
07:17paoChousuke: I get the problem is that vector put a lot of pressure on gc
07:17paoChousuke: yep
07:17_atopao: just out of curiosity can you pastebin your Python version?
07:17hiredmanyou are generating at least 6 seqs
07:17Chousukeright. no wonder :)
07:17vu3rddHello folks. I am a clojure newbie and am trying to setup slime/swank on debian.
07:17modulussomething wrong with 1.0?
07:17paoChousuke: should I try what?
07:17Chousukewell, not really.
07:17Chousukegit master is just faster .P
07:18hiredmanpao: uh, I would seriously doubt that
07:18vu3rddI am using the instructions at <http://riddell.us/tutorial/slime_swank/slime_swank.html&gt;
07:18hiredmanpao: that this code would put pressure on the gc
07:18pao_ato: http://paste.pocoo.org/show/148089/
07:19vu3rddI followed and setup slime and get the prompt in the slime-repl buffer
07:19mikem`hiredman: ok, so prn prints the data structure... how to get it back?
07:19vu3rddbut if I say (+ 2 2), it hangs.
07:19paohiredman: whith array the heap required is exactly 80Mb
07:19_atomikem`: (read some-string)
07:19vu3rddOTOH, the inferior-lisp buffer works fine
07:19_ato,(read "[1 2 3]")
07:19clojurebotjava.lang.ClassCastException: java.lang.String cannot be cast to java.io.PushbackReader
07:19vu3rddany idea what could be the problem?
07:19_atogah
07:19paohiredman: vector requires much more
07:20_atooh that's right you need to pass it a reader
07:20gbtvu3rdd: I'm new too, I used epla and clojure-mode. did anything for me
07:20paoI could try to estimate the exact heap size required with vec
07:20hiredmanpao: have you tried using vectors?
07:20vu3rddgbt: I setup according to the instructions on an Ubuntu machine, just fine.
07:20paohiredman: yep
07:20paohiredman: let me try again
07:20_ato,(read-string "[1 2 3]")
07:20clojurebot[1 2 3]
07:20vu3rddI am trying to set it up on a debian machine, which is my primary machine at home
07:21mikem`_ato: great, thanks :)
07:21vu3rddbut it is refusing to give the result back into the repl buffer
07:21vu3rddsbcl works just fine
07:22_atovu3rdd: strange. Is it printing anything in the *inferior-lisp* buffer?
07:22Chousukehmm, I got 30 seconds using vectors
07:23paoChousuke: how much using arrays?
07:23vu3rdd_ato: no. it doesn't. It just says "Connection opened on local port 48662"
07:23vu3rddand also gives "#<ServerSocket ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=48662]>"
07:24vu3rddI am able to type on the *inferior-lisp* buffer and get the results just fine
07:25Chousukepao: didn't try yet.
07:25vu3rddis there any way to turn on some debugging messages on swank/slime?
07:25Chousuke30 seconds with only lazy seqs, too (vectors a bit slower)
07:25paoChousuke: java.lang.OutOfMemoryError: Java heap space with -Xmx 200m
07:26ChousukeI have git clojure
07:26paoChousuke: that was with replacing #(into-array Double/TYPE) with vec
07:26Chousukeso (vec huge-thing) doesn't actually create as many vectors as huge-thing has items
07:26paoChousuke: I'll try with head (is there a particulare branch you would suggest)
07:27Chousukejust master
07:27paoChousuke: could you elaborate on (vec huge-thing)?
07:28_atovu3rdd: ah... that sounds familiar. At one point I was having issues like that and it was that the version of SLIME I was using was not compatible with the version of swank
07:28Chousukepao: it uses transients internally
07:28Chousukepao: with the array I got almost exactly the same result as with vectors
07:29paoChousuke: are you saying that (vec huge-thing) is master is faster thatn in 1.0.0 beacouse of transients?
07:29Chousukeit's just 19ms faster
07:29Chousukeyes.
07:29paoChousuke: I'll try master
07:29vu3rdd_ato: My slime and swank are from the git repos
07:29hiredmanlisppaste8: url?
07:29lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
07:30_atovu3rdd: yeah, when I had that issue SLIME was too new, clojure swank hadn't been updated
07:30lisppaste8hiredman pasted "untitled" at http://paste.lisp.org/display/89637
07:30_atovu3rdd: I don't know whether that's still the case, that was a couple of months ago though, you might be having a different issue
07:30Chousukebecause what it actually does is create an editable version of an empty vector, then mutably stuff things into that, and then finally it transforms the editable thing into a persistent one again and returns it
07:30hiredmanpao: I don't know python but I think that is an accurate transliteration of your code
07:31_atovu3rdd: http://www.mail-archive.com/clojure@googlegroups.com/msg05284.html
07:31hiredmanwhoops
07:31hiredmanextra prn in the first doseq
07:32Chousukearen't the fors the wrong way around?
07:32paohiredman: yep, it is... would you consider it idiomatic? ... I'm going to time it...
07:33Chousukeit's creating a 100000 small vecs instead of a 100 large vecs.
07:33vu3rdd_ato: Ok. thanks for the tip
07:34vu3rdd_ato: I removed the slime debian package from my machine. That seem to have solved the issue.
07:34_atoah cool. :)
07:34vu3rdd_ato: Thanks a lot.
07:34hiredmanpao: depends, I don't use for a lot
07:35patricius_Hi. I am making a toy-disk scheduler in Clojure. Imagine that we have a lot of processes that want to access certain cylinders on a disk. Any such request for access goes through a disk scheduler, and the processes has to block when they have made a request until the disk scheduler allows the process to access the cylinder. The scheduler runs over batches of requests; it starts by sorting the requests currently waiting, and th
07:35patricius_letting the processes gain access in the sorted order. My question is how to get processes to block until they receive access to a cylinder?
07:35hiredmanfor is a fairly hairy macro
07:36hiredmanpatricius_: don't block, use refs and the stm
07:36hiredman:P
07:37patricius_hiredman: i guess you are right
07:37hiredmanthere are many ways you can block
07:37hiredmancall .take on an empty blockingqueue
07:38hiredmanderef a future or a promise
07:38hiredmanawait an agent
07:38patricius_hiredman: thanks, i didn't know about blockingqueue and promises
07:38patricius_i'll look into those
07:38hiredmanBlockingQueue from j.u.concurrent
07:39hiredmanyou could implement your own executor service per cylinder
07:39patricius_hiredman: thanks
07:40patricius_hiredman: yeah... but it goes against the problem definition. On the other hand, I'm trying to demonstrate Clojure's concurrency features through the disk scheduler example, and maybe the problem definition shouldn't be taken literally in that case.
07:40patricius_the problem definition is worded in a traditional "threads-and-locks-way"
07:41hiredmanwhy not? it would be a sort of grand central dispatch approach
07:41hiredmaneach cylinder has a queue of jobs waiting on it
07:41patricius_hiredman: you are suggesting that I have a service per cylinder?
07:41hiredmansure
07:42patricius_hmm.... let me think a little
07:42hiredmanthey could all use the same threadpool
07:42hiredmanactually, hey, you can just use agents
07:43_atopao: http://gist.github.com/223515
07:43_atoabout the same speed as python on my PC
07:43patricius_hiredman: yeah, you're thinking since the actions sent to agents are waiting in a queue to be executed
07:43_atoassuming I haven't broken the benchmark
07:43hiredmanpatricius_: correct
07:44pao_ato: thanks ... are you using 1.0.0 or master?
07:44patricius_hiredman: my original plan was to also represent processes as agents, but I still don't know how to have them "block" and wait for cylinder access
07:44Chousuke_ato: I get similar results. though my JVM runs out of memory with 100k arrays
07:44patricius_hiredman: originally i had "processes" pass a long a function (closure) that should be called when access was given
07:44Chousukebut I get about a tenth of that with 10k
07:44hiredmanpatricius_: you can use promise/deliver
07:45_atopao: master
07:45patricius_hiredman: i'll read about them right now
07:45Chousuke_ato: what happens if you remove the vec call?
07:45patricius_hiredman: are these concurrency primitives part of clojure?
07:45hiredman(let [result (promise)] (send-off cyl1 (fn [cyl] (deliver result (read-date cyl)))) @result)
07:45patricius_hiredman: or java?
07:45hiredmanpatricius_: yes
07:46hiredman,(doc promise)
07:46clojurebot"([]); Experimental. Returns a promise object that can be read with deref/@, and set, once only, with deliver. Calls to deref/@ prior to delivery will block. All subsequent derefs will return the same delivered value without blocking."
07:46Chousuke,(ancestors (promise))
07:46clojurebotnil
07:46hiredmanpatricius_: whats the difference
07:46hiredman,(ancestors (class (promise)))
07:46clojurebot#{clojure.lang.IFn java.io.Serializable java.lang.Object clojure.lang.IProxy clojure.lang.AFn clojure.lang.IMeta clojure.lang.IDeref java.util.concurrent.Callable clojure.lang.IObj :clojure.contrib.generic/any clojure.lang.Obj java.lang.Runnable}
07:46patricius_hiredman: just where to look for documentation
07:46Chousukeright. :)
07:47hiredmanhuh
07:47hiredmanpromises are IFns?
07:47hiredman~def promise
07:47patricius_ahr... thanks - excuse me, but I'm very new to clojure
07:48hiredmanneat
07:48Chousuke,(let [x (promise)] (deliver x inc) (x 2))
07:48clojurebotjava.lang.IllegalStateException: Multiple deliver calls to a promise
07:48Chousukeoh, heh
07:48Chousukeso it was deliver instead of forwarding
07:48patricius_i guess its not part of clojure 1.0 then?
07:48paoChousuke: without vec you you get a list instead of a vec at the end, right?
07:49Chousukepao: well, a lazy seq, but yes.
07:49hiredmanoh, was promise post 1.0?
07:49Chousuke,(let [x (promise)] (x 2) @x)
07:49clojurebot2
07:49patricius_i can't find any documentation for it, so I guess it's not official or whatever yet
07:50pao_ato: with 1.0.0 and s/vec/into-array Double/TYPE
07:50pao"Elapsed time: 22362.154 msecs"
07:50paoreal 0m24.406s
07:50paouser 0m34.712s
07:50paosys 0m4.364s
07:50paopython was
07:50paoreal 0m15.487s
07:50paouser 0m14.121s
07:50paosys 0m0.509s
07:50paogood
07:50paoI'll try master
07:50Chousukepao: try removing the (into-array ...) entirely
07:51Chousukeie. just let it be a lazy seq
07:51paoChousuke: but the lazy-seq gets progressively reified into a list, right?
07:51hiredmanpao: and what's the time on an already running vm?
07:51Chousukeyes.
07:52Chousukepao: but I don't see the point in actually putting those things in arrays in your benchmark :)
07:52Chousukeunless you want to test array creation
07:53paoChousuke: what I want to "bench-mark" is "immutable double array" memory efficiency and naive processing
07:53hiredmanwell
07:53hiredmanarrays are not immutable
07:54Chousukepao: hm
07:54paohiredman: the double quotes were for that reason ... I don't really care about the underlying rapresentation... unless is memory and access efficient
07:54_atohmm got it down to four seconds, by making the inner loop eager instead of lazy and explicitly using transients
07:54paoChousuke: with lazy seq (without vec) -> OutOfMemoryError ... got to compile master...
07:55pao_ato: ! :-)
07:55modulushmm gtg
07:55pao_ato: would you mind pasting it?
07:55_atopao: http://gist.github.com/223515
07:55Chousuke_ato: so basically the creation of the arrays were the bottleneck, not the reduce
07:56_atoChousuke: I think all the temporary seqs
07:56_atoprobably driving the GC crazy
07:57pao_ato: can you confirm that with this implementation vectors are not collected as soon as they are reduced?
07:58hiredmanuh
07:58Chousukepao: nothing is ever collected because you (def ...) them :P
07:58Chousukepao: there's a reference to the vectors so they can't be collected.
07:59Chousukeif you want collectable vectors, you need to make a function that generates the vectors (and sums) and call it like (map (partial reduce +) (sums (make-vectors))
08:00Chousukeer, wait. got confused :P
08:00paoChousuke: good... I didn't want them to be collected
08:00hiredmanbetter to use locals
08:01Licenser20% of the time seem to be the print too - at least for me
08:01hiredmanIO is slow
08:01LicenserI know especially when run in netbeans :P
08:02Licenserso I feel my system sucks, I get 10s even without print :.(
08:54paoChousuke: are you a clojure committer?
08:59hiredmanI am pretty sure Chousuke is atleast a contrib commiter
09:03paothanks hiredman
09:03paoClojure 1.1.0-alpha-SNAPSHOT
09:03paouser=>
09:04paothat should be it
09:11paowack ... master is definitely speedy
09:12paovec are only slightly slower than unboxed arrays
09:18avitalHello. Is anyone here comfortable with monads both in Clojure and in Haskell? I am trying to learn Haskell for the first time (specifically monads) by comparing it to the monads library in clojure-contrib. I can't figure out how you tell a do statement in Haskell which monad to use (in Clojure domonad takes a monad as a first argument).
09:19paoavital: in haskell the monad is inferred ... is there is no context the expression is polymorphic
09:19pao*if
09:20paoavital: in other term the expression "return 1", if not given any more context, is parametric in the type of monad
09:20avitalInteresting... I'm trying to compare the efficiency of monads in Clojure and Haskell so I'm just trying to write some sample code in Haskell. How would I write something using the Maybe monad, for example? Or the state monad? (The online haskell monad tutorials aren't helping me well enough...)
09:20paoPrelude> :t return 1
09:20paoreturn 1 :: (Num t, Monad m) => m t
09:21paoavital: I can help you out
09:21paojust tell me what you want to achive
09:21avitalGreat!
09:21paoin general the monad should be "enforced" somehow...
09:21paoor by explicit type annotation
09:22paoPrelude> :t (return 1) :: Maybe Int
09:22pao(return 1) :: Maybe Int :: Maybe Int
09:22avitalI'm trying to write something equivalent to (domonad writer-t [a (m-result 3) _ (write "Hello") b (m-result (* a a))] b)
09:22paoor by "running" it
09:24paolet me try do "decode" the clojure syntax :-)
09:24paojust a second
09:27avitalsorry, my example is broken
09:27avitallet me write a working one
09:27paoyep
09:28avital(domonad (writer-m empty-vector) [a (m-result 2) _ (write "hello") b (m-result 3) _ (write "also") c (m-result (+ a b))] c)
09:29avitalI may not be using the clojure-contrib monads library properly with my calls to m-result all the time..
09:30paoyou get a vec of string in the writer?
09:31avitalwrite-m receives an empty accumulator and returns a monad whose monadic values are vectors like [result ["first-string-written" "second-string-written"]]...
09:31paoavital: yep
09:31paoI know :-)
09:32avitalso sorry what was the question?
09:32paorun the monad pls ...
09:32paoand give me the result
09:32avital[5 ["hello" "also"]]
09:32paoperfect
09:33pao*Main> main
09:33paoLoading package syb ... linking ... done.
09:33paoLoading package base-3.0.3.1 ... linking ... done.
09:33paoLoading package mtl-1.1.0.2 ... linking ... done.
09:33pao(5,["Hello","also"])
09:33paohttp://paste.pocoo.org/show/148104/
09:33paothat's the exact transliteration of you
09:34pao*of your code
09:34avitalthanks! how much do i owe you?
09:34avital:)
09:34paosome helps with monads in clojure when I will need :-)
09:35avitalhehe sure.
09:35avital!
09:35paoplease note the te last two lines in the do are redundant
09:36paoreturn (a+b) >>= return is equivalent to return (a+b)
09:36avitalyou mean c <- return (a + b); return c; instead of just return (a+b)?
09:36avitalAha yeah./
09:36paothat holds also for clojure code
09:36avitalof course
09:37patricius_I may be a complete idiot, but why does the following block?: (dosync (alter (ref []) conj (promise)))
09:38hiredmanthe printing blocks
09:38patricius_hiredman: what do you mean?
09:38hiredmandosync returns the last expression, like do, and alter returns the new value of the ref
09:39patricius_arch!
09:39patricius_(that was a guttural sound)
09:39hiredmanso the value of that expression is [(promise)]
09:39patricius_hiredman: thanks again man
09:39hiredmana promise is an IDeref, and by default when the repl prints an IDeref it derefs it
09:40paoavital: does the contrib library also supports monad transformers?
09:40avitalpao: Yes, but I haven't gotten an example using transformers to work yet - documentation is scarce and example are almost non-existant.
09:41paoavital: I would suggest trying with StateT s [] a
09:41avitalpao: What? :)
09:41paoa list monad wrapper by a state-t transformer
09:42avitalAha. I'll try that.
09:43avitalAlso, I'm trying to compile your code with ghc but it can't find Control.Monad.Writer
09:43avitalGiven that I this is my first try with Haskell,
09:43avitalwhat do I have to do? ...
09:44paohmmm ... in theory nothing
09:44paohow do you installed ghc? os?
09:45avitalsynaptic on linux
09:50paoavital: search for mtl
09:50clojurebotfor is not a loop
09:51avitalpao: ok cool thanks
09:51paoavital: # dpkg -l |grep mtl
09:51paoii libghc6-mtl-dev
09:51paothen compile with
09:51paoghc --make test.hs
09:52paohow do "clojure friendly" profile the jvm heap ?
09:52paoany suggestion?
09:52avitalgrea thanks!
09:52avitalgreat
09:54avitalnever done that... i don't think there are any specialized tools other than standard jvm profilers...
09:54paoavital: as a standard heap profiler what would you suggest? I'm very new to jvm world...
09:54avitalhttp://clojure.org/getting_started#toc6
09:55avitalThere is also a built-in one that comes with the Sun JDK I think
09:55paoavital: great, thanks
09:55avitalbut it's been a long time since I've used that
10:00avitalpao: Is there an easy way in Haskell to time how long it takes to run something 10000000 times, for example? [In clojure it's (time (dotimes [_ 1000000] (f)))]
10:01paothere the timeit package
10:01pao*there is
10:01paobut you should install the haskell platform to install the package
10:04avitalhttp://stackoverflow.com/questions/1516808/writing-a-time-function-in-haskell
10:07paoavital: it's not so "trivial" to write micro bench in haskell... becouse _everything_ is by default lazy there... (also * or conj for example)... and it's not so trivial to force evaluation deep enough
10:08paoavital: my personal experience is that idiomatic haskell is as fast as a good interpreted language (python is the example that I closely know)
10:08paoavital: optimizing haskell is quite tricky and you generally loose its amazing elegance
10:10notallamai thought haskell was generally pretty close to c++/java speed. or is that only if you do tricky stuff?
10:10paoavital: I wouldn't choose haskell for performance
10:10avitalI'm trying to check it
10:10paonotallama: I would definitely say yes
10:15paonotallama: http://www.opensubscriber.com/message/haskell-cafe@haskell.org/2996376.html
10:15paonotallama: still relevant
10:19Chousukehiredman: nah, I'm not a committer for anything :P Chouser is
10:22paoChousuke: that is what misled me
10:22pao:-)
11:13churibcan anybody give some quick help? the following gives me a reflection warning: (defn int-log10 [x] (.intValue #^Double (/ (Math/log x) (Math/log 10))))
11:15churibMath.log returns a double...
11:23ambientand it takes a double
11:23ambient,(class 10)
11:23clojurebotjava.lang.Integer
11:27churibsame with (.intValue #^Double (Math/log Math/E))
11:28ambient,(class Math/E)
11:28clojurebotjava.lang.Double
11:28ambienttry (int (Math/log (double Math/E))
11:30churib(int ..) cuts the decimal places, i want something that returns 1 when 0.99 is given
11:30ambientMath/round
11:32churibthat works, thanks!
11:59slashus2, (str "Range: " (seq (range 1 10)))
11:59clojurebot"Range: (1 2 3 4 5 6 7 8 9)"
12:13yasonDoes contains? compare value or identity?
12:15yasonI'm wondering why this doesn't work:
12:15yason,(let [x (list (list))] (contains? x (first x)))
12:15clojurebotfalse
12:15yasonsame with a list of structs (maps)
12:16Chousuke~contains?
12:16clojurebotcontains? is for checking whether a collection has a value for a given key. If you want to find out whether a value exists in a Collection (in linear time!), use the java method .contains
12:17yasonuh, no wonder I didn't find it :)
12:18ChousukeThis is one of the most frequently asked questions :P
12:19yasonHow about wrapping .contains into a (has? coll value)
12:19yasonjava interop is nice but primitive coll/seq stuff ought to be lispy
12:20Chousukewell, you could just use (some #{value} coll)
12:22yason,(let [x (list (list))] (some #{(first x)} x))
12:22clojurebot()
12:23yason,(let [x (list (list))] (every? #{(first x)} x))
12:23clojurebottrue
12:24Chousukeboth answers are boolean true :)
12:24Chousukesome returns the first item that matches the predicate and is not nil or false
12:25yasonOh, right
12:25yasonI'm so used to () being equal to nil.
12:27raek,(nil? ())
12:27clojurebotfalse
12:27raek,(nil? (seq ()))
12:27clojurebottrue
12:35adityo~max people
12:35clojurebotmax people is 187
12:43spuzslashus2: So that's another way to convert a sequence to a string?
12:44spuzIf (range) returns a sequence, then what exactly is does seq on a range do?
12:45spuz,(str "Range: " (range 10))
12:45clojurebot"Range: clojure.lang.LazySeq@9ebadac6"
12:45spuz,(str "Range: " (seq (range 10)))
12:45clojurebot"Range: (0 1 2 3 4 5 6 7 8 9)"
12:45spuz(class (seq (range 10)))
12:45spuz,(class (seq (range 10)))
12:45clojurebotclojure.lang.ChunkedCons
12:46spuzhmm....
12:47spuz,(class (range 10))
12:47clojurebotclojure.lang.LazySeq
13:07chouser,(range 0)
13:07clojurebot()
13:07chouser,(seq (range 0))
13:07clojurebotnil
13:40danlarkingiven a map with keys :a, :b, :c and :d, is there a function that returns a map with only the keys (and their values) I specify and everything else dissoc'ed?
13:40danlarkinmaking sure I'm not missing the idiomatic function
13:41arbscht,(doc select-keys)
13:41clojurebot"([map keyseq]); Returns a map containing only those entries in map whose key is in keys"
13:41danlarkinthere it is!
13:42danlarkinarbscht: thanks
15:57chouserhuh. ruby has rational numbers.
15:59djorkthey're not that easy though
16:00djork,(println "Not like " (/ 1 2))
16:00clojurebotNot like 1/2
16:00chouserno. They have this handy Rational(1, 2) syntax.
16:00ambient,(/ (/ 1 2) (/ 3 7))
16:00clojurebot7/6
16:00djorkoh, even better
16:01djork,1/2
16:01clojurebot1/2
16:01ambient,(sqrt -1)
16:01clojurebotjava.lang.Exception: Unable to resolve symbol: sqrt in this context
16:01chouserruby: 4/5 ==> 0 ; whee!
16:01djork,(Math/sqrt -1)
16:01clojurebotNaN
16:02djorkyeah it's kind of annoying to have to deal with that in ruby
16:02ambientwould be nice if the answer was i :)
16:02ambientalthough complex numbers aren't used that often
16:02moduluscommon lisp has a nice syntax for complex
16:02modulus#c(a,b)
16:03moduluswhere the number is a+bi
16:03djorktoo bad we can't make new reader dispatch macros :)
16:03ambientwe can, if we fork the source :2
16:03MakoryuOnIcePester rhickey for something
16:04MakoryuOnIce,1+1
16:04clojurebotInvalid number: 1+1
16:04MakoryuOnIce,2i
16:04clojurebotInvalid number: 2i
17:29technomancysweet; Clojure is the #1 most-watched Java project on Github: http://github.com/languages/Java
17:31dublindannice
17:33technomancywould any ant pros be able to translate something for me?
17:34technomancywondering what the "mapper" element in this example means in code: http://maven.apache.org/ant-tasks/examples/dependencies.html
17:37technomancynever mind; found it
18:09krumholthi i have a java class MyClass containing a public enum MyEnum {Foo, Bar}; how can i get an objet from this enumeration in clojure? In java i would do MyClass.MyEnum.Foo
18:11_atohmm.. possible MyClass$MyEnum/Foo, that's what you'd do for an inner class
18:13hiredmanclojurebot: nachos?
18:13clojurebotTitim gan éirí ort.
18:13hiredmanclojurebot: nachos | are | delicious
18:13clojurebotOk.
18:13hiredmanclojurebot: nachos?
18:13clojurebotnachos are delicious
18:15RaynesIs there a function to return all but the last element of a sequence?
18:15hiredman,(doc butlast)
18:15clojurebot"([coll]); Return a seq of all but the last item in coll, in linear time"
18:15Rayneshiredman: Thanks. <3
18:23krumholt_ato, thanks that was it
19:50dakroneis there an easy way to create java classes with annotations in clojure?
20:07skillet-thiefthe standard clojure xml parsers all want streams or uris: I want to parse xml that is already in a string. What to do?
20:11dakroneskillet-thief: in clojure.contrib.lazy-xml the parse-seq function takes a string
20:11skillet-thiefdakrone: ok, I must have read wrong. Thanks.
20:12dakroneskillet-thief: oh wait, nevermind, that's my mistake
20:12dakroneskillet-thief: it is only a URI
20:12chouserit's because the Java xml parsers want streams.
20:12chouserYou can open a stream on a string.
20:12skillet-thiefdakrone: yeah, that is what I thought.
20:13skillet-thiefchouser: all right, I'm going to look at that.
20:16dakroneit'd be (def stream (StringReader. foo)), where foo is the string right?
20:19chouserskillet-thief: sorry, had to step awawy
20:20chouserlazy-xml includes an example that parses a string.
20:20chouser(lazy-xml/parse-trim (java.io.StringReader. "<foo />")) should do it
20:21chouserI think clojure.xml requires you wrapper a org.xml.sax.InputSource around that
20:21skillet-thiefchouser: ok, just found that example.
20:22skillet-thiefmy java is weak, so my eyes usually glaze over when I see stuff with streams...
20:22chouseryeah, java IO is relatively featureful but so convoluted.
20:26_atothere's two things that drive make crazy about the JVM, startup-time and IO
20:26_atoIO is just seriously lacking, like you can't select() on a file, only on a socket that is opened in a special way
20:30skillet-thiefgreat, finally got my string parsed (after resolving stupid namespace problems). Thanks guys!
20:30abedrais there a way to turn a string into a function call?
20:32_ato,(eval (read-string "(+ 1 2"))
20:32clojurebotDENIED
20:32_atoaww
20:32_atobut that'd do it
20:32abedrajust use eval?
20:33abedrayep that works
20:33abedrathanks
20:39hiredman,((resolve (symbol "+")) 1 2)
20:39clojurebot3
20:43falkorHow does one create a simple java array (like the equiv of String[] arr = new String[4])?
20:45wooby,(resolve (symbol "+"))
20:45clojurebot#'clojure.core/+
20:45_ato,(make-array String 4)
20:45clojurebot#<String[] [Ljava.lang.String;@1cf7e4a>
20:45falkor_ato: thanks
20:46_atoor if you want to create it from an existing list or vector:
20:46_ato,(into-array String ["a" "b" "c"])
20:46clojurebot#<String[] [Ljava.lang.String;@1e90fee>
20:47falkor,(println "thanks ;) ")
20:47clojurebotthanks ;)
21:20abedrais there a way to find the arity of a function?
21:21hiredmanabedra: not really
21:22hiredmanwell
21:22hiredmanactually
21:23abedraall i really want to do is not send an additional argument to a function if it doesn't take any args
21:23hiredman,(-> (fn [x] x) class .getDeclaredMethods seq)
21:23clojurebot(#<Method public java.lang.Object sandbox$eval__6708$fn__6710.invoke(java.lang.Object) throws java.lang.Exception>)
21:23hiredman,(-> (fn [x] x) class .getDeclaredMethods first)
21:23clojurebot#<Method public java.lang.Object sandbox$eval__6714$fn__6716.invoke(java.lang.Object) throws java.lang.Exception>
21:24hiredman,(-> (fn [x] x) class .getDeclaredMethods first .getParameterTypes)
21:24clojurebot#<Class[] [Ljava.lang.Class;@1d6be00>
21:24hiredman,(-> (fn [x] x) class .getDeclaredMethods first .getParameterTypes count)
21:24clojurebot1
21:24abedrainteresting
21:24hiredman,(-> (fn [x y] x) class .getDeclaredMethods first .getParameterTypes count)
21:24clojurebot2
21:25hiredmanif you use defn type metadata is stuck on the var that ends up holding the fn
21:26abedracool
21:26hiredmanclojurebot: nachos?
21:26clojurebotnachos are delicious
21:26abedralol
21:26hiredmanclojurebot: forget nachos |are| delicious
21:26clojurebotI forgot that nachos are delicious
21:26hiredmanclojurebot: nachos?
21:26clojurebotGabh mo leithscéal?
21:39abedrahiredman: that worked great thanks!
22:50danlarkinclojurebot: exceptions
22:50clojurebothttp://paste.lisp.org/display/74305