#clojure logs

2011-06-02

00:11tomojclojure support?? wow
00:18kornystomoj: yep - see https://gist.github.com/1001206 - it's pretty awesome
00:34offby1$36/month isn't that bad.
00:34offby1EC2 micro is a bit cheaper, but not much
00:50dnolenhiredman: ping
00:50kornysoffby1: yep, though for a tiny demo app, free would be better :)
00:52hiredmandnolen: pong
00:53dnolenhiredman: I've addressed some but perhaps not all of the issues. LVar and LCons now take metadata for doing custom things.
00:53dnolenhiredman: (unifier '(?x . ?y) [1 2]) (binding-map '(?x . ?y) [1 2]) work for first and rest matching.
00:54hiredmanah, cool
00:55dnolenhiredman: one thing I'm on the fence about is allowing people to directly pass LCons instances to the unifier ...
00:56dnolenhiredman: if you wan to create something that you can spit out from a macro, will emitting (lcons 1 (lcons 2 ...)) not work for you? core.logic also provides convenience macro llist for doing this.
00:56hiredmanwell, if they have a pre-prepped thing, and the pre-prepping happens to create an LCons
00:57hiredmandnolen: possibly, since you mention prepping is expensive in the readme, and my patter is static at compile time I have the macro do the prepping
00:57hiredmanpatterns
00:57hiredmanare
00:58hiredmansince I am not familiar with lcons I went with what seemed like the highest fidelity (pulling the fields and passing them to the constructor again)
00:59dnolenyeah I have to think about LOGIC-7 some more. let me know if (unifier '[(?x . ?y) 3] '[(1 2) 3]) support satisfies 5 & 6.
01:01hiredmanseems like it would, but yes, I'll kick it around
01:01dnolenlatest is on github and clojars.
03:15chouserthere. pushed a very early version of data.xml
03:15chouserHm, needs a README. https://github.com/clojure/data.xml
03:20brehautheh "; blame Chouser for anything broken or ugly."
03:22brehautchouser: is it 1.2 compatible?
05:08andrewcleggchouser: is data.xml fully lazy, i.e. can you parse really big files as a stream of chunks?
05:08andrewcleggv. handy if so
07:48manutterlol, I *so* cheated on 4clojure question #65
07:50manutterhttps://gist.github.com/1004288
07:50mrBlissmanutter: quite clever!
07:51manutterI couldn't resist
07:52manutterexpect one more function to be added to the Do Not Use list very soon now...
07:56tufflaxDoes swap! "block" the thread calling swap! until it is successful? Or is it a new thread?
08:35chousertufflax: swap! spins. It will not return until it is successful.
08:35tufflaxok
08:38chouserandrewclegg: That's the intention, but it needs more testing before I'm willing to claim that.
08:42tufflaxI've got a really nasty but on my hands, has to do with java socketchannels. If anyone want to take a look it's here: http://pastebin.com/Xymx9ZgE
08:42tufflaxthank you chouser btw :)
08:48tufflaxs/but/bug and s/want/wants :p
08:57timvisherhey all
08:58tufflaxhi
08:59timvisherI'm trying to serialize a seq to disk in a file using `pr` and then read it back in and I'm encountering `error: java.lang.ClassFormatError: Invalid method Code length 361053 in class file wallpaper_manager_core/core$eval2183`
08:59timvisherMy only guess is that it's trying to execute a function because the seq is serialized as `(...)`
09:00timvisherAny thoughts?
09:00stuartsierraWhat are you using to read it back in?
09:00tufflaxPaste the code
09:00timvisher(load-file)
09:00stuartsierraThere's your problem. :)
09:00stuartsierra`load-file` means read & eval. You just want `read`
09:00timvisherAh
09:01timvisherso should I make the file into a string and then call read on it?
09:01timvisheror is there a convenience function for that?
09:01tufflaxin that case read-string
09:01raektimvisher: no, 'read' reads from a stream.
09:01timvisherraek: nice!
09:02raeksummary: pr and read work on streams (*out* and *in*, which can be rebound with 'binding'), pr-str and read-string work on strings
09:21andrewcleggchouser: I'll test it by throwing some gigs at it and seeing what happens
09:30markskil1eckAny idea why get-datasets for incanter is returning some html?
09:31kephale1what is the best way to download files w/in clojure (files of arbitrary type incl binary)?
09:32kephale1a la curl
09:33drewrkephale1: you can do something with (clojure.java.io/reader "http://foo")
09:34raekkephale1: if you don't need to control the headers, the simplest way is probably to pass a URL to clojure.java.io/reader (text) or clojure.java.io/input-stream (binary)
09:34chouserandrewclegg: cool. let me know what you find. Do beware of head-holding, though.
09:34kephale1drewr & raek: aha! ty
09:35drewrwas thinking reader would polymorphically give you an input-stream, but that wouldn't really make sense
09:36tufflaxIf anyone was trying to figure my bug out, i solved it.
09:36raekkephale1: it is probably a good idea to pass the url string through clojure.java.io/as-url and then verify that the scheme is http or https
09:37raekkephale1: my friends helped me find a bug/feature in my title-printing IRC bot but asking it to look up the title for the URL file:///dev/random
09:38raeks/but/by/
09:38sexpbot<raek> kephale1: my friends helped me find a bug/feature in my title-printing IRC bot by asking it to look up the title for the URL file:///dev/random
09:38raektufflax: what caused it?
09:38kephale1raek: oh good point
09:40raekkephale1: another point: if you want to read text, you specify the encoding of the text (the "file format" of the characters) with the :encoding option: (clojure.java.io/reader url :encoding "UTF-8")
09:40raekif it is left out, UTF-8 will be used
09:41kephale1cool, i'm mostly going to be shuffling jars around, but might have some text
09:42tufflaxraek: I was reading into the wrong buffer. On line 128 in my paste i should have saved the new c in the global *players*, because i was relying on :read-tmp to be set right. Now if I didnt get any more data after reading the length of the message i forgot the new read-tmp and next time read into the buf for getting the lengths
09:47tufflaxI gotta come up with a better way to debug my programs. I ran the server in a future, and prints dont show from the new thread. What I ended up doing was conjing debug msgs into a global. btw i tried bound-fn but it didnt help. In other languages ive mostly used prints to debug but it's not very convenient in clojure. is there a good debugger?
09:47raektufflax: are you using emacs, btw?
09:47tufflaxvim
09:48raekthe prints should appear somewhere
09:48tufflaxnot before my eyes ;)
09:48raekin emacs, the repl and stdout are distinct, so prints from the repl thread appears in the repl and prints from other threads appear in stdout
09:49raektufflax: you could try (intern 'clojure.core '*out* *out*) in the repl where you want the prints
09:49tufflaxoh, that explains why bound-fn didnt work
09:49raekthis will change the root binding
09:49raektufflax: strange, bound-fn should work too
09:50tufflaxbut still, prints is not so convenient, because sometimes one needs to add a (do ... ) or something like that. what do you use for debugging?
09:51raekfor stateful code? prints I guess... :)
09:51tufflaxhehe
09:51raekfor purely functional code, you can always test things in isolation in the repl
09:52tufflaxyeah of course, functional is better :p
09:52raekI tend to build a purely functional layer first that does parsing and operations on domain data
09:52kephale1is there a pretty way to empty an input stream into an output stream?
09:52kephale1copy into, i should say
09:52tufflaxraek did you read my code? any tips on style?
09:53raekkephale1: yes, 'copy' :-) http://clojuredocs.org/clojure_core/clojure.java.io/copy
09:53kephale1raek: yay, ty again
09:54raektufflax: I briefly looked though it. I'm not very familiar with how you program using the java.nio classes. my first idea was that this would probably be simpler using a thread/connection and streams
09:55raekbut I know that one thread per connection does not scale very well...
09:55tufflaxYeah thats why i didnt want that
09:58raekone advice is to try to limit the number of kinds of side-effects per function
09:59raekfor example read-from-client both reads data and changes the atom
10:00raekif it would return the data instead, it would be easier to test it in isolation
10:00tufflaxyeah that migth be a good idea
10:01tufflaxs/migth/might/
10:01sexpbot<tufflax> yeah that might be a good idea
10:01CozeyWhich Mustache library would you recommend? clostache, stencil, mustache.clj ?
10:01raekin general, try moving state-changing stuff out from functions if possible
10:01raekI think add-new-client is fine here, since it *only* does mutation
10:12Cozeywhat would you recomment for app configuration? property file? file with clojure code ?
10:13abedraCozey, it depends on what you are configuring and if that configuration needs to change while the program is running
10:14Cozeyi'd say it won't be update by the app, but maybe it would be nice to change the conf and notify an application - do You have something in mind?
10:14Cozeythis would actually not be easy to implement in a smart way
10:15abedraCozey, having a clj file as configuration data makes it a little easier to reach in and modify configuration
10:15Cozeyyes
10:15Cozeytrue
10:16Cozeyit would be in lisp philosophy
10:16chouserbut not if there are comments in the config file
10:16abedraI tend to use properties files for configuration data that I know won't change
10:16abedra:)
10:17oelewapperkeif you know it won't change don't you want the compiler to optimize it out ?
10:18abedraoelewapperke, I mean won't change after it is configured
10:18abedraoelewapperke, I want it to be configurable by others though
10:19abedrathat may not know how to edit a clj file
10:28tufflaxDoes bound-fn only install the bindings in the lexical scope?
10:30stuartsierrabound-fn is for dynamic, not lexical scope
10:31raektufflax: if I understand it correclty, it should remember the values of the dynamically bound vars in the dynamic scope where bound-fn is called. when the resulting fn is called, the body is evaluated in a dynamic scope with those remembered bindings in place
10:33raek(def *x* 1) (def f (binding [*x* 2] (bound-fn [] *x*))) (f) => 2
10:35tufflaxHm what are the dynamically bound vars? How come (future-call (bound-fn [] (println "arst"))) prints in my repl but not (future-call (bound-fn [] (fn-which-calls-println))), and not (future (println "asr"))
10:39raektufflax: vars that are intended to be dynamically rebound are those named with *earmuffs* (there is no need for special naming of constants in clojure, since vars should not be metutaded for maintaining application state)
10:40raekthey are often used to as "implicit" arguments to functions
10:41raeke.g. print prints to the stream in *out*. to print to another stream, one temporarily and dynamically rebinds the value: (binding [*out* ...] (print ...))
10:41tufflaxwhat about earmuffs on global refs and atoms btw?
10:42raeksip them if you don't intend to rebind them with 'binding'
10:42tufflaxok
10:42raekin (def r (ref ..)), r is a constant (it always points to the same ref)
10:42tufflaxi see
10:43raektufflax: anyway, there should be no difference in writing (binding [*out* ...] (print ...)) and (binding [*out* ..] (function-that-calles-print ...))
10:43tufflaxhmm, strange :p
10:44raek...unless that function was made with bound-fn
10:45raek(boudn-fn* f) can be seen as (fn [& args] (binding [...all the bound vars...] (apply f args)))
10:48raeks/metutaded/mutated/ (in one of my previous lines)
10:49tufflaxi made a new fn that prints, and it worked as you described, but not my fns in my pasted code hmm. (yes i evaluated them again)
10:49CozeyHmm. I'd like to add a template name to a compojure route - so a wrapper function can render route's response with a proper temlate... I thought maybe about using metadata for this, but I'm not sure how to implement this. any ideas?
10:50tufflaxmaybe it has to do with where they were evaluated... or something :p
10:51tufflaxi mean, defined
10:52raektufflax: yes, bound-fn remembers the bindings from the point where it is evaluated
10:53raektufflax: also, there are debuggers for clojure: http://georgejahad.com/clojure/cdt.html
10:54tufflaxI mean defined as in where the defn of the fn that prints where evaluated, all bound-fns were evaluated in the same repl
11:01tufflaxSo, to clarify: I write (ns some.ns) (defn test [] (println "dsrtd")) in a file and eval it. Then in the repl in ns some.ns i write (defn test2 [] (println "rst")). Then in the same repl (future-call (bound-fn [] (test))) does not print but (future-call (bound-fn [] (test2))) does
11:01tufflaxgotta go afk a bit...
11:08raektufflax: what does #'test return in the repl? #'some.ns/test or #'clojure.core/yesy
11:08raek*test
11:09raekI think the file was somehow not loaded correctly and you're accidentally using clojure.core/test
11:23tufflaxraek #'game.networking/test
11:25raektufflax: so calling it directly work, but (future-call (bound-fn* test)) does not?
11:25tufflaxyup
11:26raekand the body just contains (print "asdf")?
11:26tufflaxor wait, that works
11:26tufflaxbut not (bound-fn [] (test))
11:26tufflaxinside a future
11:26raekoh, of course...
11:27tufflax? :)
11:27raek(future ((bound-fn [] (test)))) expands to (future-call (fn [] ((bound-fn [] (test)))))
11:27raekthe bound-fn ends up beining evaluated in the wwring thread
11:27raek*wrong
11:28raek(let [f (bound-fn [] (test))] (future (f))) should work though
11:29raekmaybe it would be nice to have something like (bound-future ...code...)
11:29raek(defmacro [& body] `(future-call (bound-fn [] ~@body)))
11:30tufflaxbut wasnt that exactly what i did? dont u mean bound-fn*?
11:33raektufflax: which example?
11:33tufflaxthe macro
11:34raektufflax: you said that (bound-fn [] (test)) didn't work inside a future, so I assumed you were doing something like (future ((bound-fn [] (test))))
11:34CozeyHelp! I cannot (require) clojure.contrib.condition - it can't find Condition__init method but it's there in the jar (clojure 1.3). How can I deal with that?
11:35raekCozey: what toold do you use to start clojure?
11:35Cozeyit's cake
11:35Cozeybut let me check with normal repl
11:36tufflaxraek Sorry for the confusion, what I was doing was exactly what I said when i said "So, to clarify". Also i still have not understood the difference between test and test2
11:37raekhrm. there shoudn't be any difference between them...
11:37tufflax:p
11:37raek(future-call (bound-fn [] ...))) should do the right thing
11:37raektufflax: and you can call (test) and (test2) at the repl and both works?
11:38tufflaxyes
11:38raekand it's not something basic, like that you forgot to save the file?
11:39raekalso, you said this behaves differently when you are are using bound-fn* instead of bound-fn?
11:39tufflaxyes
11:40tufflaxwell
11:40tufflaxhmm
11:40raek,(macroexpand-1 '(bound-fn [] (test)))
11:40clojurebot(clojure.core/bound-fn* (clojure.core/fn [] (test)))
11:40tufflaxit gets stranger
11:41raektufflax: and you didn't miss the parentheses around (test)?
11:44tufflaxraek hmm sometimes it works and sometimes not, maybe it's vims fault http://pastebin.com/qT3VXA4Y
11:45raektufflax: another idea: try using println instead of print (and maybe even add a flush call). maybe this is a buffering issue.
11:46tufflaxit is all printlns
11:48raektufflax: does (defn test [] (println "arst") (flush)) make any difference?
11:49tufflaxno, sometimes it still doesnt show up
11:50tufflaxim getting tierd of this problem :p
11:50tufflaxtired
11:52Cozeyraek: some dependency pulled contrib 1.2 - that was the problem i think
11:54DantasHi all, reading a nice post about metaprogramming, im wondering what *ns* means (intern *ns* 'hello (fn [] println "Hello World"))
11:57andrewcleggdantas: that's your current namespace
11:57raekDantas: it's a var that contains a reference to the current namespace of the repl
11:57andrewclegguser=> (in-ns 'clojure.core)
11:57andrewclegg#<Namespace clojure.core>
11:57andrewcleggclojure.core=> *ns*
11:57andrewclegg#<Namespace clojure.core>
11:57andrewcleggetc.
11:58tufflaxSo a final question about bound-fn; what gets bound in the new function? "bindings in effect" -- things bound with binding? But im not binding anything, and apparently *out* gets bound anyway. Does every regular var count as a binding in effect?
12:03raektufflax: you didn't bind *out* yourself, but your repl runs inside a binding form that binds it
12:05Dantasraek: andrewclegg : the var symbol is *ns* ??
12:05Dantasis the var symbol *ns* ?
12:05raeksomething like (binding [*in* ..., *out* ...] (loop [] (-> (read) (eval) (println)) (recur)))
12:06Dantasthanks
12:06raekDantas: in the source code, *ns* is an ordinary symbol, just like intern and fn are
12:06Dantasyeah, thank u
12:07raekthe symbol names the var #'clojure.core/*ns*
12:08raekjust like intern names the var #'clojure.core/intern
12:09raektufflax: i.e. your repl (but not the threads you start) runs in a dynamic scope where *out* is rebound
12:13tufflaxraek ok, so not every regular var counts then
12:13tufflaxi guess that makes sense
12:14tufflaxraek ok now im gonna get on with my project. thank you very much for always helping me
12:29timvisheris clojure.contrib.logging deprecated in favor of tools.logging?
12:29stuartsierrayes
12:29timvisherawesome
12:30stuartsierraBasically, everything in the monolithic clojure-contrib is deprecated after 1.2
12:30timvisherwhat if i'm on 1.2?
12:30stuartsierraup to you then
12:30timvisherso tools.logging should work even on 1.2?
12:31stuartsierraIt should, yes.
12:31technomancytimvisher: that's what we're doing
12:31technomancyit's a lot more convenient than contrib.logging
12:37mabestechnomancy: why do you find it more convenient? isn't it the same API as contrib.logging?
12:38technomancymabes: no, it doesn't make you to call format everywhere
12:38timvisheris it easier to set logging levels in tools.logging?
12:38technomancyit takes var-args and makes a string for you
12:38technomancytimvisher: no, that is implementation-dependent. there's no way to do it across all the loggers tools.logging supports.
12:39mabestechnomancy: ah, that is nice
12:39timvishergotcha
12:40timvisherso is this information still relevent if i were to use tools.logging? http://www.paullegato.com/blog/setting-clojure-log-level/
12:41technomancyprobably. I haven't used j.u.logging or apache logging.
12:42timvishercool. thanks for the help
12:48zitchielist
12:48zitchie,(defn foo 'adsf')
12:48clojurebotUnmatched delimiter: )
12:52wastrelhi
14:46pdk,(/ 1000 16.0)
14:46clojurebot62.5
15:01gfrlog(fn [_] (do (foo) (bar))) is redundant, right?
15:03wastrelhi
15:04ataggartgfrlog: the do is redundant, yes
15:15gfrlogataggart: thanks
15:15gfrlogwastrel: hi
15:18wastrelvampire day massacre
15:18wastrelsorry connection lag
15:27bartjwhy can't this be done:
15:27bartj(fmap #(+ 1 %) (for [i (range 10)] i))
15:27chouserwhat's fmap?
15:28hiredman,(doc fmap)
15:28clojurebotNo entiendo
15:28hiredmanclojurebot: jerk
15:28clojurebotNo entiendo
15:29hiredman,(require 'clojure.contrib.generic.functor)
15:29clojurebotjava.io.FileNotFoundException: Could not locate clojure/contrib/generic/functor__init.class or clojure/contrib/generic/functor.clj on classpath:
15:29hiredman,(require 'clojure.contrib.generic.functors)
15:29clojurebotjava.io.FileNotFoundException: Could not locate clojure/contrib/generic/functors__init.class or clojure/contrib/generic/functors.clj on classpath:
15:29hiredmanbleh
15:29hiredmanthere is an fmap somewhere in contrib vaguely like that
15:29bartjhiredman, yes, I know
15:29bartj Applies function f to each item in the data structure s and returns
15:29bartj a structure of the same kind.
15:30hiredmanbartj: I wasn't pointing it out to you
15:30hiredman(for [i (range 10)] i) is redundant btw
15:31hiredmanbartj: I imagine it doesn't work because there is no fmap implemented in that library for seqs
15:32bartjhmm
15:33bartjseems strange though
15:34hiredmanfmap is not used very often, so missing functionality is too be exepected
15:35bartjraek, help?
15:35stuartsierraYou want ordinary `map`
15:39bartjstuartsierra, yes, I guess, fmap is supposed to be applied to maps, etc only
15:39bartjstuartsierra, but, I am puzzled and curious why it doesn't work in this guess
15:39bartj*case
15:39stuartsierrabecause the author didn't implement it.
15:40stuartsierra`fmap` and the other c.c.generic stuff never went through a design review.
15:40stuartsierraThey're not part of the language.
15:41hiredmanbartj: the only real advantage of fmap is it can map over values in maps, most people are likely to just roll their own
15:42hiredman,(let [a {:a 1}] (zipmap (keys a) (map inc (vals a))))
15:42clojurebot{:a 2}
15:42hiredman,(into {} (for [[k v] {:a 1}] [k (inc v)]))
15:42clojurebot{:a 2}
15:42hiredmanetc
15:43bartjstuartsierra, thanks!
15:43bartjhiredman, thank you for your time and help
15:45zakwilsonI want a library for handling HTTP requests that lets me define handlers with typed arguments and define how the string parameters get converted in to the appropriate types. I don't know of such a thing and expect I'll have to write it myself, but I figured I'd ask first.
15:46zakwilsonTo give an example of the sort of code I want to write: (defhandler foo [id :int name :string img :file] ...)
15:49hiredmanzakwilson: if defhandler is a macro you could just as easily use type hints instead of keywords, fwiw
15:51hiredmanand I would suggest just generating a function that takes a map of params or whatever and returns a map coerced to the correct types
15:51zakwilsonhiredman: Would type hints work if I wanted to make the type conversions a multifn dispatching on the name of the desired type where the return value might be an arbitrary data structure (e.g. a map representing a database row)?
15:52hiredmanzakwilson: oh, the macro would examine the tag metadata on the symbol and do the right thing, it would look like type hints to the user, but they would never make it to the compiler
15:53zakwilsonI'm also considering an optional throw-on-null - e.g. (defhandler foo [id [:int :required]] ...)
15:53hiredmanthat sounds more like validation
15:54hiredman(defvalidator foo ...) (defhandler bar ...) ((comp foo bar) some-request)
15:54hiredmaner, reverse those
15:54hiredman(comp bar foo)
15:54zakwilsonYes. I'm not sure if I should conflate validation and ensuring that the handler doesn't have to worry about types in its body.
15:54stuartsierraWhen in doubt, separate.
15:56zakwilsonSome languages treat null checks as part of the type system, and it seems like that might go well with this little island of static typing, but it does sound more flexable to have separate validators that can do anything.
16:04zakwilsonThe other question that comes to mind for me is whether and how to deal with session variables (sandbar stateful-session). My instinct is to not do it, but it could be kind of cool to have handlers take everything a web request might need to deal with as arguments.
16:06hiredmanthe functional way to do it would be with the state monad
16:07hiredmanbut mentioning that tends to make people break out in hives
16:08pjstadigclojure is not a pure functional language, you're free to use vars, atoms, etc.
16:08pjstadigthat's why they're there
16:09gfrlogthere are still best practices about when to use them though
16:09pjstadigyeah but there is no reason to have to use monads
16:10pjstadigrich took the practical road with concurrently semantic reference types
16:10pjstadigbut you're free to use monads too if you want
16:10pjstadigwhat do i care?
16:10hiredmanpjstadig: monads and mutable reference types are orthogonal
16:11pjstadighow so?
16:11pjstadigyou're talking about mutable state
16:11robbe-If I make-array an array, and share it amongst thread, the array is copied I presume? i.e. if I want to make changes that should be reflected in other threads, I could use e.g. an array of refs?
16:11hiredmangotta run, rides here
16:11robbe-threads*
16:12pjstadigan array shared amongst threads will need some kind of locking
16:13robbe-That means the array *is* shared amongst threads, and no thread-local copy is made when a thread starts
16:13pjstadigi guess you could use an array of refs, but why not a vector
16:13robbe-right?
16:13pjstadigright no copying unless you do it
16:13robbe-thanks
16:14robbe-Considering alternatives at the moment. :-)
16:15robbe-Ah, I the requirement (not set by me) is O(1) access time, and clojure documentation states: "Vectors support access to items by index in log32N hops."
16:15robbe-Which is still plenty fast, but not constant time.
16:16robbe-And I can't change the requirements because it's a school assignment. :P
16:16gfrlogrobbe-: you could argue that it is constant, given bounds on the size of the computer and all that
16:17gfrlogalthough I suppose by that argument any halting algorithm is constant :-/
16:17robbe-Indeed, but I expect the assistant to be nitpicking about it. I'll just ask to be sure.
16:17gfrlogclojure is not a good tool for school assignments that are biased against clojure
16:18raekrobbe-: I'd say: renegotiate the O(1) requirement to include the practically constant time of clojure's data structures
16:18robbe-Yeah, but you probably mean "not constant but incredibly low bound, which is in this case low enough to be considered constant." or something along those lines. :-)
16:19robbe-Thanks for the advice. :-) Will mail him shortly.
16:19raekfor a vector with 2^32 elements, the lookup requires 6 or 7 steps, IIRC
16:19gfrlogrobbe-: Also make the case that arrays are not quite constant either due to caching and paging and such
16:19raekand for hash-maps you can't have more than 2^32 distinct hashes
16:20gfrlograek: what's the collision algorithm?
16:20robbe-gfrlog: <devils advocate> but you can fix that with more ram
16:20gfrlogrobbe-: the point is that in practice the distinction is quite murky
16:21robbe-I agree. Just trying to come up with anything he might have to counter the arguments. :-)
16:21gfrlogwell I imagine it's his perogative to say "cuz I sed so"
16:22robbe-:D
16:22robbe-Well, I have to go now, it's getting late over here, so I should mail and go to bed. Thanks everyone for the input.
16:23gfrlogenjoy your time zone
16:23robbe-Surely am, 20 past 10 pm and still light outside, I like that. Winter sucks though. :-)
16:24gfrlogenjoy your latitude as well then :)
16:25raekgfrlog: I think it has a special kind of node in the tree for hash collisions that linearly searches through an array of the objects with the same hash value
16:26gfrlograek: that sounds like it would allow >(2^32) entries then, just with quickly decreasing performance?
16:26raekyeah, that's true
16:27pjstadigyes
16:28pjstadigso if you have a terrible hashing algorithm the data structure is actually log(n)
16:28gfrlogI'd think it'd be O(n)
16:29gfrlogif "terrible" means "worst case"
16:29gfrloggiven raek said "linearly searches"
16:30pjstadighehe
16:30pjstadigoops
16:30pjstadigi meant O(n)
16:30raekgfrlog: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentHashMap.java#L719
16:30raekhttps://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentHashMap.java#L784
16:31ordnungswidrig,(extend Object (ns-resolve *ns* (defprotocol Z)))
16:31clojurebotDENIED
16:31ordnungswidrig(extend Object (ns-resolve *ns* (defprotocol Z)));; this works
16:32ordnungswidrig(extend Object (ns-resolve *ns* (defprotocol Z (x [this]))){:x (constantly 42)}) ;; -> #'user/Z is not a protocol
16:32ordnungswidrigany clues
16:34pjstadigi believe defprotocol returns a symbol
16:34pjstadignot the protocol
16:35pjstadigoh
16:35pjstadigright but you're trying to resolve
16:35pjstadigah but there is a #' there
16:37pjstadigyeah add an @ in front of the defprotocol
16:37pjstadigerr
16:37pjstadigthe ns-resolve
16:37pjstadig(extend Object @(ns-resolve *ns* (defprotocol Z (x [this]))){:x (constantly 42)})
16:37ordnungswidrigpjstadig: thanks, nice catch.
16:56TimMcWell, I wrote a thing to do dynamically scoped "binding" in Java.
16:56TimMcNow I'm passing it around for my coworkers to poke holes in. :-P
17:01gfrlogTimMc: wut
17:06raekTimMc: does it use ThreadLocal? http://download.oracle.com/javase/6/docs/api/java/lang/ThreadLocal.html
18:29TimMcraek: InheritableThreadLocal, yeah.
18:30TimMcI'll see if I can get permission to post it -- I coded it on the clock, so by default it is company code.
18:30TimMcMy test rig for multi-threaded well-behavedness is amusing.
18:31TimMcgfrlog: try { LocalConfig.push("key", "val"); /* stuff */ } finally { LocalConfig.pop("key") }
19:06miwillhitehey all…anyone got an app running on Heroku yet?
19:58miwillhitehey…I'm trying to run my clojure app with `lein run -m stammer.core` (relevant files: http://pastebin.com/wfQJ3C9c)…but I keep getting the exception in the pastebin…any ideas? (using lein 1.5.2)
20:00sritchiehey all -- what protocol would I extend to cover all sequences?
20:00sritchieI had thought it would be aseq, but this misses vectors
20:01hiredmanvectors are not seqs
20:02sritchieI think iterable is what I'm looking for
20:18miwillhitecan I access environment variables in clojure? (like RACK_ENV in ruby for example)
20:18technomancy,(System/getenv "HOME")
20:18clojurebotjava.security.AccessControlException: access denied (java.lang.RuntimePermission getenv.HOME)
20:19miwillhiteawesome thanks!
20:21technomancysure
20:23__name__,(Runtime.getRuntime)
20:23clojurebotjava.lang.ClassNotFoundException: Runtime.getRuntime
20:23__name__,(Runtime/getRuntime)
20:23clojurebot#<Runtime java.lang.Runtime@12996d6>
20:24__name__,((. Runtime/getRuntime availableProcessors))
20:24clojurebotjava.lang.Exception: Unable to find static field: getRuntime in class java.lang.Runtime
20:24__name__,((. Runtime getRuntime availableProcessors))
20:24clojurebotjava.lang.Exception: Unable to resolve symbol: availableProcessors in this context
20:24__name__,((.. Runtime getRuntime availableProcessors))
20:24clojurebotjava.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn
20:24__name__,(.. Runtime getRuntime availableProcessors)
20:24clojurebot1
20:25__name__Sorry.
20:42TimMc__name__: You can also privmsg clojurebot
20:43__name__TimMc: I know.
20:43__name__I always thought it would work and wanted to share the result.
20:43__name__#scala's bot still is cooler.
20:43__name__It gives you 42 :)
20:44TimMcweird
20:52kornyhi folks - is there something like partition-by that splits a seq by a boolean fn into two seqs, rather than repeatedly splitting?
20:52korny&(partition-by odd? [1 2 3 4 5 6])
20:52sexpbot⟹ ((1) (2) (3) (4) (5) (6))
20:52kornywhereas I'd like ((1,3,5)(2,4,6))
20:53hiredman,(group-by odd? (range 10))
20:53clojurebot{false [0 2 4 6 8], true [1 3 5 7 9]}
20:53kornyhiredman: thanks
20:59picklesI am about to tear my hair out over this: (def x [obj obj]), (.method (first x)) -> true, (map '.method x) -> [nil nil]
21:01hiredmando you understand what quoting a symbol does?
21:01brehaut,(map #(.toString %) [(Object.) (Object.)])
21:01clojurebot("java.lang.Object@1c0ae76" "java.lang.Object@fde7ba")
21:02pickleshiredman: i have an idea, but no, i do not
21:02brehaut,(type 'foo)
21:02clojurebotclojure.lang.Symbol
21:02TimMc,(type '.method)
21:02clojurebotclojure.lang.Symbol
21:02TimMcgrah, I am slow
21:03brehautpickles: symbols are ifn's, so it can be passed it
21:03brehautas an argument to map
21:03brehaut,(ifn? '.method)
21:03clojurebottrue
21:03brehautbut its not a handle on a method
21:03hiredmanpickles: http://www.apl.jhu.edu/~hall/lisp/Lisp-Quote-Hints.text is written for common lisp, but similar enough
21:04brehaut,(map 'foo [{'foo 1} {'foo 2}])
21:04clojurebot(1 2)
21:04pickleswhen I do (map .terminates? x) i get an exception
21:04hiredmancorrect
21:05TimMcpickles: .method is a Java interop form
21:05hiredmanbecause the name '.terminates?' is not bound locally or globally to anything
21:05TimMcIt can't be passed around.
21:05picklesmmm
21:05TimMcpickles: However, #(.method %) can be. :-)
21:05hiredman(macroexpand '(.foo bar))
21:05picklesso i need to do a lambda
21:05hiredman,(macroexpand '(.foo bar))
21:05clojurebot(. bar foo)
21:05picklesaha
21:05picklesi c
21:08picklesmany thanks all
21:08pickleshopefully i'm through being a n00b for the day
21:16picklesrock on, it's working, thanks again!
21:52leif-pHi. Anyone know how to make clojure.pprint print metadata like (set! *print-meta* true) in the REPL does?
22:21crowbarCan someone please give me feedback on how I'm handling a point in 3d space? I'm currently trying to hold it as a map with {:x 1 :y 10 :z -4}. To simplify creation of a 3d point I have (defn point [a b c] {:x a :y b :z c}). Is this idiomatic?
22:26chousercrowbar: yep, it's fine. Also consider defrecord
22:30crowbarthanks chouser. exactly what I was after.
23:07no_mindI have some functions returning hash maps. I want to add the returned hash-maps to a sequence and return the sequence. How do I do this ? When I try to use concat or conj or cons, the returned sequence breaks hash-map elements into smaller sequqnces, something I do not want
23:08hiredmanit means you are doing something that calls 'seq' on your maps
23:08hiredman(seq {:a 1})
23:08hiredman,(seq {:a 1})
23:08clojurebot([:a 1])
23:11no_mindhiredman: yes and I want to know how to avois this ?
23:12no_mindhiredman: I want result like this ({:a 1, :b 2} {:c 3, :d4}) where {:a 1 :b 2} and {:c 3, :d 4} are returned from two different functions, lets say abc and xyz
23:22bprno_mind: (conj existing-sequence (seq hash1 hash2 ...))
23:23hiredmanbpr: nope
23:23bpr?
23:23bprthen list rather than seq?
23:23hiredmanbpr: what does seq do? how many args does it take?
23:24bpryeah then list
23:26bprlol, god i feel silly now
23:27bprhiredman: thanks for pointing that out
23:48bdeshamhi all
23:48bdeshamI'm trying to write a function like flatten, except that it works with sets instead of sequences
23:48bdeshamI came up with this: https://gist.github.com/1005837
23:49hiredman,(flatten #{#{:a} #{:a}})
23:49clojurebotDuplicate key: #{:a}
23:49hiredmanbleh
23:49hiredman,(flatten #{#{:a} #{#{:a}}})
23:49clojurebot()
23:49hiredmanhuh
23:49bdeshamit works fine, except that I'd like some way to make sure there are no duplicates in the input... for example, (flatten-sets [:a :b :a]) should generate some kind of output that lets me know there's a problem
23:49bdeshamhiredman: right ;-) I tried that
23:50hiredman,(set (remove set? (tree-seq set? seq #{#{:a} #{#{:a}}})))
23:50clojurebot#{:a}
23:50bdesham,(filter (complement set?) (rest (tree-seq set? seq (set [:a #{:b} #{:c #{:d #{:e :f} :g}} :h)))))
23:50clojurebotUnmatched delimiter: )
23:50bdeshamdamn
23:51hiredman,(set (remove set? (tree-seq set? seq #{#{:a} #{#{:a}} #{:a :b :c {:d :e :f}}})))
23:51clojurebot3
23:51bdesham,(filter (complement set?) (rest (tree-seq set? seq (set [:a #{:b} #{:c #{:d #{:e :f} :g}} :h])))))
23:51clojurebot(:c :g :d :f :e :a :b :h)
23:51bdesham,(set (remove set? (tree-seq set? seq #{#{:a} #{#{:a}} #{:a :b :c #{:d :e :f}}})))
23:51clojurebot#{:a :c :b :f :d :e}
23:51hiredmanclojurebot: seriously?
23:51clojurebotI don't understand.
23:51bdeshamlol
23:52bdeshamhiredman: that seems to do the same kind of thing
23:53bdeshambut I'd like something that would detect duplicates, no matter how deeply nested they are
23:54hiredmancreating a set removes duplicates
23:56bdeshamI guess I can check for duplicates at top level with (= v (vec (set v)))
23:56bdeshambut I could do that with distinct? just as easily
23:56bdeshamhmm...
23:58hiredmansets cannot contain duplicates
23:58hiredmanthats what a set is
23:59hiredman,(conj #{:a} :a)
23:59clojurebot#{:a}
23:59bdeshamhiredman: right
23:59hiredmanso you cannot possibly check for duplicates in a set, because there will never be any