#clojure logs

2010-07-29

00:16_rata_hi
00:21qbgWhy did I only just recently notice that clojure.contrib.datalog exists?
00:22qbgContrib is huge
00:24technomancydaaku: there is radagast, but it's very primitive
00:24technomancyclojurebot: google clojure radagast
00:24clojurebotFirst, out of 12 results is:
00:24clojurebotfmu's Profile - GitHub
00:24clojurebothttp://github.com/fmu
00:24technomancyclojurebot: that's terrib
00:24technomancyle
00:24clojurebotexcusez-moi
00:24technomancyclojurebot: botsmack
00:24clojurebotclojurebot evades successfully!
00:24technomancyhttp://github.com/technomancy/radagast
00:25technomancythat guy doesn't even have any repositories
00:25daakucool, thanks technomancy -- i'll play with it
00:25technomancydaaku: it only does fn-level coverage, not branch-level
00:26technomancythe latter would necessitate compiler hacks
00:26daakutechnomancy: cool -- i found a namespace tracer thingy this morning too
00:35Lajlaablokzijl, I love you.
00:38slyrusis (first (filter ...)) the best way to find a single object that matches pred? I keep find myself looking for cl:find.
00:42scottjyeah, there's a find-first in contrib not sure if it's been promoted, it's implemented that same way
00:42tomojno promotion
00:48_rata_filter is lazy even when the input collection isn't? (newbie question, I know)
00:49Drakesonwhich html parser would you recommend?
00:49Drakesonis tagsoup good?
00:51tomoj_rata_: tricky question
00:52_rata_tomoj, why?
00:52tomojif the sequence is chunked, weird things can happen
00:52tomojlike (first (filter nil? (map println (range 10))))
00:52daakuDrakeson: i've heard good things about http://about.validator.nu/htmlparser/ -- but haven't used it myself
00:52tomojbut ignoring chunked sequences, yes, filter is lazy even if the input collection isn't
00:52tomoj(first (filter ...)) will stop and return as soon as it can
00:55_rata_lazy is so cool :)
00:56scottjDrakeson: if you're consuming html from other people chances are it's malformed so I'd use tagsoup
01:05slyrusthanks scottj
01:06slyrus(first (filter #(....)) = a lot more typing than (find item sequence :test bogosity), for instnace... but OK.
01:14_rata_tomoj, btw what's the problem with (first (filter nil? (map println (range 10)))) ?
01:22Drakesonscottj, daaku: thanks
01:23tomoj_rata_: try it out
01:23tomojit prints all ten even though it only returns the first
01:23tomojbecause range is chunked
01:23Drakesonscottj: is the fact that tagsoup breaks long strings into shorter ones a bug, desired, or just not important?
01:23_rata_yes, I tried it out first and didn't see anything wrong
01:23tomojoh, depends on your clojure version
01:24_rata_1.1.0
01:24tomoj,(first (filter nil? (map println (range 10))))
01:24clojurebot0 1 2 3 4 5 6 7 8 9
01:25scottjDrakeson: no clue
01:25_rata_the problem is that every number in range got printed?
01:30tomojyeah
01:30tomoj,(first (map println (range 100)))
01:30clojurebot0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
01:36_rata_mmm... ok
01:41_rata_sorry, but what's the reason for that behavior? what does it means that a sequence is chunked?
01:41tomojsee how it printed only the first 32 elements?
01:42qbg_rata_: Reduced overhead
01:42tomojif you did instead (nth (map println (range 100)) 32) it would print the first 64
01:42tomojso it realizes the sequence 32 elements at a time instead of 1 at a time
01:43tomojwhen you ask for the first one, it gets the first 32 ready. then when you get done with those and ask for the 33rd, it gets the next 32, etc
01:43daakuis there a version of if-let that allows for multiple bindings and tests?
01:44_rata_tomoj, ok, I understand it know :)
01:44_rata_can you set the "size of the chunk"?
01:45qbg,(doc chunk-buffer)
01:45clojurebot"([capacity]); "
01:45qbgThat isn't very useful...
01:46_rata_if instead of println the function would have been very costly to compute, would Clojure still be getting them in 32 elements chunks?
01:47tomojyep
01:48tomoj,(time (first (map #(do (Thread/sleep 100) %) (range 100))))
01:48clojurebotjava.lang.Exception: No such namespace: Thread
01:48tomojeh
01:48tomojwell, it takes a little over 3.2s since it sleeps for 100ms for each of the 32 in the chunk, even though you only ask for the first
01:49tomojthere's some function on someone's blog somewhere for forcing one-at-a-time semantics
01:49_rata_buuu... then lazy is not so cool
01:50tomojit doesn't cause trouble as much as you might think
02:45cais2002hi, I have two functions named convert-to_ and convert_to- , it seems that the naming caused some problem such that when ran in a standalone jar, the code has problem locating the right function to invoke
03:00BelafHi, I'd need to contact the author of r0man/appengine-clj on github, does anybody know if he's reading this channel or how to reach him? I don't seem to find any contact information on github...
03:03ataggartcais2002: that may be due to the fact that dashes are converted to underscores in compiled code
03:05cais2002ataggart: that's what I suspect. but it failed on a standalone jar without using :gen-class, too..
03:05cais2002anyway, the problem went away after i rename the functions
03:37cpfrhey is this the best place to ask incanter questions?
03:46NikelandjeloIs it good practice to use destructuring in function in params part? Or is it better to use "let" inside function for destructuring?
03:50sid3khi all, it seems gen-and-load-class is deprecated, where can I use information about this change?
03:51sid3kthe tutorial in wikibooks still includes some examples using this function
03:54sid3kany ideas)
03:54sid3k?
03:59ChousukeNikelandjelo: I think using let is better if the destructuring isn't very simple
04:00ChousukeNikelandjelo: and remember that the argument vector shows up as is in the documentation unless you override the metadata
04:02sid3khow can I load a java class using clojure?
04:02clojurebot"[Clojure ...] feels like a general-purpose language beamed back from the near future."
04:02sid3kclojurebot: thanks, yo
04:02NikelandjeloChousuke: Yes, actually I ask because of this :) Thanks for advice
04:02clojurebotexcusez-moi
04:02Chousukesid3k: what do you mean?
04:02Chousukesid3k: you can directly use any java class that is in the classpath
04:03sid3kit seems gen-and-load-class function is deprecated, I'm looking for its replacement
04:03Chousukeso you want to create a class in clojure?
04:03sid3ksome examples in wikibooks uses this function
04:03sid3kChousuke: exactly
04:03Chousukethere are many ways, depending on what you need.
04:03sid3khttp://en.wikibooks.org/wiki/Clojure_Programming/Concepts
04:04sid3kcheck out the example mentioining about user defined exception classes
04:04sid3kI just need to find replacement of gen-and-load-class
04:04Chousukethere's the :gen-class directive for the ns macro (see doc for gen-class), there's proxy for quick implementing of interfaces, and reify in 1.2.
04:05Chousukeor was reify in 1.1 already? hm
04:05sid3kall right, but as you see, I'm a newbie trying to learning from a tutorial already
04:05sid3kcould you check out the example in the page I've given?
04:06Chousukeright, the wikibooks tutorial is probably horrendously outdated if it still mentions gen-and-load-class
04:06Chousukethat was deprecated even before 1.0
04:06sid3krigt
04:06sid3kis there any document about the deprecation?
04:06Chousukenot really
04:07sid3kwhy its so hard to continue a tutorial written for 1.0
04:07sid3kanyway, I'm checking out that manual, I hope that will help
04:08Chousukesid3k: check out this one http://java.ociweb.com/mark/clojure/article.html
04:08Chousukeit's up to date and comprehensive
04:08Chousukethe wikibooks one seems pretty much useless :/
04:09sid3khmm, thanks
04:09Chousuke(it still says that (rest ()) returns nil :P)
04:09sid3kit was a nice beginning for me
04:09Chousukeit wouldn't be so bad if it were kept up to date
04:10sid3karright
04:10Chousukethe best documentation is usually on clojure.org but it's not in tutorial form
04:11sid3kI'm on the article you've linked, it looks great
04:11sid3kmany thanks
04:41Belafr0man: Hi, are you the one of appengine-clj ?
04:41r0manyup
04:42BelafCan I ask you some info about its state?
04:42r0manyes, for sure
04:43BelafThe submission to clojars seems to be broken for 0.4-SNAPSHOT, the jar is missing.
04:43BelafIs 0.4-SNAPSHOT meant to be released?
04:44r0manyes, someone mentioned this to me as well 2 days ago. i'll take a look at this maybe tonight or tomorrow
04:45BelafIs there an official way to report issues ? I couldn't find any contact information on github.
04:45r0manyes, i want to release that one soon. i thought about adding validations and some lifecyle methods, but i think i'll put those features in another release ...
04:47r0mani just enabled the "issues" checkbox on github. i wasn't aware that i have to enable it
04:47r0manyou can try this one now ...
04:47BelafOk, I'm going to try it now :-)
04:47r0manfor what are you using appengine-clj?
04:49BelafWell, for the time being I'm trying to find out how I can use it to write a web application. Still learning.
04:50r0manok, nice
04:50BelafMy problem is that I'm getting at much new things at the same time: clojure, compojure and appengine... so I never know how much one thing can be a problem or just me misunderstanding it.
04:51BelafPossibly I will end up with a real web application sooner or later, but I'm still trying to understand whether the appengine solution is the one I really need, for instance.
04:52callen-nycBelaf: well what are you trying to do that makes you think you need app engine specifically?
04:52callen-nycnot being confrontation, just inquiring and trying to grok what you're doing.
04:53callen-nycconfrontational
04:55BelafWell, honestly one of the things I liked was its "free to start" paying scheme. So I wanted to use it to experiment
04:55callen-nycBelaf: true that, but that's also what the dev machine is for.
04:56callen-nycBelaf: don't get me wrong, app engine is cool, but contorting yourself into bending over backwards while having to learn a whole language + web framework and then throw an unfamiliar deployment method into that that is unnatural to the environment seems a little
04:56callen-nycwhat's the word? masochistic.
04:56callen-nycBelaf: perhaps you could cool your jets, get your feel with clojure and compojure locally, get comfortable, worry about deployment/app engine testing when you're grokking your code.
04:57BelafOh, sure, it seems a wise advice :) On the other side I still haven't committed to anything, and I'm trying to learn things :)
05:00BelafI'm getting aware of the issues with appengine (funny database, startup times, etc), but it seems to also have interesting things... On the other side in the end I could turn to try a more normal setup.
05:02Belafr0man: do I need a github login to add an issue ?
05:06r0manBelaf: could be. i'm not sure
05:07r0manBelaf: i would also not suggest starting with app engine.
05:08BelafThanks for your advice :)
05:08r0mani played around a with it some while but there are still some tiny things that i don't know how to do.
05:09r0manand since the java version is not really open sourced it's sometimes hard to figure out to do things
05:09r0manbulk loading for example
05:09BelafI see.
05:18Belafr0man: Ok, it looks like I made it :-) (it took a while to guess the formatting...) I hope the issue description makes sense.
05:31Belafcallen-nyc: which are the main drawbacks of using appengine?
05:31r0manBelaf: thy
05:31Belafr0man: to you :)
05:32r0manBelaf: i'll take a look into this the next days
05:33BelafSure, no need to hurry. I just wanted to know whether the thing is released and if there's a way to communicate back.
05:34BelafAs I said, I'm not committed to it, but I'll keep playing around.
05:44old_soundhi, are there any libs for XMPP besides this one: http://github.com/zkim/xmpp-clj ?
05:49ragnardraek: I remember you asking about 'killing' a running agent that is blocking somewhere... Did you find a solution?
06:59krunaldoHi! I'm having some problems with lein... Ran lein new test1; cd test1; lein deps got this output http://pastebin.org/427714
07:00krunaldoI did change the version number from beta to 1.1.0 as the beta threw the first error
07:50raekragnard: one option would be to use future-cancel (i was using futures for doing the blocking parts), but I haven't investigated if that would work in my case
09:03neotyk,(doc flatten)
09:03clojurebot"([x]); Takes any nested combination of sequential things (lists, vectors, etc.) and returns their contents as a single, flat sequence. (flatten nil) returns nil."
09:04neotyk,(flatten nil)
09:04clojurebot()
09:04neotykhow come?
09:09greghwhat else would you expect it to do?
09:10raekthe docstring ^^^ says it should return nil :)
09:10neotyk,(doc flatten)
09:10clojurebot"([x]); Takes any nested combination of sequential things (lists, vectors, etc.) and returns their contents as a single, flat sequence. (flatten nil) returns nil."
09:11greghnil is the same thing as ()
09:11Chousukenope
09:11Chousukenil is not ()
09:11raeknot in clojure
09:11neotykgregh: not at all
09:11raek,(class nil)
09:11clojurebotnil
09:11raek,(class ())
09:11clojurebotclojure.lang.PersistentList$EmptyList
09:11gregher, maybe I'm mixing up my lisps again
09:12raekit works somewhat like nil in certain circumstances, though
09:12defn,(= nil ())
09:12clojurebotfalse
09:12defn,(rest ())
09:12clojurebot()
09:13raeki think the rationale basically is that there are many collection types which have empty values
09:13raek() [] {} #{} etc
09:13raek,(next ())
09:13clojurebotnil
09:14defn,(letfn print-seq [s] (when s (prn (first s)) (recur (next s))))
09:14clojurebotjava.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol
09:14defnblurg
09:15raek(letfn (print-seq [s] ...
09:15defnoh righ
09:15raek(letfn [(print-seq [s] ... even
09:19bOR_,(source flatten)
09:19clojurebotjava.lang.Exception: Unable to resolve symbol: source in this context
09:19neotyk~flatten
09:19clojurebotflatten is clojure.contrib.seq-utils/flatten
09:20neotyk(defn flatten
09:20neotyk "Takes any nested combination of sequential things (lists, vectors,
09:20neotyk etc.) and returns their contents as a single, flat sequence.
09:20neotyk (flatten nil) returns nil."
09:20neotyk {:added "1.2"}
09:20neotyk [x]
09:20neotyk (filter (complement sequential?)
09:20neotyk (rest (tree-seq sequential? seq x))))
09:20neotyk,(rest nil)
09:20clojurebot()
09:21neotyk,(filter false nil)
09:21clojurebot()
09:21neotyk,(next nil)
09:21clojurebotnil
09:21raekaha
09:21neotykand if filter would do when-let before lazy-seq it would return nil
09:22Chousukehmm
09:23Chousuke,(sequential? nil)
09:23clojurebotfalse
09:23raekimho, to get a fully lazy sequence, the if that returns nil should be inside lazy-seq
09:23neotyk,(lazy-seq)
09:23clojurebot()
09:24raek,(sequential? #{1 2 3})
09:24clojurebotfalse
09:24raek,(sequential? (sorted-set 1 2 3))
09:24clojurebotfalse
09:36edbondhow to setup java_options when I run 'lein swank'? I want -server etc.
09:38neotyk,((fn [& {:as a}] (println a)))
09:38clojurebotnil
09:38neotykbut what if I want in general case to use this "a" to be passed to another fn with &{:as..
09:39neotyk(flatten (seq a))
09:39neotykshould do the job
09:39chouserwhat are you asking?
09:39neotykas long as there is data in *a*
09:39chouser(fn [& a] ...)
09:40neotyk(fn [& {:as a}] ...)
09:40chouserisn't that the same?
09:40chouseroh, it's not
09:40chouserhuh
09:40neotyk,((fn [& a] (println a)) :a 1)
09:40clojurebot(:a 1)
09:41neotyk,((fn [& {:as a}] (println a)) :a 1)
09:41clojurebot{:a 1}
09:41neotykso I have fns f and g both with same &{:as a}
09:41chouserugh
09:41neotykhow do I pass *a* from f to g
09:42chousersome of these new bits of clojure don't feel quite as clean as most of the old bits.
09:42neotykit is nicer for user of f
09:42neotykbut if f has to use g it is pain
09:42raek(apply g a)
09:42chouser(apply g (apply concat a))
09:43raekaw
09:43neotykfor now I do something like (if (empty? a) (g a) (g))
09:43neotykbut it feels just wrong
09:43chouserneotyk: (apply g (apply concat a))
09:43chouserbut I agree it doesn't feel very right.
09:44raekthis uses keyword arguments and passes them around: http://github.com/clojure/clojure/blob/master/src/clj/clojure/java/io.clj
09:44chouserI assume you're using 'a' as a map in f as well?
09:44neotykyep
09:44bOR_edbond - relatively easy to add in the lein bin file.
09:45chouserneotyk: I might collect both forms, just to avoic (apply concat a)
09:45bOR_or set Java_CMD
09:46neotykraek: it doesn't do & {:as ...}
09:46neotykchouser: I dont think this would work for nil case
09:46chouser(fn f [& as] (let [a (apply array-map as)] ... (apply g as) ...))
09:46raekhrm, yeh
09:46chouserneotyk: why not?
09:47neotyk,(apply concat nil)
09:47clojurebot()
09:47neotykchouser: it does work for nil case
09:49chouser,(apply interleave ((juxt keys vals) {:a 1 :b 2}))
09:49clojurebot(:a 1 :b 2)
09:50sid3k,(str "hello" "world" "yo")
09:50clojurebot"helloworldyo"
09:51neotyk,((fn [& {:as a}] (apply (fn [& {:as a}] (println a)) a)) :a 1)
09:51clojurebotjava.lang.IllegalArgumentException: No value supplied for key: [:a 1]
09:52neotykwould it be possible to make & {:as a} take also map as argument?
09:52sid3kI'm a newbie started learning clojure today and it's like I'm trying my new bike
09:52chousersid3k: :-) welcome
09:52sid3kthanks :)
09:52neotyknormally :a 1 is converted to {:a 1} but if one would provide a map {:a 1} to it
09:53chouserneotyk: users will call your g function as well?
09:53chouseras in, it's public not a internal helper?
09:53neotykyes, they might
09:54Chousukeneotyk: I don't think it's possible.
09:54Chousukebut you can always do it manually.
09:54neotykI have to layers of api, one easy to use GET, POST and alike, and underling prepare-request execute-request
09:55neotykChousuke: I know it is not possible now
09:55neotykI would like to know what would be consequences of having it like that
09:55neotykwould it makes sense
09:55neotykthere would be nice symmetry in it
09:57neotykyou pass :a 1 it gets converted via & {:as a} to map, but you could also use map as argument to it
09:57neotykso (f :a 1) would be same as (f {:a 1}) if (fn f [& {:as a}] ...)
09:58raekI think it would make sense to design the functions that way, at least
09:58raekkeyword args will always have an even number of args
09:58raekand keyword-args-as-map will always be just one arg
10:00raek(fn [& opts] (let [opt-map (if (even? (count opts)) (apply array-map opts) (first opts))] ...))
10:00Chousukethat's probably too slow
10:03neotykwhere does this & {:as a} destructuring happen?
10:03neotykI mean where in code?
10:03Chousukein two places actually
10:04Chousukethe destructure function and the fn macro definition
10:19BahmanHi all!
10:39cemerickneotyk: what you're suggesting would require a check (consisting of multiple conditionals) on every fn call
10:46neotykcemerick: isn't there already a check?
10:46neotykit is hard to tell for me by looking at source of clojure.core/destructure
10:47Chousukeno, the conditionals you're seeing are macroexpand-time checks
10:48Chousukeit just checks if the & is followed by a map form or not.
10:48Chousukethen if it is, it generates the map-building code.
10:49cemerickneotyk: what Chousuke said. You can selectively get the behaviour you want with a simple wrapping fn though.
10:51Chousukesomething like (defn map-apply [f map & other-args] (apply f (apply concat other-args map)))
10:51Chousuke? :P
10:52Chousuketoo bad the arg order has to be reversed like that.
10:52neotyki do now (apply f (apply concat arg)
10:52cemerickI think it can be generalized.
10:53cemerickDepends a lot on what exactly neotyk wants. :-)
10:54neotykcemerick: I have fns f and g both have [& {:as a}]
10:54neotykf calls g
10:54neotykwould like to pass a from f to g
11:01cemerickneotyk: https://gist.github.com/71a50c1628d856d3a74d
11:02cemerickthat should be generally-applicable...so you can pass kwargs or a map, in addition to positional args.
11:03cemerickIt'd be nice if the original fn metadata were retained, etc. but that's a start.
11:05neotykcemerick: looks like magic to me, have to get some time to digest it
11:05cemerickheh. No magic, I promise. :-)
11:08neotykI believe you
11:09_rata_hi
11:11raekhrm, I would like it to check the number of args passed instead of looking at the type of the last arg
11:11raek(f :a {...}) should be possible too, imho
11:11raekif the fn is called with kw args, then there will be an even number of args
11:12chouseractually, you should be able to use :inline and get no performance cost on direct calls
11:12cemerickraek: that's a fundamentally ambiguous situation, at least for a wrapper-fn impl.
11:13raekis it? the arg count is 1 for kw args passed as a map, and an even number for kw args passed directly
11:13cemerickchouser: you still need to spelunk into the & args going in, and then destructure or not, no?
11:14raekor am I missing something?
11:16chouser(foo a b) has to be one case and (foo a) the other, doesn't it?
11:16chouseronly (apply foo x) is ambiguious at compile time
11:18raek(also, the fn that does the wrapping needs to know how many fixed arguments there are)
11:19raek(foo {:a 1, :b 2, :c 3}) => odd number of args (1), (foo :a 1, :b 2, :c 3) => even number of args (6)
11:19raekthat was what I thought
11:20raekonly the condition in cemerick's code would have to change
11:21raekhttps://gist.github.com/96d7618e294c5278c90f
11:22raek- (-> args last map?)
11:22raek+ (-> args count odd?)
11:35pdkis the :else keyword in a cond form mandatory for it to work as expected
11:35pdkor will it fall back on the last form in there either way
11:35pdk(doc cond)
11:35clojurebot"([& clauses]); Takes a set of test/expr pairs. It evaluates each test one at a time. If a test returns logical true, cond evaluates and returns the value of the corresponding expr and doesn't evaluate any of the other tests or exprs. (cond) returns nil."
11:36pdkypu're so enlightening clojure bot
11:36pdkoh shit it returns nil
11:36pdkthat's a bit of a downer after writing it all out
11:36pdk,(cond)
11:36clojurebotnil
11:36pdkor is that just for cond with no args, looks like it
11:37pdk,(cond 1 "guess so")
11:37clojurebot"guess so"
11:37pdk,(cond false "first form!" "something else!")
11:37clojurebotjava.lang.RuntimeException: java.lang.IllegalArgumentException: cond requires an even number of forms
11:37pdkBAH
11:37pdkfine cond you can have your :else
11:38Chousukeyou need the :else. or anything truthy, really
11:38Chousuke:i-dont-like-else works too
11:38pdkyeah
11:38pdki'll say things about its mother in the last keyword
11:39mfex,(cond (= 0 2) :zero (= 1 2) :one)
11:39clojurebotnil
11:40pdkwow
11:40pdkcond hates keywords!
11:40mfexwhen no clause matches and no last keyword clause cond returns nil
11:55raek"truthy" is a neat word...
12:01pdkcan (keys map) and (vals map) both be guaranteed to come out in the same order that the key-value pairs are stored in the map
12:04raekyou mean if (keys map) and (vals map) will be in the same order as (seq map)?
12:05raekI think the printer uses seq
12:05pdkyeah
12:05pdkhmmmm
12:05raekI would suspect so...
12:05pdki didnt think to use seq but that would fit the bill
12:06Chousukepdk: if you neeed to go over both then probably safest is to iterate the key-value pairs instead
12:06pdkyeah that was what i was lookin for
12:06pdkforgot about it i guess :p
12:06raekok, then seq does that
12:06Chousukepdk: it's very likely the seqs will have the same order but it's not guaranteed anywhere so in theory you can't rely on it :)
12:42pdkyknow what's awesome
12:42pdkrandom null pointers with no documentation
12:47foguspdk: Sounds like to need a Maybe :p
12:56pdkok so
12:56pdkhttp://pastebin.com/KSUKvZVa
12:56pdkwith this code
12:57pdkhazard a guess as to why the (inc (get successors :total-count line would give you a null pointer error
12:58chouserif successorts has no :total-count
12:58chouser,(inc (get {} :total-count))
12:58clojurebotjava.lang.NullPointerException
12:59jfieldsis there any way to put logic in the in the dispatch-val of a defmethod? For example if you want the defmethod to match any value in a set? something like: (defmethod foo #{:bar, :baz} [m] ()); where the caller uses (foo {:type :bar}) or (foo {:type :baz}) to call the method?
12:59pdkall maps within this structure are struct-maps of a defstruct i made that includes :total-count
12:59pdkand i had the (if (nil? successors bit so it wouldn't try to get from nothing
13:00chouserhm, so the value of :total-count would have to be nil I think.
13:03dnolenjfields: not really, but rhickey has spoken about wanting support things like that.
13:04jfieldsdnolen, cool. thanks.
13:07fogusHmmmm, you know it would be nice to do this: (defmethod foo [1 2] :as x [v] (println "I dispatched on" x))
13:08pdkchouser i have two functions that initialize and insert items into the structure
13:09pdkthey ensure that :total-count has a positive numeric value except when the structure is empty in which case :total-count at the root level will be 0
13:10pdk,(get {} :test)
13:10clojurebotnil
13:11raek,(inc nil)
13:11clojurebotjava.lang.NullPointerException
13:11raek,(inc (get {} :test 0))
13:11clojurebot1
13:13raekpdk: the NPE did not come from 'get', but from 'inc'
13:13pdkyeah the thing that's vexing me is
13:14pdksince the inc is within the else clause of that (if (nil? successors block why is it being reached and doing this if successors is nil
13:15raeksuccessors is a map (not nil) but does not have the key :total-count (nil)
13:15pdknow that's odd
13:15raekcontains? checks if it has a key
13:16raekacutally, successors can be anything truthy at that point
13:16pdkthing is all of the additions to the structure are being done through this http://pastebin.com/GSPCRRWu
13:16raeki.e. anything but nil and false
13:17pdkwhich is making every map added a struct-map that contains :total-count
13:17raek,(get (ref {:a 1}) :a)
13:17clojurebotnil
13:17raekit's not wrapped in something?
13:18pdkwhat do you mean exactly
13:18pdk,(get @(ref {:a 1}) :a)
13:18clojurebot1
13:18pdkthough come to think of it
13:19pdkmaybe the fact that the get within new-total-count right there defaults to nil instead of 0
13:19pdkthat may explain the error
13:19pdkummmm
13:19pdkor not
13:20raekcan you do a (do (println successors) (if (nil? sucessors) ...
13:21raekthat would make it simpler to diagnose
13:21raekto see if successors is really a map, and if so whether it contains the key
13:22pdksure
13:23pdkoh no wonder
13:24pdkthe values of the keys outside of those defined in the defstruct
13:24pdkare REFS to maps
13:24pdkand i forgot that
13:24pdkso this all came down to not having a lowly @
13:26pdkchanging (inc (get successors :total-count and (rand-key (seq successors to add a @ to both fixes it it seems
13:27raekthe values you let could be functions
13:28raekthat would make the code easier to test
13:28raekone shouldn't generally have to inject printlns
13:29raek(let [successors ... -> (defn sucessors [ ...
13:35pedroteixeiracan we have function overload with protocols?
13:35pedroteixeira[same name, different arity]
13:36raekno, protocol methods have vars in the namespace, just like functions
13:37pedroteixeiraraek: ok, thanks.
13:37aldebrnAny general advice on converting an XML tree into a specific document (viz., Latex)? After parsing the XML file into a map structure, I recursively converted each tag into a string using a multimethod, but I think that's ham-fisted and I wonder if I should be using zip-filter or xml-zip to properly walk the tree
13:40hiredmangeneral structure for that sort of thing seems to be: (-> create-tree transform1 transform2 collapse)
13:43edbondhow to profile clojure code?
13:43aldebrnThanks hiredman, I'll study ->
13:43pdk(doc do)
13:43clojurebotHuh?
13:43pdkfk
13:44pdkedbond regular java profilers can be used on a running clojure session it sounds like
13:44pdkthere's a bit mentioned in the getting-started section of clojure.org
13:46raekaldebrn: (-> e f3 (f2 c d) (f1 a b)) becomes (f1 (f2 (f3 e) c d) a b)
13:47edbondtried c.c.profile but it doesn't works, empty table only
13:48raekthat one requires you to put (prof ...) in your code
13:57aldebrnThanks raek. Seeing how to use zippers and -> to transform xml trees wholesale will need some thinking, the online examples I've found are small-scale specifics
14:13edbondraek: no, it doesn't require prof, http://richhickey.github.com/clojure-contrib/profile-api.html example doesn't work
14:14edbond1.2 beta
14:15edbondhm, my fault. didn't see that prof stuff
14:16raekthere are "real" profilers too
14:16raekI tried jvisualvm briefly once
14:17raekhttps://visualvm.dev.java.net/
14:18raekany java profiler will work, but the classes might have funny names
14:18raeklike
14:18raek,(fn [])
14:18clojurebot#<sandbox$eval500580$fn__500581 sandbox$eval500580$fn__500581@7c06b2>
14:18raekthose kind of names
14:19edbondraek: thanks, will try yourkit
14:27lozhyou probably alerady have jvisualvm if you're using a recent jdk, should be in the bin folder
14:40raekI'm philosophizing about whether I should use defrecord, deftype or reify
14:41raekin this case, the fields would not be of any use to the user directly
14:42raekanyone have any examples of cases for each one where it would be no doubt that it is the best fit?
14:47rhudsonraek, little direct experience, but my take is reify for one-offs, defrecord for most things, deftype if your name is Hickey
14:55aldebrnIs there a latest vim clojure tool somewhere? There's so many outdated things online, and mine doesn't autoindent >.>
14:59raeksince I have a separate "constructor function" for my defrecord and never access the fields from the outside, i'm thinking about calling reify in the constructor fn instead
15:10patrickdloganaldebrn: re: XML to other doc formats - what I've been doing lately is a basic XML to RDF then use Jena and SPARQL "construct" queries to build the graph I want, then spit out the appropriate doc format from that.
15:10patrickdlogan(heckalot easier than anything else I've ever done)
15:15hiredmanaldebrn: the point is not -> but that you get a tree, you put the tree through transformation stages, then you collapse or output the tree, or whatever
15:15hiredmanzippers are very useful for the transformation pipeline, but I dunno how useful they would be for the end
15:38arohneron a sorted set, is there a way to get the index of an element?
15:39dakronearohner: you could use clojure.contrib.seq-utils' "indexed" function
15:40arohnerdakrone: thanks, but I'm looking for simple, fast lookup
15:41tomojsorted sets don't implement any interfaces that look useful
15:41arohneri.e. (index-of :c #{:a, :b, :c,:d}) => 2
15:41tomojiow I think you're stuck with O(n)
15:42arohner:-(
15:42chouserarohner: you need a finger tree
15:43Nikelandjeloarohner: ,(doc positions)
15:43Nikelandjelo,(doc positions)
15:43clojurebot"clojure.contrib.seq-utils/positions;[[pred coll]]; Returns a lazy sequence containing the positions at which pred is true for items in coll."
15:43chouserarohner: I haven't tried it yet: http://functionaljava.googlecode.com/svn/artifacts/2.21/javadoc/fj/data/fingertrees/FingerTree.html
15:43Nikelandjelo,(positions #(= 4 %) (tree-set 5 4 3 2 1))
15:43clojurebotjava.lang.Exception: Unable to resolve symbol: positions in this context
15:44Chousukepositioning is undefined for a set
15:45NikelandjeloChousuke: It works for me
15:45arohnerChousuke: I specified a sorted set
15:45chousersorted sets can't get by index better than O(n)
15:45NikelandjeloIt's still O(n), but it's not very long to write
15:45chouseryou need child count info on each node of the tree, and clojure sorted sets don't do that.
15:45chouserfinger trees can
15:46Nikelandjeloarohner: Do you need speed or simplicity? :)
15:46Nikelandjeloarohner: Just wondering
15:46arohnerNikelandjelo: sub O(n)
15:48arohnerI can clojure.set/index the collection, but that changes the datastructure. I could keep the results of set/index in metadata or something
15:48chouserarohner: finger trees!
15:49chouseryou keep ignoring me and I'll have to solve this for you myself. :-P
15:49arohnerchouser: maybe I'll keep ignoring you then :-P
15:49Nikelandjelochouser: Is there implementation in clojure?
15:50chouserNikelandjelo: yes, though it's not ready for prime time.
15:57chouserwow. pain.
16:06BjeringWhat is the idiomatic clojure way to make a discrete event based simulation? In another language I would make a priority queue, post events to it, and have a thread-pool of workers working away at it (with complex locking on my part). I want to get rid of the locking thanks to the STM, but I am unsure how/what to map the thread-pool too.
16:09chouserthe thread pool is probably a java Executor and the queue is probably a java BlockingQueue
16:10jstirrell`is
16:10BjeringAlright, so if I was planning to use Netty in the same app (for the I/O) I could/should just go along and use the same pool for simulation part?
16:10jstirrell`is there an easy way to do make all nested elements of a seq top level?
16:11raekflatten
16:12chouserBjering: not sure. I don't know what Netty's thread pool looks like
16:12jstirrell`sweet thanks raek
16:12chouserBjering: I'd probably make my own Executor instance so that I could tweak it's parameters without messing with Netty's behavior at the same time.
16:12Bjeringchouser: But in principle as long as it is a java thread clojure is fine with it? Nothing speciial is needed (such as registering with the STM or so?)
16:13chouserright
16:14Bjeringthanks, sounds good, I'll walk down this path and see where it leads.
16:15pdk(doc rand-int)
16:15clojurebot"([n]); Returns a random integer between 0 (inclusive) and n (exclusive)."
16:15pdk,(rand-int 0)
16:15clojurebot0
16:16chouserarohner: I take it back. Unless I'm missing something functionaljava's finger trees are missing support for 'split' which you'd need to get sorted-set behavior.
16:16weissji'm having some trouble figuring out ->>. I think this fn is a good candidate for using ->> but i can't figure out how to turn it inside out: (defn gather-tests [testfilter nslist]
16:16weissj (filter testfilter (vals (apply concat (map ns-publics nslist)))))
16:17chouserarohner: you could try to use my finger-tree, but it's probably not worth it.
16:18chouserweissj: try: (defn gather-tests [testfilter nslist] (->> nslist (map ns-publics) (apply concat) vals (filter testfilter)))
16:18weissjchouser: thanks!
16:18weissjthat is what i had, but it didn't look right for some reason
16:20chouserrun your copious unit-tests on it to gain a sense of comfort that it's correct. :-)
16:24pdkwith a struct-map the keys declared in the defstruct are always lumped at the start of the map's sequence form right
16:24pdk,(doc struct-map)
16:24clojurebot"([s & inits]); Returns a new structmap instance with the keys of the structure-basis. keyvals may contain all, some or none of the basis keys - where values are not supplied they will default to nil. keyvals can also contain keys not in the basis."
16:24pdk,(doc defstruct)
16:24clojurebot"([name & keys]); Same as (def name (create-struct keys...))"
16:24pdk,(doc create-struct)
16:24clojurebot"([& keys]); Returns a structure basis object."
16:25raeki don't know if one can rely on that the struct's own keys always will be first
16:25pdkhm
16:25raekif it doesn't say it in the docs
16:25pdkwell the code to skip iterating over the keys already in the struct is already there so we can deal
16:32pdk"A struct map will retain its base keys in order."
16:57aldebrnpatrickdlogan, thanks for the pointers on converting XML to templated doc formats, I'll look into them. I know I want to transform nearly every tag into a document representation, so a walk makes more sense than a set of queries, but I'll think about it
16:59aldebrnhiredman, after puzzling over the zipper docs, it looks like a zipper is one good structure to use for a walk through the tree, applying transformations that might rely on a node's ancestors and descendants (e.g., in reST-to-XML, <section> tags are used to denote chapters, sections, subsections, etc., which Latex differentiates between)
17:00aldebrnI'm trying to decide how to transform a node object into a string, and build that alongside a zipper (or whatever walker is used)
17:01patrickdloganaldebrn: sure thing - though it may work well. look at sparql "construct" queries (and you can do that over in-memory graphs - v.lightweight)
17:03jkkramerdoes anyone have an emacs config that supports nice indentation for defrecord and friends?
17:03raeki've been looking for that too
17:04technomancypatches please!
17:07jkkramerit seems like a tricky thing to deal with, since it's context-sensitive
17:07rhudsonaldebrn: you might want to look at XSLT, at least for inspiration. It's a pure functional language specifically designed for doc transformations
17:07raekjkkramer: how?
17:09jkkramerraek: from what i can tell, most indentation rules can be specified per the first symbol -- e.g., by telling it that defn indents like defn
17:09jkkramerraek: but for defrecord method bodies, the first symbol in the form changes
17:09raekah
17:10jkkramerif all your defrecord methods are on one line like most examples, it's fine, but not for multiline methods
17:10raekyeah, I see the issue
17:11raekletfn has the same problem
17:14raekalso, anyone else think that def contents should be indented 2 spaces too?
17:15raekso the contents of a map replacing a function is to the left
17:15jkkramerraek: agreed...i was just about to make that change to clojure-mode.el
17:16technomancyyay, patches. =)
17:18raektechnomancy: any rationale on the current indentation of 'def'?
17:19raekin case we just dug up some "this has been discussed thorougly before" issue...
17:21technomancyraek: nope, 100% legacy
17:21technomancythat is to say, I didn't write it, I inherited it.
17:24raekwas the backtracking-indent inherited by you too?
17:24technomancyaye; no idea what it does.
17:25raekjkkramer: the backtracking-indent knows about proxy, which should be indented like defrecord and friends
17:25raekiirc
17:25raekmaybe it's just a matter of adding defrecord/deftype/reify to that list
17:26jkkramerraek: ya, could be; will experiment. my emacs lisp skills are poor
17:26raekmine too
17:26raeknow, how do I activate an elisp defcustom?
17:29raekokay, letfn indents well with M-x customize-variable clojure-mode-use-backtracking-indent
17:38pdk,(= (seq [1 2 3]) (seq '(1 2 3)) (list 1 2 3))
17:38clojurebottrue
17:38pdk,(seq [1 2 3])
17:38clojurebot(1 2 3)
17:45jkkramerraek: yup, after figuring out how to recompile clojure-mode.el, adapting the proxy indent rule for defrecord, and enabling backtracking-indent, it works! sweet
17:45jkkramerstill can't get def to indent 2 spaces though
17:48raekjkkramer: add (def 'defun) over (defn 'defun)
17:48raek(put 'defrecord 'clojure-backtracking-indent '(4 4 (2)))
17:48raek(put 'deftype 'clojure-backtracking-indent '(4 4 (2)))
17:48raek(put 'reify 'clojure-backtracking-indent '((2)))
17:48raekthese are the changes I made
17:50raekoh, forgot defprotocol
17:50tomojraek: that fixes defrecord??!
17:50tomojI didn't think it was possible with the way clojure-mode currently indents
17:50jkkramerraek: oh, there we go. i didn't restart proprely
17:50raekyes, if one activates clojure-mode-use-backtracking-indent
17:50tomojawesome!
17:50raekwhich is experimental
17:50jkkramerthat should be enabled by default
17:51jkkramerseems to work well enough
17:51tomojraek: thanks!
17:51qbgWhat is backtracking-indent?
17:51raeka feature of clojure-mode
17:52raekthat the old maintainer started to work on
17:52jkkramerwhich has apparently laid dormant until now
17:52qbgHow is it different than the normal indent that clojure-mode provides?
17:52raekit can indent letfn, proxy and defrecord better
17:52qbgSounds nice
17:52qbgI hate indenting them by hand
17:52raek23:07 < jkkramer> raek: from what i can tell, most indentation rules can be specified per the first symbol -- e.g., by telling it that defn indents like defn
17:52raek23:07 < jkkramer> raek: but for defrecord method bodies, the first symbol in the form changes
17:53raekjkkramer: could you add defprotocol '(4 (2)) too?
17:53raekor, should you or I do the patch?
17:54jkkramerraek: feel free to go ahead. i didn't fork or anything yet
17:54raekok, I have a fork
17:57StartsWithKany one using c.c.error-kit or c.c.except?
18:02jkkrameroh man, this is so much better now, with proper auto-indents
18:04raeki fixed future to indent like do, too
18:05raekit's bad when the try and future forms are next to each other, and the indentation differs with one space
18:05raekalso, I wanna remove the special indentation for assoc
18:05raekI think special indent should be reserved for macros
18:06raekany comments?
18:07technomancyraek: let's leave it alone for now.
18:08jkkrameri never noticed that one before
18:10technomancywhile we're fixing clojure-mode, if somebody could make it so delete-trailing-whitespace doesn't kill commas et the end of the line that'd be great too. =)
18:10technomancymaybe it'd be better just to not treat commas as a whitespace syntax class
18:12raektechnomancy: assoc? future too?
18:12jkkramermaybe multiline docstring indentation, too?
18:12technomancyraek: just assoc. future sounds good.
18:12raekk
18:14raekI won't change the default setting for clojure-mode-use-backtracking-indent
18:15raeksince I don't want to potentially break the clojure community's indentation over a night
18:17lozhcan fix the preferred ^Class hint too by adding ("\\^\\sw+" 0 font-lock-type-face) towards the end of clojure-font-lock-keywords
18:18lozhonly #^Class gets highlighted as it stands
18:19lozhand I've no idea whey #?^\\sw+ doesn't match both patterns
18:23raeklozh: which line?
18:25lozhbetween 513 and 514 as I'm looking in github now
18:27raekfound it
18:27lozhcool, was halfway through cloning it :)
18:29raekthat regex matches both
18:29raekbut I had to restart clojure-mode
18:30lozhDoesn't work in mine, odd, even though it did in re-builder
18:30lozhI'll double check restarting it
18:33lozhDefinetely doesn't work for me, just doing (defn test ^String a]) into a blank buffer doesn't highlight with #?^\\sw+
18:34lozhbut #^String does
18:37cmihaiIs there any official Clojure documentation, specs and / or API I can download for offline use (such as pdf or zipped html formats)? I could mirror the whole website with httrack or wget or grab the urls from the front page source, but that's probably not very nice.
18:38pdki highly doubt there's any large files on there to make people worried about bandwidth
18:38lozhI don't think wget would be too painful, there's not that many pages linked
18:38pdkit's practically all text
18:38cmihaiSame goes for the blip.tv videos, I can easily grab the flv, but that is rather taxing on my time :-)
18:39technomancycmihai: fixed the curl-related bug you found yesterday btw.
18:39cmihaiHm... I just grabbed the source, ran an emacs macro and curl-ed it locally, looks readable... but no saved pictures and stuff and would need more cleanup.
18:39cmihaitechnomancy: oh, cool :-)
18:39lozhWonder if clojure-mode makes more sense in the languages customisation group rather than application
18:39cmihai%s/curl/wget/g ? :P
18:39technomancycmihai: eh; it was actually a bug involving both.
18:43cmihaitechnomancy: ah, the -fail flag. Epic :-)
18:50lozhraek: do you still have clojure-mode handy - line 323 could do with a ? after the # too - fixes up (def^{:doc "foo"} bar) to highlight bar
18:51lozhI daresay the one on 465 could too, but I don't know what that affects yet
18:53StartsWithKso, here is a small lib that can be used to define custom exceptions http://paste.pocoo.org/show/243227/
18:54StartsWithKyou can (defexception Foo) that will create a real java class
18:55StartsWithKlike in error-kit, exceptions can have extra data attached to them
18:57raeklozh: ok
18:57lozhty
18:58raekhttp://github.com/raek/clojure-mode/commits/master
18:58raekthis is what I have so far
19:01raektechnomancy: enjoy the patches!
19:01technomancywheeeee
19:01technomancyraek: I have a high-priority fix coming out soon in Lein 1.2.1; hope to get to my elisps soon after.
19:02raekno worries
19:03raeklozh: jkkramer: thanks for the help!
19:04raekanyone know how to disable tab characters in emacs?
19:05raekI want them *gone*!
19:05jlfM-x customize-variable RET indent-tabs-mode
19:06Raynestechnomancy: Write an Emacs clone in Clojure configurable in Clojure.
19:06technomancydown with tabs!
19:06jlfand C-x h M-x untabify
19:06RaynesI shouldn't joke. Knowing you, you'll actually do it and kill yourself. ._.
19:06technomancyRaynes: nope, I'll just get Clojure to compile to Emacs bytecode.
19:06technomancymuch less work
19:07RaynesCute.
19:07technomancyI've said too much.
19:08raekjlf: thanks
19:08jlfnp
19:09raektechnomancy: that patch I submitted some months ago for fixing name-space -> name_space in clojure-test-mode.el... it contained a tab character....
19:09raek*ashamed*
19:11technomancyraek: it's ok, this indentation code has paid the penance. =)
19:23pdk(doc dissoc)
19:23clojurebot"([map] [map key] [map key & ks]); dissoc[iate]. Returns a new map of the same (hashed/sorted) type, that does not contain a mapping for key(s)."
19:23pdk(doc disj)
19:23clojurebot"([set] [set key] [set key & ks]); disj[oin]. Returns a new set of the same (hashed/sorted) type, that does not contain key(s)."
19:23pdkvoila
19:25technomancyconj works on sets and maps (as well as vectors, lists, etc); I don't see why disj should be different.
19:26technomancy(minor point of course)
19:28raekI guess it's just a matter of naming symmetry
19:28raekassoc-dissoc, conj-disj
19:37slyrus_technomancy: thanks for the lein manual install instructions!
19:37slyrus_to get it fully working however, I had to do: cp lib/dev/swank-clojure-1.2.1.jar lib/
19:37slyrus_oh, and I like the ideas about the hooks
20:16weissjif i want a try/catch/finally block to return a map, and one of the items in the map is the "end time" of the block execution, how do i add that? the finally seems to only be for side effects.
20:17weissji guess i could just assoc it after the whole block
20:41gfrlogwhat's the clojure word for zip?
20:41gfrlogas in (zip [1 2 3] [:a :b :c]) => ([1 :a] [2 :b] [3 :c])
20:42rhudson(map vector coll1 coll2)
20:42gfrlogvery good
20:42technomancy,(seq (zipmap [1 2 3] [:a :b :c]))
20:42clojurebot([3 :c] [2 :b] [1 :a])
20:43technomancynot quite the same, but if you want a map back...
20:43gfrlogoh
20:43gfrlogwell that still gives a seq back...
20:43gfrlogooh
20:43gfrlogno it doesn't
20:53polypusis it possible to typehint the return type of an anonymous fn?
21:05gfrloghow do you find out if a vector contains a value?
21:05gfrlogor list, I guess
21:08gfrlog,(any? #(= 10) [1 2 5 10 23])
21:08clojurebotjava.lang.Exception: Unable to resolve symbol: any? in this context
21:08rhudsonThe usual idiom is (some #{x} coll)
21:08gfrlogah yes
21:08rhudson,(some #{10} [1 2 5 10 23])
21:08clojurebot10
21:09gfrlog,(some #{nil} [1 4 nil 2 3])
21:09clojurebotnil
21:09gfrlog,(some #{nil} [1 2 3 4])
21:09clojurebotnil
21:09gfrloglet's hope one isn't looking for nil then
21:10rhudson(some #(= % nil) ...) works in that case
21:10gfrlogyep
21:10gfrlogwait
21:10gfrlog,(some #(= % nil) [1 2 3])
21:10clojurebotnil
21:10rhudsonBut I'm always surprised when I type any? and it isn't there
21:10gfrlog,(some #(= % nil) [1 nil 3])
21:10clojurebottrue
21:11gfrlog,(def any? some)
21:11clojurebotDENIED
21:11gfrlogoh that hurt
21:11rhudsonclojurebot doesn't like def's
21:12gfrlog,(apply def [x 10])
21:12clojurebotDENIED
21:12gfrlogwhat a jerk
21:12tomoj-> (def any? some)
21:12sexpbot=> #'net.licenser.sandbox.box3508/any?
21:12tomoj-> (any? #{4} [1 2 3 4])
21:12sexpbot=> 4
21:12polypus,(eval '(def any? some))
21:12clojurebotDENIED
21:12polypusfigures
21:13gfrlog,(println "DENIED")
21:13clojurebotDENIED
21:13rhudson:)
21:13gfrlogdid it work? we'll never know...
21:13polypus,
21:13clojurebotEOF while reading
21:14polypus,
21:14clojurebotEOF while reading
21:14gfrlog(let [x (java.util.ArrayList.)] (.add x 12) (.add x x) x)
21:14gfrlogdang
21:15gfrlog,(let [x (java.util.ArrayList.)] (.add x 12) (.add x x) x)
21:15clojurebot#<ArrayList [12, (this Collection)]>
21:15gfrlogoh weird
21:16tomojhuh, clojurebot's sandbox sucks
21:17tomoj,foo
21:17clojurebotbar
21:17rhudsongotcha!
21:19rhudsonThat (this Collection) thing isn't clojurebot; it's Clojure itself
21:19rhudsonpretty clever, I think
21:20gfrlogruby does that too, I found out yesterday
21:20gfrlogit's a weird thing that you can only get with mutable data types
21:20rhudsonWell, for an immutable collection there's not (obvious) way to get it to contain itself
21:21tomojseems like it's java, not clojure
21:21gfrlogit's whoever's turning the thing into a string
21:21gfrlog,(.toString (java.util.ArrayList.))
21:21clojurebot"[]"
21:22gfrlog,(.toString (java.util.arrayList [2 34 4]))
21:22clojurebotjava.lang.ClassNotFoundException: java.util.arrayList
21:22gfrlog,(.toString (java.util.ArrayList [2 3 33 333]))
21:22clojurebotjava.lang.ClassCastException: java.lang.Class cannot be cast to clojure.lang.IFn
21:22gfrloggosh dangit
21:22gfrlog,(.toString (java.util.ArrayList. [2 3 33 333]))
21:22clojurebot"[2, 3, 33, 333]"
21:23rhudsonYeah, the (this Collection) thing turns up in Groovy too, so kudos Java
21:23gfrlog,(.toString (let [x (java.util.ArrayList. [3])] (.add x x) x))
21:23clojurebot"[3, (this Collection)]"
21:24gfrlogpython catches it too
21:25tomoj,(+ 2 2)
21:25clojurebot5
21:25gfrlog,(+ 2 2)
21:25clojurebot4
21:25tomoj;)
21:25gfrlogI think that makes you a witch
21:26tomojI'm surprised sexpbot's been abused by clojurebot fans
21:26tomojclojurebot seems defenseless
21:26gfrlog,(System/getProperties)
21:26clojurebotjava.security.AccessControlException: access denied (java.util.PropertyPermission * read,write)
21:27rhudsonclojurebot: here's a botsnack
21:27clojurebotthanks; that was delicious. (nom nom nom)
21:30gfrlogwhy does he claim it is delicious, in the past tense, and only then proceed to nom on it?
21:30rhudsonpostprandial lipsmacking?
21:30gfrlogI question clojurebot's integrity
21:31gfrlog,(Thread/sleep 10)
21:31clojurebotjava.lang.Exception: No such namespace: Thread
21:44defni would like to put into question your question of clojurebot's integrity
21:45defnHmmm, this Seph language looks sort of neat
21:48gfrloghow do I get the first item in a list that satisfies a predicate?
21:49rhudson(first (filter pred? coll))
21:49gfrlogeasy!
21:49gfrlogman it's hard to think lazily
21:50rhudsonTakes a while but it opens up whole new vistas
21:50cmihaiDoes clojurebot support reverse polish sausage noming?
21:53defnonly if it's unadulterated
21:56tomojdefn: where do I see it?
21:56tomojI only lightly skimmed the blog post and gave up when there was no code
22:01gfrlogdangit what's clojure for reduce?
22:01rhudsonuh, reduce?
22:01gfrlog(doc reduce)
22:01clojurebot"; "
22:02gfrloghuh?
22:02gfrlogI don't see it on clojure.org/api
22:02rhudson,(clojure-version)
22:02clojurebot"1.2.0-master-SNAPSHOT"
22:02rhudsonFor some reason reduce documentation disappeared in some of the 1.2.0 snapshots
22:02gfrlogis reduce deprecated?
22:02gfrlogoh ok
22:02rhudsonIt's there in beta1
22:02gfrlogI was gonna say
22:02rhudson-> (doc reduce)
22:02sexpbot=> ------------------------- clojure.core/reduce ([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, ... http://gist.github.com/499722
22:03gfrlog-> (clojure-version)
22:03sexpbot=> "1.2.0-beta1"
22:03TheBusbyit is interesting that reduce doesn't show up in the docs for core
22:05gfrlogRich has thought of something better
22:05rhudsonuser=> (doc reduce)
22:05rhudson-------------------------
22:05rhudsonclojure.core/reduce
22:05rhudson([f coll] [f val coll])
22:05rhudson f should be a function of 2 arguments. If val is not supplied,
22:05rhudson returns the result of applying f to the first 2 items in coll, then
22:05rhudson applying f to that result and the 3rd item, etc. If coll contains no
22:05rhudson items, f must accept no arguments as well, and reduce returns the
22:05rhudson result of calling f with no arguments. If coll has only 1 item, it
22:05rhudson is returned and f is not called. If val is supplied, returns the
22:05rhudson result of applying f to val and the first item in coll, then
22:05rhudson applying f to that result and the 2nd item, etc. If coll contains no
22:05rhudson items, returns val and f is not called.
22:05gfrloglike extend
22:05rhudsonI don't know why the docstring for reduce is so volatile, but I can't imagine it going away any time soon
22:05TheBusbyUnderstand it's there, just why not here? http://richhickey.github.com/clojure/clojure.core-api.html#clojure.core/reduce
22:06slyrusit's probably in the special forms page
22:06gfrlogit can't be a special form
22:07TheBusbydoesn't appear in the index either...
22:09rhudsonIn the current source reduce is defined early on without a docstring, but with a comment that it's gonna be redefined later after internal-reduce is defined. But that later def is commented out (with #_ ) So it's there, but doesn't show up in the doc because there's not docstring.
22:11rhudsonIn between, it's used in about a zillion places
22:12rhudsonSo I take it to mean that internal-reduce (whatever that is) and/or the definition of reduce in terms of it, isn't quite baked yet
22:14rhudsonthe two api doc branches are 'master' (the bleeding edge) and '1.1' (stable release).
22:14rhudsonIt's a little unfortunate there isn't a '1.2-beta1' branch
22:14chouserare we in beta now?
22:15rhudsonYou would know better than me. There's a 1.2.0-beta1 download
22:18gfrlogI'm having an awful time constructing a large binary tree without blowing the stack.
22:18gfrlogI tried using lazy-seq around the recursive calls, but that just delayed the stack blowing until the seq was resolved
22:19gfrlogI feel like I'm missing something easy
22:19rhudsonIs it something you can build from the bottom up?
22:19gfrlogthat'd be a bit strange I think
22:20rhudsonWell, depends on what you're trying to do. What are you trying to do?
22:21gfrlogwell, say you have a number. like 42.
22:21rhudsonI like 42
22:21gfrlogI would like to turn 42 into
22:21gfrlog,(* (* (+ (+ (*) (*)) (*)) (+ (* (+ (*) (*)) (+ (+ (*) (*)) (*))) (*))) (+ (*) (*)))
22:21clojurebot42
22:22rhudsonok. btb you do know that + and * are n-ary, right?
22:22gfrlogyeah
22:22rhudsonjust checking, sorry
22:22gfrlogit's just simpler code to do it binary
22:24gfrlogthis is crazy. I can't think of any way of doing this.
22:25tomojhmm
22:25tomoj,(* (* (+ (+ (*) (*)) (*)) (+ (* (+ (*) (*)) (+ (+ (*) (*)) (*))) (*))) (+ (*) (*)))
22:25clojurebot42
22:25tomojwtf?
22:25tomojoh, heh, I accidentally left my repl with the + that always returns 5
22:26gfrlogha!
22:26rhudsonwhat's the representation -- what's the boring form with all the (*) added together?
22:27gfrloghuh?
22:27rhudson6*7? 2*3*7? 3*7+3*7 ?
22:27gfrlogoh I dunno
22:27gfrlog:) it's something
22:28gfrlogit works out evidently
22:28rhudsoni.e., what's your method for turning a number into that form?
22:28gfrlogwell the one I've been trying is to check if the number is divisible by anything in (2..12)
22:28gfrlogif so you create a (* d (/ n d))
22:29gfrlogotherwise decrement and try again
22:29gfrlog(creating a (+ (*) (dec n))
22:29tomojwhat the heck are you really trying to do? O_o
22:30gfrlogI was gonna create this gigantic bunch of crazy code that would make clojurebot say something silly and then everybody would think I was clever
22:30gfrlogor had too much time
22:30gfrlogbut now I'm genuinely interested in why this seems to be so hard to do in clojure
22:31gfrlogthe only way I can possibly imagine doing this is with mutable data types
22:38gfrlogoh well
22:38rhudsonThis might be a job for clojure.zip
22:39rhudsonstart with (vector-zip [42]) and start transforming it.
22:41rhudsonor maybe (seq-zip '(42))
22:47slyrushrmm... anyone using fnparse3?
22:51tomojI wish
22:52slyruswhy?
22:52clojurebothttp://clojure.org/rationale
22:52slyrussilly bot
22:54tomojI've tried reading the source but still don't get it
22:55weissji'm trying to write a recursive function that traverses a tree (checking "dependencies" and keeping track of them to catch circulars), but I am a little stumped on how to recur in a loop. can someone point me to an example?
22:56weissj(when i say recur in a loop, i mean call recur multiple times)
22:58slyrustomoj: I guess the question is fnparse2 or fnparse3? or keep doing this #^&^*! parsing by hand
22:59weissjhm i guess i don't use "recur" at all, just call the function in the "normal" stack consuming way. my tree should be shallow enough for that to work.
23:00rhudsonweissj: you can call recur in any tail position in the loop. That would typically be the result expressions of 'if or 'cond
23:00weissjrhudson: but this is a tree recursion - so my original call to the fn should spawn multiple recurs, which themselves could spawn multiple recurs etc
23:01weissjhow do i do multiple recurs? doseq doesn't seem right
23:01weissjsince it is for side-effects
23:02tomojyou can't
23:02weissjtomoj: this is a pretty common scenario, what's the idiomatic way?
23:02lancepantzanyone happen to know what unit jetty returns time in within the statistics handler?
23:02weissjjust consume the stack?
23:03tomojtrampolines might help
23:03tomojoften better to just rethink the way you're doing it
23:04rhudsonWould tree-seq work for you?
23:05weissjrhudson: i don't know, will it handle circles? i doubt it. my code needs to catch circular deps
23:06weissjlet me check if trampoline will work
23:06rhudsonmaybe clojure.contrib.graph ?
23:09weissji dunno, there's gotta be a standard way of doing this. i'm just traversing a tree
23:09tomojtree-seq does a depth-first traversal
23:09weissjtomoj: but i want to write the recursive function myself
23:09tomojmaybe you should look at tree-seq's source, then?
23:09weissjhow is the recursion in a tree done, normally?
23:10weissjyeah i guess that's what i should do :)
23:10rhudsonIf there's loops in it, it's not a tree
23:10weissjrhudson: yeah, i just want to throw an exception if i find a loop
23:10tomojif you pass something with a cycle to tree-seq I think you'd get an infinite seq back
23:11tomojand you'd have to walk the seq collecting what you find to check for dups
23:11rhudsonWell, you could make a set of all the nodes you've seen in the tree walk, and barf if you find one you've already seen
23:11weissjrhudson: yeah that was my plan
23:12rhudsonWithout looking at the source, I imagine wraps the recursive calls with lazy-seq
23:12rhudson[I imagine => I imagine tree-seq]
23:13tomojyep
23:13weissjrhudson: yeah, it recurs the old fashioned way, just by calling itself
23:14weissjso i guess that's what i'll do. thanks :)
23:16rhudsonlancepantz, don't know about jetty stats specifically, but most Java time stuff is msec
23:17lancepantzrhudson: you are correct, i eventually found it
23:32technomancyreduce's metadata disappearing was due to a bug.
23:32technomancythere was a more performant version of reduce that used protocols; somehow its definition overwrote the metadata on the original
23:32technomancyI think that reduce got disabled for 1.2 though
23:40defnfogus is my hero: seq-utils
23:40defnerr: http://www.fogus.me/fun/unfix/
23:40defnawesome.