#clojure logs

2009-04-14

00:50djkthxis there a way to return multiple values in clojure?
00:50djkthxlike with (values) in common lisp?
00:50cmvkkno, other than with lists or vectors like usual
00:51cmvkkpervasive destructuring makes this more convenient
00:51Raynesdjkthx: Return a vector of those values.
00:51djkthxalright, cool
01:30RaynesI really wish llya would fix La Clojure's identation. :\ It's annoying having to backspace 3 times after the closing bracket in a let form :|
01:36djkthxis there a way to do exponents that will automatically overflow to BigDecimal?
01:36djkthxMath/pow just overflows java.lang.Double
01:38cmvkkother than the terrible way of rolling your own pow function
01:38RaynesPOW!
01:41hiredman,(BigDecimal. 1)
01:41clojurebot1M
01:41hiredman,(.pow (BigDecimal. 3) 3)
01:41clojurebot27M
01:41cmvkk,(Math/pow (BigDecimal. 2) 2222)
01:41clojurebotInfinity
01:41hiredman,(.pow 27M 3)
01:41clojurebot19683M
01:42hiredman,(.pow 27M 10000000)
01:42clojurebotExecution Timed Out
01:42hiredman,(.pow 27M 1000000)
01:43clojurebotExecution Timed Out
01:44djkthxhmm
01:44djkthxwriting miller-rabin is proving to be a tad more complicated than i originally thought
01:50djkthxoh cool, someone already wrote it for me :P
01:51hiredmanthat always helps
06:49Lau_of_DKCompojure guys, is there a way to do (html (format "Server running on IP %s and port %s" ??? ???)) ?
06:51AWizzArdLau_of_DK: could you give me 1-3 links of the best manuals/howtos for Compojure?
08:05cemerickooh, r1350 sounds delicious!
08:08RaynesOh no. I missed r1337
08:13Lau_of_DKAWizzArd, Sorry for the late reply, all I've got is the projects wiki and their googlegroup
08:25AWizzArdoki, thx
09:47rahul Wanna get your pic on magazine cover??? http://techbuddha.blog.co.in/2009/04/14/wanna-get-your-pic-on-magazine-cover/ -- http://techmaharshi.blogspot.com/
09:50Chouserhuh. ircspam
09:50cemerickI've seen that handle before, legitimately, I think.
09:51cemerickmaybe someone's got a worm.
09:51Chouserirc seems like a pretty weak attack vector for link propogation. ...but what do I know?
09:53cemerickthat's what I've always thought about email as an advertising route for viagra...apparently, it's a very profitable biz, though.
09:53Chousergood point
11:14twopoint718,(+ 1 2)
11:14clojurebot3
11:58Drakesonhow can I create a lazy sequence of cummulative-sum of another seq? (?? [1 2 3 4]) -> (1 3 6 10)
11:59Chouserclojure.contrib.lseq-utils/reductions
11:59Chouserclojure.contrib.seq-utils/reductions
12:01Drakesonthanks :)
12:01Chousercertainly
12:04Chousercontrib's good enough for me, though I'm a bit sad it requires a build step now.
12:05Carkbah how is it a problem ?
12:05Carkyou mean for newcomers ?
12:06Chousercompiling? it's a hitch in the development cycle when fetching new or making my own changes in contrib.
12:06Carkah right
12:06Carkanyways this pprint thing is very much worth it =)
12:06rhickey_Chouser: what's changed?
12:07Chouserpprint's the main thing -- doesn't depend on any external libs, but uses gen-class internally
12:07Chouserand I want it, so I compile.
12:07dakrone_hb,(show-doc "pprint")
12:07clojurebotjava.lang.Exception: Unable to resolve symbol: show-doc in this context
12:07rhickey_it needs to use gen-class?
12:08Carki'm not sure why it does, but yes
12:08ChouserI've brought it up with Tom Faulhaber a couple times -- apparently the alternatives would be a bit messy.
12:09rhickey_can you point me to the discussion?
12:09ChouserI haven't looked at it myself.
12:09ChouserI'll try -- just a sec.
12:10rhickey_hmm.. extends Writer
12:11Chouseryeah, he wants extra state without wrapping the Writer in a separate object (struct-map or whatever)
12:11Chouserso proxying on Writer and IDeref might get you somewhere, but it also might be a bit messy
12:12rhickey_why not just close over an atom with proxy?
12:12rhickey_ctors aren't needed
12:12Carkthis reminds me of a question i had : is using proxy incuring a runtime cost as opposed to genclass ?
12:13rhickey_Cark: similar costs - there's an indirection to a fn - in neither case is the code in the method body
12:13cemerickCark: not anymore, AFAIK
12:13Carkallright thanks
12:14Chouserhere's some discussion, but I don't see a conclusion to use genclass over proxy: http://groups.google.com/group/clojure/browse_thread/thread/e51f75750da6cbb8/ab03fa5e5245194a
12:17rhickey_Chouser: thanks
12:18rhickey_:methods is evil
12:18Chouserhttp://clojure-log.n01se.net/date/2009-04-06.html#18:29
12:19Neronusload-file returns the result of the last evaluation. Is this just a coincidence and will disappear in the near future, or will it remain this way?
12:21Chouserit's hard to imagine how proxy on Writer+IDeref closing over a (mutable if necessary) Reference would be insufficient for this kind of use case.
12:21rhickey_Chouser: I don't get the IDeref part
12:21Chouserbut I haven't dug into pprint specifically to see what it would look like.
12:22rhickey_I see it as interface + proxy
12:22Chouseroh, custom interface? like gen-interface?
12:22rhickey_yes
12:22Chouserthat would do, but still requires a compile step
12:23rhickey_once and forever - just put the resulting .class in the lib
12:23ChouserIDeref gives you a kind of generic way to get at a single value -- @foo returns the value (mutable if needed) so that utility functions can do things with it
12:23rhickey_methods not inherited from interfaces are generally bad
12:24rhickey_IDeref seems like a hole in this case
12:25Chouser*giggles* you said "hole"!
12:25Chousersorry, I don't know what you mean.
12:25rhickey_in encapsulation
12:26Chouseroh. yes, definitely.
12:26rhickey_I'm kind of sad all this build stuff negates what I always saw as the simplest path - use gen-and-save-interface once and reuse the .clas sfile from then on
12:27cemerickputting classfiles in SCM is Bad(TM(TM)
12:28Chouseryes, (ns .. (:gen-class ...)) feels very static, even with the ability to change method bodies at runtime
12:28rhickey_cemerick: maybe, but consumers of interfaces shouldn't have to build them
12:29rhickey_classes and interfaces are static, and the latter especially should be highly stable
12:29cemerickwell, *someone* has to build them. contrib is not an "end user" library that people are just linking to...everyone is "building from source" when using it.
12:30Chouserif gen-interface was allowed to run at runtime (instead of just compile-time), wouldn't that solve a lot of this?
12:30rhickey_cemerick: but tho Chouser's point, if the interface def was somewhere else, he wouldn't have to recompile when working on contrib libs
12:30cemerickinsofar as it would allow one to back-door a method into a proxy, yeah
12:30Chouserthen libs that used gen-interface + proxy instead of gen-class wouldn't require a build step
12:31Chouserthe interface would be compiled on first runtime load, and you're off an running.
12:31rhickey_the whole point of an interface is that it's a contract - you don't rewrite them over and over, and thus shouldn't need to rebuild them over and over
12:32ChouserI don't want to rebuild them over and over, as I'm sure you know. I just want my call to 'require' to build whatever the lib needs on its way in.
12:32cemerickcontracts do change though, and you don't want to suddenly have a build failing for (from the viewpoint of someone who's unaware of the classfiles-in-scm approach) no reason.
12:33rhickey_Chouser: there are so many issues relating to making dynamic named classes visible everywhere you might need tham - I want to move away from that - if you need the name, it must be static - that's a java thing
12:33rhickey_cemerick: I don't see how its different from how we consume the JDK
12:33rhickey_not from source
12:34cemerickit's not -- but we're never pulling the JDK source in order to use it. We always pull contrib's source in order to use it. Working around that by putting build artifacts into source control isn't a good idea, IMO.
12:34rhickey_Chouser: the beauty of proxy is you don't care about the name - you implement the stable, named contract
12:35cemerickI always build contrib (and everything else), so I'm just a noisy observer here. :-)
12:35rhickey_cemerick: I don't want to get distracted by the .class/scm bit - that's not the real issue here. It could be built once from source - I guess it more a matter of separation - putting something stable that requires building rarely amongst the dynamic stuff
12:36Chousermany uses of gen-interface don't *really* need the name, they just need some way to point proxy at it.
12:36rhickey_Chouser: really? I don't think that's the argument he was making in the thread - i.e. he argued someone might want to know they had a column-aware writer
12:37rhickey_Chouser: I don't see how someone consumes an unnamed interface
12:39rhickey_This is really important - I'd like to see much greater usage of interfaces + proxy/implements/whatever-it-gets-called
12:39Chousercouldn't proxy theortically take gen-interface-like specs for new methods? I thought the main problem with that was just the messiness of having those kinds of declarations mixed into alogrithmic code.
12:39hiredman~gen-class
12:39clojurebotNo, hiredman, you want gen-interface + proxy
12:39rhickey_but without gen-interface raining on the otherwise dynamic parade
12:40rhickey_Chouser: how does it get consumed? via reflection?
12:40rhickey_(def x (some-proxy-making-thing-that-adds-methods)) ... (? x)
12:41Chouserhm. refelction would of course work. ...and I guess that's the only possible way. :-(
12:43rhickey_that's the crux - but interfaces are largely stable and rarely changed. defining and building them occasionally should be painless, but maybe isn't now
12:44rhickey_I really like the 'the only static/named parts are these interfaces, now have fun' model
12:46rhickey_maybe it's just splitting the build or something
12:51rhickey_and keeping gen-interface out of the lib loading process
12:59cemerickChouser: why do you need to rebuild contrib, anyway? Unless you're tweaking PrettyWriter, it shouldn't be necessary....?
13:01ChouserI guess it makes me nervous to know I have compiled .class files in a jar that are out of date with the .clj files in a directory. Does clojure do the "right thing" every time?
13:02Chouserhow stable is that behavior? do I dare rely on that to the point of accepting the half hour of confusion it will generate if my .clj changes aren't getting picked up?
13:03ChouserI suppose if that's really my primary objection then splitting the build might be sufficient. "ant build-interfaces" to make a .jar that has only interfaces, no real code.
13:04Carkmore complexity
13:05hiredmanat what price?
13:05Chousermore complexity in the build.xml, less in my head.
13:05hiredman?
13:06hiredman~whose job is it to handle Chouser's complexity?
13:06clojurebotthat is replaca's job
13:10cemerickChouser: I'm still confused. If you haven't changed PrettyWriter.clj, then the classfile it generated when you compiled it three weeks ago is still "good".
13:18Chousercemerick: but I don't compile just PrettyWriter, I run 'ant' which compiles all of contrib
13:35lispblissHow come (nil) gives a different error ("Can't call nil") than ((:type 1)) which just says NullPointerException?
13:36lispblissis it because the first error is from the reader?
13:37cp2(something ....) is trying to invoke a function
13:37cp2,(:type 1)
13:37clojurebotnil
13:37cp2you are trying to invoke nil in both examples
13:37cp2lispbliss:
13:38cp2oh
13:38cp2i see what you are asking now
13:38lispblissyeah, so I'm wondering why one gives a clear error, and the other gives a nonclear error
13:38cp2yeah, i have no idea
13:38cp2,((:type 1)
13:38clojurebotEOF while reading
13:38cp2,((:type 1))
13:38clojurebotjava.lang.NullPointerException
13:38lispbliss,(nil)
13:38clojurebotjava.lang.IllegalArgumentException: Can't call nil
13:39cp2,`((:type 1))
13:39clojurebot((:type 1))
13:39cp2er
13:39cp2whatever
13:42Chouser"Can't call nil" is when the compiler detects it
13:43Chouserit would have examined the thing to see if it's the name of a var that's marked as a macro, or if it's an expression that returns a fn, etc.
13:43Chouser...but it's just nil, so it throws an error.
13:47cp2makes sense
13:49Chouserclojure often does. :-)
13:51djkthxis there any function that converts a string->number that will automatically use BigInteger if it needs to?
13:53Lau_of_DKHey guys
13:53djkthxhowdy
13:53cp2djkthx: there are no string->number functions in the clojure api. the java api has Integer.parseInt(...) and such
13:53cp2not sure if those will automagically convert, but i assume not
13:54djkthxyeah, they don't
13:55cp2so then, you will probably just have to play it safe and just use BigInteger
14:00Chouser,(class (read-string "9876543210000000000000"))
14:00clojurebotjava.math.BigInteger
14:01Chouserbut I'm not sure I'd trust read-string with unsafe data
14:02Chouser,(read-string "#=(java.lang.System/exit 0) 99")
14:02clojurebotjava.lang.RuntimeException: java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM.0)
14:02Lau_of_DK,(class (read-string "987654321000000000000898324098230948230940239840923804982304982394839888888888888888888888888888888888888888888882039482309842039840239840928340980"))
14:02clojurebotjava.math.BigInteger
14:02Lau_of_DK,(class (read-string "9876543210000000000008983240982309482309402398409238049823049823948398888888888888888888888888888888888888888888820394823098420398402398409283409809876543210000000000008983240982309482309402398409238049823049823948398888888888888888888888888888888888888888888820394823098420398402398409283409809876543210000000000008983240982309482309402398409238049823049823948398888888888888888888888888888888888888888888820394823098420
14:02Lau_of_DK39840239840928340980"))
14:02clojurebotEOF while reading string
14:03Lau_of_DKNo integeroverflow?
14:03stuhoodyour irc client split that into 2 lines
14:04djkthxoh
14:04djkthxnice!
14:04djkthxthanks Chouser
14:04cemerickSorry, lunch interrupted. :-)
14:04cemerickChouser: even so, PW.class won't be modified unless PW.clj has a newer moddate on it than PW.class
14:04technomancyis there really no recursive delete for directories in Java?
14:05cemerickAll I'm saying is, if you're in a REPL, there's no need to bounce it unless PW.clj changes (or, probably more specifically, unless PW.clj's :gen-class spec changes).
14:05technomancyI'm not finding anything, but I'm having a hard time believing that they left something like that out.
14:05cemericktechnomancy: nope. That's what libraries are for, I guess. :-/
14:05technomancywow.
14:06technomancyit boggles the mind.
14:06kotarakmost programming languages don't have a recursive directory delete built-in...
14:07technomancyI guess that's why I don't program in most lanugages. =)
14:09kotaraktechnomancy: apache commons... FileUtils.deleteDirectory
14:09cp2technomancy: JSR 203(?) has much better fs operations, etc
14:09cemerickThere's also a very nice filesystem API in the netbeans platform.
14:09cp2but thats due in java 7, so...
14:10cemerickcp2: wasn't that (effectively?) on hold?
14:10cp2cemerick: im not sure, i havent looked _too_ much into it, i just know that it provides some better io operations
14:12technomancycp2: ah, the jdk7. sounds like it's got a lot of good stuff.
14:12cp2yeah, seems interesting
14:32Chouserrhickey said something about eventually targetting Objective C, to allow writing Clojure for iPhones. But there's no GC there, right? How's that going to work?
14:33djkthxobjc2.0 has a gc
14:33djkthxi don't know if that's what the iphone supports now
14:33djkthxbut the standard one for osx development has a gc now
14:35Chouserah, interesting.
14:36djkthxthat would be quite cool if something comes of it
14:38Hunthe iphone can't use the GC. you have to use ye olde refcounting there
14:38djkthxreally? that sucks
14:39Hunobjective C is pretty usable even without a gc. you have autorelease-pools
14:39Hunwhich decrease the ref just a bit later
14:39djkthxi've done some objc development myself
14:39djkthxbefore the gc, and it wasn't too bad
14:40djkthxi'm saying it sucks in the context of having clojure target objc
14:40Huntrue
14:54hiredman~botsnack
14:54clojurebotthanks; that was delicious. (nom nom nom)
14:59cp2objc, yuck
15:04Lau_of_DKIs there any way to do hard realtime with the jvm ?
15:06djkthxi remember reading about it in an acm crossroads issue
15:06djkthxi believe
15:15danlarkinhiredman: https://twitter.com/clojurebot/status/1518882399 ha
15:15hiredmandamn
15:16hiredmanI was hoping to delete that before anyone noticed
15:23danlarkinI'm too quick!
15:24cp2heh
15:36stuhoodi'm going to be hurt if clojurebot doesn't follow me back =P
15:39cemerickwow, contrib has really grown since I took a big-picture look at it some time back!
15:47durka42kotarak: does vimclojure require ivy now?
15:47kotarakdurka42: at the moment, yes, but it will optional in the future.
15:48kotarakJust working on the setup
15:48durka42maybe i should stay off the bleeding-edge branch for a little bit :)
15:48durka42or if i install ivy somewhere, will it work?
15:48kotarakdurka42: it should.
15:49kotarakdurka42: try the commit I just pushed.
15:49kotarakIt will download the ivy.jar for you. Put it in ~/.ant/lib and you should be fine for the future.
15:49kotarakBeware, that it will also try to download clojure and parts of contrib.
15:49durka42um
15:49kotarakThis is still in the "future" part.
15:50durka42ivy NPE'd
15:50kotarakHmm.. Let me check.
15:50kotarakJust a sec.
15:50durka42in Hashtable
15:53kotarakHmmm... It works for me. Which Java do you use? I just installed soylatte, so this is maybe in issue?
15:54kotarakdurka42: when does it segfault? At which step?
15:55kotarakHmm... works also for stock Java on OSX:
15:55lisppaste8durka42 pasted "kotarak" at http://paste.lisp.org/display/78569
15:58lisppaste8durka42 annotated #78569 "verbose mode" at http://paste.lisp.org/display/78569#1
16:04kotarakdurka42: can you try to remove the cache (rm -r ~/.ivy2/cache) and try again? This is just guessing, but the problem doesn't show up here.
16:04kotarakdurka42: I updated the ivysettings.xml on the server.
16:04durka42all right, i'll remove that directory and pull
16:05kotarakdurka42: I mean the kotka.de/ivy/ivysettings.xml. The xml in the repo includes that one.
16:05durka42i just discovered what you meant
16:05durka42it's downloading clojure
16:05durka42so that's a good sign
16:06durka42ech
16:06durka42BUILD FAILED
16:07durka42 /Users/alex/Programming/vimclojure/build.xml:54: java.lang.NoSuchMethodError: clojure.lang.MultiFn.<init>(Lclojure/lang/IFn;Ljava/lang/Object;Lclojure/lang/IRef;)V
16:07durka42worked after ant clean
16:10hiredmanok
16:10hiredmanhas anyone here written some clojure that can post to twitter without using anything besides what comes with the jre?
16:11hiredmanthis is killing me
16:15dakrone_hbcan someone give me an example of how 'while' is used, I can't find any examples and I'm trying to do (while [line (.readLine stdout)] <dosomestuff>
16:17hiredman http://gist.github.com/95395 this is what I have, and it doesn't work
16:17hiredman,(doc while)
16:17clojurebot"([test & body]); Repeatedly executes body while test expression is true. Presumes some side-effect will cause test to become false/nil. Returns nil"
16:17hiredmandakrone_hb: use line-seq
16:18hiredman,(doc line-seq)
16:18clojurebot"([rdr]); Returns the lines of text from rdr as a lazy sequence of strings. rdr must implement java.io.BufferedReader."
16:18kotarakdakrone_hb: How about: (doseq [line (line-seq *in*)] ...)
16:18dakrone_hbhiredman, yea, I read the doc, hence my code, I get " Unable to resolve symbol: line in this context"
16:18hiredmandakrone_hb: because you are doing it wrong
16:18dakrone_hbhiredman, kotarak doesn't that read the *entire* thing into memory before grabbing a single line?
16:18hiredmanwhile is not a loopish binding form
16:19dakrone_hbI'm trying to write an equivalent to Chouser's shell-out that won't load the entire stdout into memory for million-line output
16:19hiredmandakrone_hb: please read the line-seq docstring
16:20dakrone_hbhiredman, I read it, I just don't exactly understand what "lazy" means in terms of memory-management, etc. In the implementation, this won't kill the memory, right?
16:20dakrone_hbI also have no doubt that I'm doing it wrong :)
16:20hiredmanlazy means it creates a seq of readLine calls
16:21hiredmandakrone_hb: while doesn't take a binding form
16:21hiredmanwhile takes a predicate
16:21dakrone_hbif it creates a seq of 1m readLine calls, won't that still take up 1m * (size of readline call) in memory?
16:21hiredmandakrone_hb: lazy-seq
16:21dakrone_hbor does it not do the entire length at once?
16:21hiredman*lazy* seq
16:23dakrone_hbI only know what *lazy* means from a somewhat conceptual perspective, not from an implementation perspective, like I said, so do you have any good resources I can read about the _exact_ meaning of 'lazy'?
16:23hiredman,(let [a (atom 0)] (while (> 10 @a) (swap! a inc)) (println @a))
16:23clojurebot10
16:23hiredmandakrone_hb: lazy means you do it later
16:23dakrone_hbright now 'lazy' is a word associated with lisps that means "good performance for some things" to me
16:24hiredman*snort*
16:24hiredmanlazy has nothing to do with performance
16:24dakrone_hbsee? I knew I was mistaken somewhere :)
16:24stuhooddakrone_hb: it means that the next item in the sequence is actually a function that can generate the result
16:24dakrone_hbokay, so it's just putting off the evaluation
16:25dakrone_hbfrom a memory-perspective, none of this is loaded in advance, right?
16:25stuhooddakrone_hb: and the function itself isn't generated until you ask for it
16:25dakrone_hbalright
16:26stuhooddakrone_hb: a sequence in memory is (current_item, fn for next item)
16:26dakrone_hbso very memory efficient then
16:26stuhoodyea
16:26stuhoodexcept for the weird "holding onto the head case" where every item that has already been generated gets cached and stays in memory
16:26dakrone_hbthat brings me to the next question, if I rebind *in* to be my buffered reader, will I run into problems in a threaded program that expects the default value of *in* to be there since it's global?
16:27dakrone_hbstuhood, oh, so once it's generated, is it going to be stored?
16:27hiredman,(doc binding)
16:27clojurebot"([bindings & body]); binding => var-symbol init-expr Creates new bindings for the (already-existing) vars, with the supplied initial values, executes the exprs in an implicit do, then re-establishes the bindings that existed before."
16:27hiredmanhuh
16:27dakrone_hbso if I have a lazy-seq of 1m items, once they're all generated, will they still all be in memory?
16:27hiredmanonly if you hold on the head of the sequence
16:27stuhooddakrone_hb: only if you keep a copy of the sequence pointing at an earlier item in the list: it is effectively a linked list, so any pointers you hold onto will cause the remainder to stay in memory
16:28hiredmananyway
16:28hiredmanbinding is thead local
16:28hiredmanthread
16:28dakrone_hbso if I have it in a doseq that calls a function with the line as an argument, that isn't keeping a copy when it goes to the next line, right?
16:28dakrone_hbhiredman, okay, thanks for clearing that up
16:28kotarakdakrone_hb: burning yourself with concurrency is hard in Clojure...
16:29stuhoodno, doseq explicitly doesn't hold onto the head
16:29hiredman,(binding [*out* (java.io.StringWriter.)] (println :foo) *out*)
16:29clojurebot#<StringWriter :foo >
16:29hiredmanwhich is effectively what print-str does
16:29hiredmanor pr-str or whatever it's called
16:30dakrone_hbhiredman, okay, that's elegant then
16:30dakrone_hbI will do it that way, thanks hiredman, kotarak, stuhood
16:30dakrone_hbplease excuse my ignorance :)
16:33dakrone_hbso, another question, why would you want a non-lazy sequence over a lazy-sequence in some cases? Because you want to lock down the value of the sequence?
16:34kotarakWhat is a "non-lazy sequence"?
16:35kotarakThere might be cases, when external resources are involved, that you want to do a "doall" on the seq.
16:35dakrone_hbokay, that makes sense
16:38kotarakdakrone_hb: for example: (with-open [some-file (open-some "file")] (doall (line-seq some-file))) When you access the sequence produced by line-seq the file will already be closed by the with-open. Hence you need the doall in such a situation.
16:39dakrone_hbokay
16:39dakrone_hbthat's a good example
16:39dakrone_hbthanks!
16:40hiredmanso
16:40hiredmananyone want to fix my twitter?
16:43HunMan Builds Chair That Tweets His Farts, Single-Handedly Justifies Twitter's Existence
16:53stuhoodkotarak: that won't hold onto the head, will it?
16:54kotarakstuhood: what?
16:54stuhoodyour last example for dakrone
16:54kotarakIt will, but without doall it will blow up.
16:55kotarakYou must not leak a lazy-seq outside of the scope of the resources it uses.
16:55stuhoodnothing holds onto the lazy seq returned by line-seq though
16:55stuhoodoooh
16:55stuhoodsorry, i was missing the context
16:55kotarakstuhood: this is just a snippet.
16:56kotaraksomething outside might use the line-seq
16:56stuhoodyea, great example... apologies
16:57hiredmanlisppaste8: url?
16:57lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
16:58lisppaste8hiredman pasted "with-open-proc" at http://paste.lisp.org/display/78573
17:02dakrone_hbhiredman, so would you use that like (with-open-proc "ls -l" stdin stdout stderr (doseq [line (lazy-seq stdout)] (println line))) ?
17:02hiredmanuser=> (with-open-proc "echo hello world" [out in er] (apply str (line-seq out)))
17:02hiredman"hello world"
17:02hiredmanuser=>
17:03dakrone_hbawesome, thanks for the example on how to use it correctly
17:03hiredmanor (with-open-proc "echo hello world" [out _ _] ...) if you are ignoring in and er
17:04stuhoodjust watch out that you start a thread to read from stderr if you are going to block reading on stdout
17:04dakrone_hbis _ a keyword for discarding the value then?
17:05slashus2Just an idiom for an argument that is not used.
17:05stuhoodits a convention, but i don't think it does anything special to the variable
17:06lisppaste8kotarak annotated #78573 "More flexible approach" at http://paste.lisp.org/display/78573#1
17:07dakrone_hbwhat makes that one more flexible, it looks about the same in function
17:07dakrone_hb?
17:08kotarakdakrone_hb: When you update the function, you have the updated version immediately.
17:08kotarakdakrone_hb: with a macro every user must be recompiled.
17:08kotarakdakrone_hb: functions can be map'd, apply'd, etc.
17:08kotarakdakrone_hb: although this is not very interesting in this case...
17:09dakrone_hbokay, that's really useful
17:10dakrone_hbby the way, how does something get into clojure-contrib, it seems like that would be a useful macro to go into the contrib
17:10kotarakdakrone_hb: one example is binding: I really needed binding* because I want to build the Var/Value pairs programmatically. But there is no binding*. Only the binding macro. So I have to re-invent binding* everywhere....
17:14dakrone_hbokay, I think I understand
17:15Chouserthere may be performance consequences for a thunk like that, which might matter for something like binding. for shelling out, though, it should be fine. :-)
17:17kotarakHmm... I was always told that creating a fn in Clojure is fast...
17:17slashus2(with-open-proc "ls -la" [out _ _] (line-seq out)) This doesn't work?
17:17hiredmanline-seq is lazy
17:17Chousersure it's fast, as is calling one. But is creating and then calling a function likely to be faster than doing neither?
17:18hiredmanso the iostream has been closed by the time you go to read it
17:18slashus2(with-open-proc "ls -la" [out _ _] (doall (line-seq out)))
17:18slashus2this works
17:18hiredmanso you need to a. do the work inside with-open-proc b. use doall
17:18slashus2Yup, I got it.
17:19lisppaste8dakrone_hb annotated #78573 "kotarak's with fixed gensyms" at http://paste.lisp.org/display/78573#2
17:19hiredmanerm
17:19hiredmanyou cannot use gensyms like that
17:20hiredmanor unquote in the function
17:20kotarakChouser: ok. Of course not calling a function is faster than creating and calling one. When binding is used really in low-level stuff, it might be reasonable. I still miss binding*. And I still think speed is overrated....
17:20dakrone_hbhiredman, are you talking about the annotation?
17:20hiredmanyes
17:21dakrone_hbwithout it was getting Unable to resolve symbol: proc in this context
17:21clojurebotthis is not a bug
17:21dakrone_hboh, should the bound proc# just be proc instead?
17:21slashus2yes and there shouldn't be a ~ in front of cmd
17:22kotarakdakrone_hb: oops. the proc# and ~cmd in my version where cut'n'paste errors. Should be w/o # and ~.
17:22lisppaste8hiredman annotated #78573 "actually fixed" at http://paste.lisp.org/display/78573#3
17:22dakrone_hbhiredman, thank you for the correction
17:24hiredmanactually
17:24hiredmanstill doesn't work
17:24hiredmanoh
17:24hiredmanI was using it frong
17:24hiredmanwrong
17:25hiredmanthings are completely different, but the same
17:26kotarakNothing is more lasting than change.
17:28dakrone_hbis not being able to use that for something like "ls -l | grep r*" a java thing then?
17:29dakrone_hbI think I remember not being able to do that exec-ing things from Java before
17:29kotarakthe pipe (|) is a shell thing.
17:29stuhoodand the *
17:29dakrone_hband since it doesn't spawn a shell, no piping
17:29kotarakYou will have to build this on your own.
17:29waltersor exec /bin/sh -c "whatever"
17:29kotarakEg. scsh does this. (| (cmd1) (cmd2) (cmd3)) .....
17:30hiredmanso no dice on my non-working twitter code?
17:30waltersif you want shell script, run a shell
17:30hiredmanwalters: makes sense to me
17:30dakrone_hbokay, thanks
17:30cp2scheme shell eh
17:30cp2interesting
17:33Chouserwould you want with-open-proc to bind *in* *out* and *err* for you?
17:34hiredmanno
17:34hiredmanmaybe err
17:34Chouserno, you're right. it's all backwards
17:34kotarakcp2: scsh is quite nice. I always suffered from the limited library problem, though...
17:35cp2im not sure i love scheme enough to use it as my primary shell
17:35stuhoodhiredman: i don't think you flush your streams
17:35kotarakcp2: Well... It's not for interactive use, but for scripts.
17:35cp2oops, didnt think of that
17:36cp2yeah, in that case, woosh; awesome
17:36hiredmanstuhood: I disgree on principle, but I am willing to add a .flush
17:36cp2then again you can kinda-sorta use clojure for the same reason
17:36cp2witht hat whole metadata hackish thing :
17:36Chouseryou might, however, find yourself doing (with-open-proc "foo" [out in err] (binding [*out* in] (println ...) (line-seq out) ...))
17:37hiredmanChouser: you might
17:37hiredmanChouser: you might not
17:37Chouserright
17:40hiredmanyou could provide *proc-in* *proc-out* *proc-err* and just have with-open-proc bind those
17:44hiredmanflushing the streams does nothing
17:44hiredmanthe error I am gettting is 401 which is not authorized
17:44stuhoodyea, i'm seeing that now
17:45stuhoodjavadocs say you actually need to call .connect at some point
17:46hiredman*shrug*
17:46stuhoodnevermind, same thing
17:46hiredmanthis is code is based on reading the java source of 4 or 5 different java implementations that were basically the same thing
17:49hiredmanhttp://www.psychicorigami.com/2008/12/22/a-5k-twitter-client/ this client is pretty impressive
17:50hiredmanwhich, ah, thats right, I was looking at the source when this computer fell offline yesterday and I lost my state
17:53stuhoodhiredman: i found one issue, but it didn't solve the problem: the space between "Basic" and creds is missing
17:54hiredmanyeah, I tried that too
17:54hiredmana lot of the java code did not put a space their either
17:55hiredmanthere
18:08hiredmanwell, now it's changed to a 403
18:12stuhoodoh? i'm still seeing 401
18:16stuhooder...
18:17stuhoodthat code appears to work, but i was using the wrong password
18:17stuhood*facepalm
18:22hiredman:(
18:22stuhoodyou too?
18:22hiredmanno
18:22hiredmanI am still getting a 403 now
18:25stuhoodi also removed the 's' from https
18:27stuhoodshoot... it was the flush
18:30stuhoodhiredman: i added a flush after the write, before reading: http://gist.github.com/95473
18:35hiredman!
18:35hiredmanstuhood: thanks!
18:53twansithmm ...is there a global modifier for regexes?
18:54twansitor am i missing something
18:55cmvkkwhat do you mean by that
18:55cp2i think he means like
18:55cp2s/..../..../g
18:55cmvkkoh, so #"..." ?
18:55cp2no, in perl regexs //g implies a global search
18:56cp2meaning if it finds one match it wont stop, it will search the rest of the string too
18:56cmvkkohhh, now i understand. a global modifier.
18:56twansit#"(?i)... thats the insensitive case
18:56twansitbut i found a solutiong though
18:56twansitusing re-gsub
18:56twansitin contrib
18:57twansitthanks for your time
18:57cp2yep
19:02hiredmanwhoops
19:46dysingerhelp plz
19:47dysingerHow can I access a static member of a static class of an interface ?
19:47dysingerhttp://www.rabbitmq.com/releases/rabbitmq-java-client/v1.5.4/rabbitmq-java-client-javadoc-1.5.4/com/rabbitmq/client/AMQP.PROTOCOL.html
19:47dysingerI need com.rabbitmq.client.AMQP.PROTOCOL.PORT
19:48dysingerAMQP is an interface, PROTOCOL is a class of the interface and PORT is a static member of PROTOCOL
19:48dysingerI tried com.rabbitmq.client.AMQP/PROTOCOL/PORT
19:48dysingerbut no luck
19:48dysinger(import '(com.rabbitmq.client.AMQP.PROTOCOL)) blows out too
19:49dysingerleave it to erlang programmers to write a java interface :P
19:50dysinger!clojurebot do something
19:50dysinger:)
19:52dysingerIt looks to me like I have stumped clojure
19:53dysinger:D
19:53dysingersomeone tell me "your doing it wrong" plz
19:53arohnerdysinger: have you tried (import '(com.rabbitmq.client.AMQP.PROTOCOL))?
19:53arohnerand do you know that everything is in your classpath?
19:53dysingery above
19:53dysingeryes have a good classpath
19:54arohnersorry, misread your comment about trying exactly what I suggested. :-)
19:54dysingeruser> (import '(com.rabbitmq.client.AMQP))
19:54dysingernil
19:54dysingeruser>
19:54dysingerIt's an "self-contained" interface
19:54dysingerhow tricky of them
19:54arohnerreturning nil on import is good
19:55arohneryou get exceptions when things blow up
19:55dysingery tells me classpath is fine
19:55arohneruser=> (import 'foo.bogus)
19:55arohner(import 'foo.bogus)
19:55arohnerjava.lang.ClassNotFoundException: foo.bogus (NO_SOURCE_FILE:0)
19:55dysingerbut I have no access to static classes of that interface
19:55dysingerblows up
19:56arohnerwhat is the error on just evaluating com.rabbitmq.client.AMQP.PROTOCOL/PORT ?
19:56dysingerIt may just be that rhickey didn't see this one coming. He's smart though I better knock on wood or be hit by lightning.
19:57Carkdysinger if i refer to your description it would be something like : com.rabbitmq/AMQP$PORT/PROTOCOL ?
19:57dysinger(import 'com.rabbitmq.client.AMQP.PROTOCOL) -> class not found
19:57dysingeroh that's right
19:57dysingerthe $
19:57dysingerI have been gone from java too long
19:57dysingerlemmie try that.
19:57Carki missed a part of it
19:57Cark.client
19:58dysingerbingo
19:58dysingeruser> com.rabbitmq.client.AMQP$PROTOCOL/PORT
19:58dysinger5672
19:58dysingeruser>
19:58dysingerfugly but works
19:58Carkeasy on the eye =P
19:58dysingerthanks guys
19:59arohnersorry for my fumbling. What does the $ mean?
19:59Cark$ is to access contained classes
19:59Carkinternal classes ?
19:59dysingery
19:59Carkdon't know how they call these in java
20:00dysingerstatic inner class in this clase
20:00dysingercase
20:00dysingersorry public static inner class
20:00dysingerYou don't see that everyday
20:00dysingertis why I was joking around about the erlang devs writing a java client.
20:01arohnerand you can tell that because the javadoc declares that com.rabbitmq.client.AMQP has a static class AMQP.PROTOCOL member?
20:01dysingery
20:01dysingernormally you don't see a lot of interfaces with inner classes
20:01dysingerIt's a hack that it works IMO
20:02Carkthough nothing as bad as this enumeration nonsense they came up with
20:02dysingerwho Sun ?
20:02Carkyes
20:03dysingerif (enum.iCanHasNextCheesburger)
20:04dysingery i am happy to write clojure code - won't be going back to java any time soon.
20:04dysingerspent 3 nice years doing ruby and lisp / erlang
20:04dysingerafter 10 on java
20:04dysingereye opener
20:05Carki found erlang pretty annoying because of its syntax
20:05arohnermy day job is in Ruby now. I can't stand it, esp compared to clojure
20:06djkthxerlang is fun, but i'm a little used to the syntax thanks to prolog
20:06Carkah right
20:07dysingerI use the Lisp Flavored Erlang syntax
20:07dysingerwhich is fun
20:07rhickeyarohner: sorry I missed your question the other day - I think some sort of external/gradual typing could be interesting
20:08Carkrhickey : you mean as a library ? or as an external tool ?
20:09Carksome kinde of preprocessor (yuk!)
20:09arohnerrhickey: np
20:10arohneryeah, I find it interesting as a nice way to catch bugs. I find myself writing assert a lot to catch things that could be caught by typing
20:10rhickeyCark: just an analyzer that can tell you when things are type-inconsistent or undecidable without necessarily preventing your program from running
20:11Carklooks like one hell of a work
20:13arohnerCark: it doesn't have to be
20:14arohneryou "just" attach metadata to objects as they're used
20:14Carkbut that would be at runtime then
20:15Carki thought the point was to have "compile time" errors ?
20:17arohnerbut clojure resolves symbols at compile time
20:17Carkdon't you need to go check inside functions for type errors ?
20:17djkthxhow can you do optional arguments in defn?
20:18djkthxlike &optional (val 3) ...
20:18djkthxin common lisp?
20:18Carkdjkthx : use a map
20:18Carkerr no
20:18Cark(defn bleh [arg1 & args] ....
20:19djkthxdoesn't that just bind everything to a list called args?
20:19Carkeverything but the first one
20:20Carkyou could also do (fn blah ([arg1] body here) ([arg1 optional-arg2] body here))
20:20arohnerCark; start with the basics. Assume you know how to infer type errors on just simple functions, like +
20:20arohnerso if the compiler sees (+ foo bar), you can infer that foo and bar should both be numbers
20:21arohnerso if you see (assoc foo :key 42), then you can say "hmm, that looks weird. previously foo was used as a number, and now it's being used as an associative"
20:21Carkyou still need a code walker for that very first step
20:22Carkthen you need to go meta for function results ...then you have macros ...
20:22Carkseems like a mountain to me =P
20:22Carkanyways i would gladely use it of someone writes it
20:32arohnerdysinger: it does bind everything to a list called args. You can use let's destructuring to pull arguments out of the list, or write a macro
20:32dysingeryou meant djkthnx
20:33arohneryup, sorry
20:33djkthxyeah, that's what i was planning to do
20:33djkthxi'm just really used to common lisp
20:33arohnerdjkthx: check out deftmpl in compojure.control
20:33djkthxso i periodically ask how to do things that i would normally do in CL
20:34arohneryou can define things that are called like (foo :bar 1 :baz 2)
20:35djkthxah, cool
20:52msingh`why doesn't clojure have erlang style pattern matching?
21:12msingh`seems to me being able to pattern match atoms is a pretty useful thing and cl already had destructuring so what progress has clojure made in this respect?
21:20dnolenmsingh: do multimethod not work for you?
21:22msingh`dnolen: haven't looked at htem yet.. i'm watching a podcast where the person mentions not being keen on patern matching except the destructuring aspect
21:23dakrone_hba clojure podcast?
21:23msingh`yeah
21:23cmvkki believe that's why, actually. rich hickey doesn't care for them that much.
21:23msingh`it's by the author, 'clojure for lisp programmers'
21:25dakrone_hbmsingh`, http://pragprog.com/podcasts/show/24 this one?
21:25msingh`dnolen: are you suggesting that mms allow you to pattern match by value of parameters?
21:25dakrone_hbjust curious where it was
21:26dnolenmsingh: it can, your dispatch-fn can just return the value of the params.
21:26cmvkkmsingh`, multimethods allow you to match by anything you want.
21:26msingh`dakrone_hb: nope, one sec i'll get the url for you.
21:27msingh`oh that sounds cool!
21:28msingh`dakrone_hb: http://blip.tv/file/1313398
21:29dakrone_hbmsingh`, cool, thanks!
21:30msingh`np :) there is part 2 too, i've been watching it on the train on a shuffle.
21:31dakrone_hbyea, these are the ones from the clojure page right?
21:32msingh`yeah
21:40hiredmanclojurebot: http://clojure-log.n01se.net/date/2009-04-14.html#12:06 remember this
21:41hiredmanclojurebot: you are here right?
21:41clojurebotTitim gan �ir� ort.
21:44hiredmanclojurebot: http://clojure-log.n01se.net/date/2009-04-14.html#12:06 remember this
23:00dysingerWhat benefits do you get by having json in json contrib instead of just using a json lib in java like .org.json ?
23:00dysingersorry json in clojure.contrib
23:00dysingerprobably it understands clojure better
23:00dysingerto answer my own question
23:00danlarkindeals in native clojure datastructures
23:06dysingery
23:06dysingeralready using it.
23:06dysingerslick
23:07dysingerwhat does it mean when I get "java.lang.IllegalArgumentException: No matching ctor found for class" trying to define a simple proxy of an interface
23:07dysinger?
23:09Chouserprobably passing the wrong number or wrong types of args to the base class constructor
23:25dysingerhmmm
23:25dysingerbingo
23:33dysingertanks chouser
23:51dysingeruser> (json-str "hello")
23:51dysinger"\"hello\""
23:51clojurebotBUENOS DING DONG DIDDLY DIOS, fRaUline dysinger
23:51dysingeruser> (json-str :hello)
23:51dysinger"\"hello\""
23:51dysingeruser> (json-str 'hello)
23:51dysinger"hello"
23:51dysinger^^ broken ?
23:52dysinger"hello" isn't a json encoded string
23:52danlarkin(json/encode-to-str 'hello)
23:52danlarkin,(json/encode-to-str 'hello)
23:52clojurebotjava.lang.Exception: No such namespace: json
23:52danlarkin,(org.danlarkin.json/encode-to-str 'hello)
23:52clojurebot"\"hello\""
23:54dysingercool
23:55dysingeralso contrib's json feels clunky
23:55dysinger(read-json-string (json-str (str *ns*)))
23:55dysinger"user"
23:56dysinger(clojure.contrib.json.read/read-json-string (clojure.contrib.json.write/json-str (str *ns*)))
23:56dysinger,(clojure.contrib.json.read/read-json-string (clojure.contrib.json.write/json-str (str *ns*)))
23:56clojurebotjava.lang.ClassNotFoundException: clojure.contrib.json.read
23:58dysingerIf I hadn't read the comments, I would think two different people wrote the read / write.
23:58dysingerIt doesn't feel unifrom
23:58dysingeruniform
23:59dysingerunless it's some lisp-y idiom I don't get
23:59dysingerprobably why there are 2 or 3 other json libs for clojure on github