#clojure logs

2010-09-22

00:17laurusWhat is the best way to automatically wrap a block of Clojure code inside a function from the command line?
00:20tomojwhat does that mean?
00:20Rayneswut
00:20laurusSo what I want to do is this
00:20laurusI want to create a new cljr option
00:20laurusSay, cljr hello
00:20laurusSo I can run "cljr hello filename.cljr"
00:21laurusEr, .clj
00:21laurusAnd it will take that .clj file and evaluate it, but inside another function
00:21laurusAnd return the result to that function for the final processing.
00:22tomojjust load the file?
00:22laurustomoj, what do you mean? Heh
00:22Raynesload-file
00:22laurusRight, but how do I create that additional cljr command?
00:23laurusRaynes, the reason I phrased the question the way I did the first time was because I assumed it might be difficult to do that, and I could do it with one of the existing commands using some kind of tricky syntax :P
00:23laurusSuch as passing the function itself in on the command line as an argument, and then utilizing it from within the program somehow.
00:24laurusHey, thanks ;)
00:24laurusI'm mainly using Incanter so I don't need a complicated system right now
00:24RaynesHrm.
00:25Raynescljr doesn't appear to have any sort of extension mechanism.
00:25laurusRaynes, I know you can do this with leiningen. See here: http://github.com/markmfredrickson/changeling/blob/master/project.clj
00:25RaynesAnd cake. Very easily with cake, even.
00:25laurusHe just defined a new function, and then one can run "cljr changeling"
00:25laurusHehe what does that whistling imply?
00:25RaynesIt implies that I almost did what I said I wouldn't do. ;)
00:26laurusWell
00:26laurusIs it possible with cljr?
00:26RaynesYou'd probably have to fork the repository and add it yourself. I'm pretty sure cljr isn't made to be extended like that.
00:27laurusHmm, okay.
00:27laurusBut cake is, huh?
00:27laurus;)
00:27laurusDo I have to create a project with cake? I don't really need projects since everything I do is one giant project, so to speak
00:27Raynescake has a thing called "the global project" and you can add tasks to that, so no.
00:27laurusOh, neat
00:28laurusI'm just kind of annoyed by all of these various build systems
00:28RaynesIt explains it in the README.
00:28laurusI'm sick of switching between them all the time as well :P
00:28RaynesCake is fairly leiningen project compatible.
00:29laurusI also like how cljr is a jar
00:29RaynesWell, cake kind of is too.
00:29laurusOkay, here's what I'm really trying to do, at a high level
00:29laurusI'm close to being done with an alternative Clojure script for org-babel
00:29RaynesThe Ruby stuff is just for bootstraping and launching
00:29laurusThat doesn't require swank or SLIME
00:30laurusBut I'm stuck at the final part, which is actually getting the return value from the Clojure code into the output buffer
00:30laurusSo the way I decided to do that was wrap the Clojure code in a "print out" function
00:30laurusI.e., clojure.contrib.duck-streams/spit
00:30laurusBut the trick is, how to wrap it.
00:30RaynesWhat version of Clojure are you using?
00:30laurus1.2.0.
00:31Raynesspit is in clojure.java.io now.
00:31laurusOh, cool, thanks for that tip :)
00:31RaynesActually, it's in core.
00:31laurusSo you would recommend switching the build system to one that is extensible.
00:32RaynesWell, you'd have to look at cake and Leiningen to decide for yourself, but I believe that most of what you can do with cljr, you can also do with cake.
00:32RaynesEspecially with the global project.
00:32laurusOkay, cool!
00:32RaynesIt's worth checking out and seeing if it'll do, anyway.
00:33laurusWait, one other question
00:33RaynesCake isn't really a build system. It's just a REPL and package manager thingy.
00:33laurusIs there a way to pass in the function that I want to wrap the code in in the command line and then utilize it from within the program?
00:33laurusI'm not good enough at Clojure yet to figure that out myself
00:34laurusI don't even know if that's good practice, to turn a string into a function like that...
00:34Raynes(eval (read-string "(fn [x] (println x))"))
00:35Rayneshttp://gist.github.com/591143
00:35laurusWhat exactly is read-string? I see the docs but I don't get it.
00:36RaynesIt just reads an object from a string. In this case, it's reading a list.
00:36scottj,(read-string "(+ 1 1)")
00:36clojurebot(+ 1 1)
00:36laurusSo in other words, it turns a string into actual Clojure code.
00:36RaynesPretty much.
00:36laurusThe word "object" there kind of confused me. :P
00:36scottjinto the actual datastructure
00:36laurusAnd then eval runs that code.
00:36Raynes-> (read-string "{:blah \"hai\"}")
00:36sexpbot⟹ {:blah "hai"}
00:36scottj,(first (read-string "(+ 1 1)"))
00:36clojurebot+
00:36Raynes-> (:blah (read-string "{:blah \"hai\"}"))
00:36sexpbot⟹ "hai"
00:37rickmodePreconditions and postconditions do not work for protocol methods. Is this correct?
00:37mabesrickmode: I believe that is the case.. I haven't tried it though
00:37laurusWhat I was doing is this: (clojure.contrib.duck-streams/spit (first *command-line-args*) (list 1 2 3 4)) for example
00:37Rayneslaurus: read-string reads in the list, and then eval evaluates it as code.
00:38laurusSince it's passing the output file as the first command line argument
00:38laurusSo I would just run (eval (read-string thesecondargument) therestofthecode) :P
00:39laurusEr
00:39Raynes((eval (read-string thesecondargument)) therestofthecode)
00:39rickmodewabes: I tried to use one, and it *looks* right, but doesn't have any effect, so was double checking. it makes sense though, since a method is different beast than a fn
00:39laurusBut the problem is how does it know what the rest of the code is? :P
00:40laurusIt's running that code itself, as a file
00:40laurusAnd this eval function is being passed to that file as an argument
00:40RaynesI'm not sure I understand what you're asking.
00:40laurusI'm sorry, it's really weird
00:40laurusDo you use Emacs by the way Raynes?
00:41laurusThe command I have so far in ELisp is this: (cmd (concat "cljr run " (or cmdline "") in-file " " out-file)))
00:41RaynesThe (eval (read-string ..)) if what read-string is reading is a function ("(fn ..)") then it will evaluate to a function which is then called on therestofthecode
00:41RaynesAnd yeah, I use Emacs.
00:41laurusRight, I understand that
00:41Raynesis*
00:42laurusThe question is how do I fit that into that ELisp line I just wrote there
00:42laurusBecause it's running in-file, so out-file is the first argument to in-file
00:42laurusI think this may be impossible...
00:43laurusDo you see what the problem is? It's impossible to run that eval from outside the Clojure code since the Clojure code is already in a file
00:43laurusI think, at least.
00:44laurusI think I'd better just use one of the other build systems.
00:44laurus:P
00:44laurusOtherwise, in every code block, I'd have to insert that eval bit.
00:45RaynesI think I just misunderstood your question.
00:45laurusI think I asked it really badly
00:45bhenryhow can i turn (map :weight answers) into a set
00:45laurusWhat you told me is what I asked for, I just didn't realize the major problem with the whole idea
00:45Raynes(into #{} (map :weight answers))
00:46chouser,(set [1 2 3 4])
00:46clojurebot#{1 2 3 4}
00:46RaynesOr that.
00:46laurusBut thanks Rayes, working through it like this with you made me realize it's impossible to do what I'm trying to do with cljr :P
00:46laurusSo cake here I come!
00:46bhenrythanks guys
00:46Rayneschouser: I thought into was the primary way to get one collection out of another?
00:47chouserRaynes: yeah, it is. And nothing wrong with using it in this case.
00:47RaynesYay!
00:47chouserbut there are a couple fns just for building a collection from nothing: vec, set, list
00:48Raynes-> (list [1 2 3])
00:48sexpbot⟹ ([1 2 3])
00:48chouserhm
00:48chouserright, not list. :-)
00:48RaynesNot quite.
00:48Raynes:p
00:48technomancyman... it's so weird looking at leiningen and having other people apply pull requests for me.
00:48technomancylove it
00:49chousertechnomancy: watchout, man, that mass is critical!
00:49laurusOops, "sudo aptitude install gem" just installed the "Graphics Environment for Multimedia" on Debian :P
00:50TheBusbythe droids you are looking for are "rubygems"
00:50laurusTheBusby, just installed that, thanks ;)
00:50laurusThat often happens on Debian, it's so amusing
00:51technomancydebian is trying to protect you from rubygems
00:51Rayneslaurus: I did that exact same thing once.
00:51TheBusbyI can imagine a context sensitive apt-get in the future, MS Bob's evil twin?
00:51laurus:D
00:52bhenry,(apply list [1 2 3])
00:52clojurebot(1 2 3)
00:52Raynes-> (into '() [1 2 3])
00:52sexpbot⟹ (3 2 1)
00:53bhenry-> (into () [1 2 3])
00:53sexpbot⟹ (3 2 1)
00:53laurusI've never looked at ruby code before, interesting.
00:53bhenrydon't need to quote empty list as it evals to itself
00:53RaynesI concede.
00:54phobbsruby isn't that interesting imo... just clean
00:54TheBusby→ (into () [1 2 3])
00:54laurusRaynes, how does one edit the global project.clj file? Does it exist as such?
00:54laurusNever mind, sorry.
00:54laurus~/.cake/tasks.clj
00:54clojurebotI don't understand.
00:55Raynes:p
00:55laurusI wonder if anyone would be interested in this alternative org babel clojure mode
00:56laurusIt's really hacky and doesn't serve much purpose except to satisfy my own OCD-ness
00:59laurusThanks for the help Raynes!
01:02technomancywould people like it if lein's test task took regex arguments to match against all test namespaces?
01:03technomancyactually wait that's pretty lame compared to test classifiers. scratch that.
01:05dysingerso I don't see a solution for proxying a factory-method generated Javaland nugget
01:06dysingerI will just have to wait methinks until proxy supports that
01:07dysinger__ the person(s) that wrote cake realize that coffe-script build files are called cake also right ?
01:07dysingers/coffe-script/coffee-script
01:11dysingerhttp://jashkenas.github.com/coffee-script/documentation/docs/cake.html
01:26scottjif cakephp wasn't good enough to dissuade I doubt that would be
01:27scottjwhen I read proxying a factory-method I totally thought of a starcraft rush
01:31chouserdysinger: ah, yeah it's not that kind of proxy
01:32chouserdysinger: you want like an instance delegator?
01:34dysingery
01:34dysingerchouser: y
01:35dysingerI want proxy but with the ability to call a factory method instead of super constructor
01:40chouserhmmm
01:41chouserseems like it might be fun to build
01:42chouserthe delegate isn't of a final class, is it?
01:53chouserdysinger: is it acceptable to reflect on every method being forwarded?
02:23LauJensenGood morning all
02:23laurusGood morning LauJensen :)
02:29chouserdysinger: not fun to write. NOT fun.
02:33LauJensenchouser: ?!
02:39cgrandwriting is painful
02:42zmilalong ago i was writing by pen. now only keyboard
02:44chouserdysinger: here's a start: http://gist.github.com/591243
02:44chouserbut it's way past my bedtime, so I'm off...
02:53phobbsfor some reason my slime repl doesn't load when I compile files or evaluate function definitions...
02:54phobbsdoes anyone know what could cause this? How can I fix it?
03:47fliebelCan any Enlive expert in here enlighten me about doing a conditional prepend? I want to add a div wiht an id to a set of divs only if no such id is already there.
04:22fliebelI wrote this to do the job: (defn containing [selector] (pred #(seq (select % selector))))
04:23fliebeland then use this for prepending: [[:#foo (but (containing [:#bar]))]]
04:23fliebelOr did I just duplicate Enlive behavior?
04:27cgrandfliebel: hi
04:27cgrandso you html source is dynamic and you want to add a div if it's missing, right?
04:27fliebelyea
04:28fliebelcgrand: I'm looking for something like the idempotent updates :P
04:29fliebelcgrand: Kind of like with PUT and POST. If I run the template twice I want to end up appending only one element.
04:29cgranddid we already discuss it?
04:29cgrandah ok
04:30cgrand"containing" already exists and is named "has"
04:30fliebelthanks
04:31fliebelyay, works :)
04:31cgrandbut no facility for idempotency
04:31cgrandgreat!
04:32fliebelcgrand: the right hand side of a selector basiacally gets the selected nodes, right? So I could write and append-ur-update fn.
04:32fliebel*or
04:34LauJensenfliebel: Im tied up with Christophe right now in a conf call, so we're coming and going :|
04:34fliebelhaha, okay :)
05:09RaynesIt's disappointing that out of the 23 channels I'm in over three networks, the only activity is in #haskell with the occasional brief burst of yawns in #perl6. :\
05:09Raynescemerick: Morning. :D
05:14esjhi everybody. I'll try contribute a yawn or *gasp* for you Raynes
05:17cgrandfliebel: yes you can write such a function
05:17bobo_anyone know a good way to convert pdf to .epub? calibre doesnt seem to handle joy of clojure any good and i want to read my book :-(
05:17Raynesbobo_: You mentioned something about Irclj a day or two ago. What was that? I kind of forgot. :\
05:18bobo_Raynes: to get the key for a channel
05:18bobo_so i can add it as password for my log
05:18RaynesOh yeah.
05:18bobo_didnt irssi connect me to #irclj? bah
05:19RaynesI'll write that down and see if I can get it done tomorrow.
05:19bobo_:-)
05:19RaynesEr, later today.
05:19RaynesIt's kind of already tomorrow. 4:16am
05:19bobo_im in your future, its 11 here
05:19clojurebotmultimethods is what separates the boys from the men.
05:20RaynesI've been working on cake stuff lately.
05:20cemerickRaynes: morning :-)
05:20RaynesI think I've got like 5 pull requests that need attention in sexpbot.
05:21cemerickRaynes: have you really been in irc starting at 1AM?
05:22RaynesI'm in IRC constantly. I'm on a bnc.
05:22RaynesUnless you mean active.
05:22fliebelcgrand: I'm trying to do that now, but I'm struggling to understand Enlive in its full glory. Took me a while to realize whether a function is called, or actually returning the actual function.
05:22RaynesThen yes, I haven't been to sleep yet.
05:23cemerickalmost a crazier schedule than mine :-)
05:23RaynesIf you can call what I have a schedule.
05:24RaynesIt's a distinct possibility. But if sexpbot wrote me, than who wrote sexpbot?
05:25esjthis is lisp: its metacircular :)
05:25fliebelI think sexpbot was actually written in Perl by some guy on a cloud.
05:26Raynes:)
05:30cgrandfliebel: (append-or-update ...) must return a function taking a node as its single node
05:33esjhowdy cgrand
05:35cgrandhi esj!
05:40fliebelcgrand: I think I got it working :) I'll show you the result in a moment.
05:45fliebelcgrand: http://github.com/pepijndevos/utterson/commit/4a01b10d279bbacb692899e7b2219ecd849d50c6
05:57cgrandfliebel: http://github.com/pepijndevos/utterson/commit/4a01b10d279bbacb692899e7b2219ecd849d50c6#commitcomment-152479
06:06Raynesivey: Ping.
06:16fliebelcgrand: Thanks :)
06:28fliebelcgrand: Which classloader is Enlive using to find templates?
06:29neotykHello
06:29cgrandFingerzam: the same as clojure itself
06:29LauJensenFingerzam ? :)
06:29neotykdo you know if there is somewhere a video of Rich talk @J1?
06:29LauJensenYou mean fliebelzam right?
06:29cgrandfliebel: that's for you ^^ (damn autocompletion!)
06:30fliebelcgrand: My experience so far is that for some reason only clojure.lang.DynamicClassLoader is able to find the file I put on the classpath. So Enlive gives me a NullPointerException :(
06:30fliebelcgrand: clojure.lang.DynamicClassLoader seems to be what the repl and everything loaded outside of ns declarations seem to use.
06:32fliebel,(.getClassLoader (class (fn [])))
06:32clojurebot#<DynamicClassLoader clojure.lang.DynamicClassLoader@352ebe>
06:33fliebel,(.getClassLoader (class ""))
06:33clojurebotnil
06:33fliebel,(.getClassLoader (class +))
06:33clojurebotjava.security.AccessControlException: access denied (java.lang.RuntimePermission getClassLoader)
06:33LauJensenfliebel: enlive looks on the cp without any problems
06:34fliebelLauJensen: Not for me… at least not in my app, on the repl it works fine because the it's using the dynamic one
06:34LauJensenOh you mean when AOTed?
06:34fliebelLauJensen: Yea...
06:36fliebelSo either I need to make AppClassLoader understand how to find my file, or I need to make Enlive use DynamicClassLoader.
06:38fliebelThis is where it all happens, right? http://github.com/cgrand/enlive/blob/master/src/net/cgrand/enlive_html.clj#L86
06:38cgrandfliebel: does (.getParent (.getClassLoader (class (fn [])))) and (.getParent (clojure.lang.RT/baseLoader)) return the same thing in your setup
06:39cgrandfliebel: yes this precise line
06:39LauJensenScala attempts to make Java simpler, here's a status report: http://i.imgur.com/QONqZ.gif
06:40fliebelcgrand: On the repl, yes… AOT… I'll see
06:42fliebelAOT: No: #<DynamicClassLoader clojure.lang.DynamicClassLoader@d1a9f20> #<ExtClassLoader sun.misc.Launcher$ExtClassLoader@138d107f>
06:43fliebelcgrand: And apparently ExtClassLoader can't find my files.
06:43fliebelLauJensen: lol
06:46fliebelcgrand: May I suggest you use (clojure.lang.DynamicClassLoader.) instead? Or will that cause havoc elsewhere?
06:46fliebelI've been using it throughout my app without problems.
06:58cgrandfliebel: DynamicClassLoader default constructor?
06:59fliebelcgrand: I have no idea what I'm doing, I just know it works :)
07:00cgrandfliebel: can you try with (alter-var-root clojure.lang.RT/USE_CONTEXT_CLASSLOADER (constantly false)) at the top of your main ns?
07:01fliebelsure...
07:02cgrandor (alter-var-root *use-context-classloader* (constantly false)) ...
07:02cgrand(same thing)
07:03fliebelcgrand: Are you sure? The second gives me a nullpointerexception during compiling.
07:04fliebelthe first did just the same as before.
07:05cgrandhow are you deploying your app?
07:05fliebelcake uberjar
07:06cgrandso it's a standalone app?
07:06fliebelyea, with a separate directory outside the jar with my tamplates
07:06fliebelbtw, that code of yours still prints #<DynamicClassLoader clojure.lang.DynamicClassLoader@6908af2a> #<ExtClassLoader sun.misc.Launcher$ExtClassLoader@138d107f>
07:07cgrand(my fear with dynamicclassloader is to break things for people running in container -- eg tomcat)
07:08fliebelcgrand: I don't know how this stuff works, so I wouldn't be able to say anything useful about that.
07:09fliebelcgrand: Would it be possible to get DynamicClassLoader Ruby-style? I mean, do a defmethod in my own code, or otherwise monkeypatching it.
07:09LauJensenfliebel: and you're absolutely sure that the resources are actually on the cp ?
07:09fliebelLauJensen: On the repl it works fine
07:10LauJensenfliebel: but the repl isn't initialized the same way as a standalone jar
07:10clojurebotwhose job is<reply>that is xxpors job
07:11fliebelLauJensen: /My/ code is using DynamicClassLoader and is able to find the file, even in the jar. But as soon as I put the filename in deftemplate it gives me a NullPointerException.
07:12LauJensenfliebel: I guess you could manually try (-> (clojure.lang.RT/baseClassLoader) (.getResource filename)) or something like that. If that does give you a URI to the file, then Enlive is broken
07:17cgrandfliebel: or you can defmethod again (defmethod en/get-resource String ...) and it's *real* monkey patching so be cautious
07:17fliebelcgrand: Just did that, and it works :)
07:18fliebelBut… why aren't defmulti's immutable like the rest?
07:19cgrandif they were immutable how would you extend a defmulti?
07:19fliebelI don't know… just define them at once like you define a defn with multiple bodies.
07:20cgranda mmethod (lie a protocol) is intended to be extended by others
07:20fliebelokay, I like it for now :)
07:22LauJensencgrand: Can you add that to the docs for how to handle the general case of an AOT'ed Enlive app?
07:23LauJensenAnd Im just thinking. I remember doing an AOT'ed enlive app not too long ago, which worked without any problems....
07:23cgrandLauJensen: I'm going to investigate and solve the issue (write code or doc)
07:25LauJensencgrand: Why did my app work if AOT is the cause?
07:28cgrandfliebel: can your provide me with the command line you are using to laucnh your app? thanks
07:29fliebeljava -cp examples/testsite:utterson-0.1-standalone.jar utterson.main page index.md
07:31fliebelbut wait… there might be another problem… I hate those "helpful" error messages
07:44fliebelcgrand: Guess what was causing an error… ((en/has selector) %)
08:17fliebelcgrand: Oh man, this reminds me so much of the story of my father where they tried to fix some plumbing where the new part was the one that was broken. The NullPointerException wasn't in Enlive. This was entirely my fault, and at the same time entirely yours. You remember that comment on my commit? That suggesting you made throws an exception. The old line works just fine both with and without the custom class loader.
08:31cgrandfliebel: grmf :-(
08:32fliebelyea :(
08:33LauJensenWell, the important thing to remember is that I was right all along :)
09:02zoldarhello, I'm trying to wrap my head around clojure.zip. I have made a small function which is supposed to convert an input stree into form that can be evaluated by hiccup's "html". What am I missing here? http://pastebin.com/yKs6EiwX . Any help appreciated.
09:15konrI want to build an utility that lists and manages clojure jobs such as web crawling and expensive computations. Is there something like this already coded?
09:17nlogaxi don't know, but feel free to use this name: cronj
09:17nlogaxthe jobs could be called cronj obs
09:17konrThese jobs would be clojure functions, wrapped with stuff like metadata, logging utilities and before-running and after-running functions, so it would be easy to create a coordinating job to, say, rip a website using four connections at any time
09:18konrhaha
09:18konrI thought about juju, too, for Jobs Under JUJU's <something with U>
09:18nlogaxUmbrella!
09:18konrgreat!
09:33zoldarok I sorted it out, this one works http://pastebin.com/A3CahmRW
09:34chousercemerick: would an external text file serve instead of an inline escape-free string? Why not?
09:35cemerickchouser: /facepalm
09:35cemerickBecause I shouldn't have to externalize strings just because they have backslashes in them.
09:36chouserI'm not arguing against the feature. I'm trying to anticipate anything rhickey might throw at me.
09:36cemerickYeah, I know :-)
09:36chouserok
09:36cemerickIt seems like such an obvious *want*.
09:37chouserso ... what's wrong with externalizing the string? Is it small? Do you have lots of them?
09:37cemerickOf course, I think the same of string interpolation, and look where that led. :-/
09:38chouser""" is the most obvious contender, but I wish it were a 100% solution. ...but what if you want to stick some clojure or python code in your string, and *that* code has """ too?
09:38cemerickYeah, I just wrote a few unit tests that deal with escaping of quotes in strings. It didn't take me long, but it took me a lot longer because I mistyped a \\\" sequence.
09:38chouserbleh
09:39cemerickRich is *never* going to go for """
09:39chouserreally?
09:39chouserthat's ... unfortunate.
09:39cemerickI'd think not. Very syntaxy.
09:40chouserhm
09:40cemerickthough, he did do the ^:private thing, or whatever that panned out to be.
09:41cemerick#\" seems more appropriate, and fewer characters to boot.
09:41cemerickTools would just *love* that. :-P
09:42chouserI don't understand. What would terminate it?
09:45cemerickA proper unicode quotation mark ”
09:45cemerick;-)
09:46cemerickI type here first, then think. #\" wouldn't work.
09:47cemerick#|symbol with spaces| has been suggested before, and is found in other lisps. Perhaps #|"string data"|?
09:51fliebelOr how about $ as a macro for symbol? $"php and perl users are going to love this"
09:51cemerick$ will always remind me of my C-64.
09:51chouserfliebel: still need something other than " to terminate or we're no better off
09:51chouser"| is an interesting terminator
09:52fliebelso you could do $:keyword or even $@some IDeref
09:52fliebelor $@#* to dereference a regex stored as * and turn it into a symbol.
09:52cemerickchouser: Which casts #|foo bar| as a very particular sort of unescaping, if one wants to draw that tenuous connection.
09:54fliebelPeople already kno $ for symbols, with #|ruby users| will think a block is coming :P
09:54fliebelchouser: I didn;t follow the entire discussion, what's wrong with "?
09:55cemerickfliebel: we're trying to avoid stuff like
09:55cemerick,"\\\""
09:55clojurebot"\\\""
09:56fliebelcemerick: What, you mean for people wanting to have \" as a symbol?
09:56cemerickno, to avoid escaping \ and " entirely
09:57cemerickRoughly equivalent to r"""string data""" in python, I'd say.
09:57fliebelokay, so what we need is arbitrary string terminators, like in PHP
09:58fliebelor… why allow symbols with spaces and stuff in the first place?
09:59cemerickwell, we weren't talking about symbols at all
09:59fliebeloh, just strings?
09:59cemerickbut symbols with spaces in them are occasionally very handy
09:59chousercemerick: that's some kind of ruby/python hybrid you've got there
09:59cemerickchouser: oh?
10:00fliebelchouser: Python has raw strings (as well?)
10:00chouseroh, you may be right.
10:00cemerickyeah: r"""hello\there""" => 'hello\\there'
10:00cemericks/gyet/yet
10:01chouseroh, ruby uses %r{...} for regex
10:01cemerickyikes
10:01fliebelBut in Python you can only use """ als this kind of strings, so you're still screwed if you want a string containing """
10:01cemerickdon't they have r/foo/ or something?
10:02chouserfliebel: right. a 95% solution
10:02fliebelIn PHP you can use three of anything as a string terminator, only the syntax is ugly.
10:02chousercemerick: yes, ruby does the perl thing of choose-your-own-terminator
10:02chouserwhich has a kind of elegence, but rhickey seems to dislike it
10:03cemerickI agree with him there. A high bar for tools.
10:03chousernonsense, but whatever.
10:03bobo_probably a stupid question, but why not just a funktion for it?
10:03fliebela high bar for newlings
10:03cemerickchouser: well, insofar as a lot of tools have quickie syntax frameworks that are driven by regexes....
10:04chouserI can understand disliking it, but I think the tool complaint is a fig leaf. or a red herring...
10:04fliebelbobo_: What would you put in the function?
10:04bobo_fliebel: i realised that pretty much as i pressed enter
10:04chousercemerick: regexs have no problem with that kind of backreference
10:04cemerickchouser: depends on what regex engine you've got to work with?
10:04fliebelyea something like .{3}.*.{3)
10:05chousercemerick: not really. what tool can't highlight ruby or perl?
10:05fliebelbobo_: You could just use str and put the quotes inbetween as a char maybe.
10:05chouserbut that's fine. "I don't like it" or "seems wishy washy" is sufficient.
10:06cemerickchouser: I thought only vim could highlight perl? Everything else just crashes on my machine. :-)
10:06chouserheh
10:06chouserwell, perl does have issues, but not usually around delimited quotes.
10:07chouserusually more around whether m/a is division or a regex.
10:08fliebel<crazy idea>What about prefixing strings with a regex to match their own delimiters</crazy idea> That is almost perl-style
10:08chouseranyway, I just added clojure and another language to a syntax highlighting too last week. configurable quotes would have been significantly less tricky than multi-line string literals were.
10:09cemerickfliebel: holy jeebus, you're nuts. :-)
10:09chouserfliebel: the primary obstacle we have to overcome is rhickey's general distain for all things stringy. Nice try though. :-)
10:10chouserdisdain
10:10cemerickhow about #name-of-fn-to-parse-following-string"foo"
10:10cemerickJust get it over with, etc.
10:11chouseryeah! if we can slip reader macros in like that, I'd be very happy.
10:11cemericks/parse/tokenize
10:12chouserbut now we can talk about tooling issues.
10:12chouser...no correct syntax highlighters unless they can eval clojure code.
10:13cemerickSurely there's a regex engine that can eval clojure code?
10:13cemerickpfhhht.
10:15_fogus_cemerick: it's 5 o'clock somewhere
10:16cemerick_fogus_: noon would be sufficient per my handy Irish-influenced well-lubricated New England folk morals handbook. ;-)
10:16bobo_its almost 5 here... :-)
10:19chouserwith #|"foo"| we could potentially allow for nesting: #|"list|of|"things"|here"|
10:20_fogus_The bar is sorely underused in PL syntax
10:24cemerickAssuming #|foo| eventually arrives for arbitrary symbols, I wonder if #|"foo"| is too similar, just in terms of legibility.
10:25chouserI don't think that would be a problem. The similarity makes a kind of semantic sense
10:25chouserand we already have very different meanings for the somewhat similar (), #(), {}, and #{}
10:25cemerickExactly why I suggested it.
10:25cemerickThat's true
10:25cemericknm then
10:32fliebelI think arbitrary delimiters is the only way without just postponing the problem.
10:34dpritchettIs there any stated timeline for clojure-cljr development? I'm sure it's not a top priority with all the momentum behind the jvm and clojure-in-clojure efforts but i'm still curious
10:44fliebelHas anyone ever written a nio WatchService in Clojure?
10:46chouserfliebel: no, but before I knew about that I made a linux-specific lib to do something similar on top of jna
10:50fliebelchouser: So what is the way to go for Java 6?
10:50chouseroh, is WatchService not in 6?
10:50fliebelI think it's a nio.2 feature for 7
10:52chouserhm, indeed "Since 1.7"
10:52chouserfliebel: you don't want linux-specific? :-)
10:53fliebelchouser: Add at least Mac :P
10:53fliebelI did find this: http://jnotify.sourceforge.net/
10:55chouserlooks like this might be an option as well: http://jpathwatch.wordpress.com/
11:41bhenrycan anyone take a look at this function? https://gist.github.com/91de400e806503b4ba3c select-ans and deselect-ans are just shortcuts to assoc calls. i feel like the select-answer function is longer than necessary.
11:42fliebelbhenry: Have you tried bending reduce to your will?
11:43bhenryfliebel: nope.
11:44chouseryou want all the matching weights, right?
11:45bhenryi want to change the :selected attribute based on a matching weight. if for some reason a weight gets in the call with no answer having that weight, i want to return the original answer
11:46bhenryreturn the original answer-set*
11:49laurusI have a Clojure program I'm running on the command line, passing in a filename as an argument. I'd like to dump out the return value of the program, as well as anything printed as side-effects, into that file. I have been using spit, but it doesn't work with writing the side effects to that file. How can I do this?
11:51mrBlisslaurus: (binding [*out* (writer ...)] (println "bla"))
11:51laurusmrBliss, well I'd like to wrap the entire program in one function call
11:51apgwoz,(let [aset [{:weight 1.1} {:weight 2.2}]] (or (first (keep-indexed #(= (:weight %) 1.1) aset]) aset))
11:51clojurebotUnmatched delimiter: ]
11:52apgwoz,(let [aset [{:weight 1.1} {:weight 2.2}]] (or (first (keep-indexed #(= (:weight %) 1.1) aset)) aset))
11:52clojurebotjava.lang.RuntimeException: java.lang.IllegalArgumentException: Wrong number of args (2) passed to: sandbox$eval7455$fn
11:53mrBlisslaurus: can't you just do (defn f-name [] (binding [..] -function-))?
11:53apgwozbhenry: i'd have thought the above would work... but, apparently i'm being lame and doing something wrong
11:53laurusmrBliss, I'm a beginner at Clojure, hehe
11:53laurusSo I don't actually know a lot of this
11:54mrBlisslaurus: np! I wasn't sure if I understood your question :)
11:54chouserbhenry: since you want different behavior for the first element depending on values of later elements, something's going to have to scan the whole list before going through and mapping on each item.
11:54laurusBasically let's say I have two things: (println "Hello") and then on the next line, (list 1 2 3 4)
11:55laurusThose two lines of code comprise a .clj file
11:55laurusI want to be able to wrap that "program" in one function, that takes one argument, a filename
11:55laurusThat filename is the file that the output will go to, both any printlns and the return values
11:55laurusSo the question is, what does that function need to look like? :p
11:55fliebellaurus: Put the above binding with *out* in a fn that call load-file on the argmuent.
11:55chouserbhenry: (defn select-answer [a-set weight] (let [foundseq (map #(== (:weight %) weight) a-set)] (if (every? false? foundseq) a-set (map #(if %1 (select-ans %2) (deselect-ans %2)) foundseq a-set))))
11:56chouserbhenry: or: (defn select-answer [a-set weight] (if (not-any? #(== (:weight %) weight) a-set) a-set (map #(if (== (:weight %) weight) (select-ans %) (deselect-ans %)) a-set)))
11:56mrBlisslaurus: put (list 1 2 3 4) in a println?
11:57laurusmrBliss, no
11:57apgwozoh, i'm a moron. keep-indexed uses a function arity 2.
11:57bhenrychouser:
11:57bhenry(defn select-answer2 [answers weight]
11:57bhenry (let [new-answers (map #(if (= (:weight %) weight)
11:57bhenry (select-ans %)
11:57bhenry (deselect-ans %)) answers)]
11:57bhenry (if (empty? (filter :selected new-answers))
11:57bhenry answers
11:57laurusI want both the side effects and the return values to be "logged" to a file
11:57bhenry new-answers)))
11:58laurusfliebel, let me try that, thanks
11:58mrBlisslaurus: this might do the trick (modify it a bit) (defmacro dbg [x] `(let [x# ~x] (println "dbg:" '~x "=" x#) x#))
11:59chouserbhenry: sure. btw, use == for numbers. and not-any? instead of empty? filter
12:00laurusfliebel, in that binding, what should "writer" be?
12:00bhenryyeah i liked your second answer. will == fail if i pass an int trying to match a float?
12:00bhenrychouser ^
12:00chouserbhenry: no, but = will in Clojure 1.3
12:00kevinclarkchouser: what's the difference between == and =?
12:00kevinclarkobject equality vs value equality?
12:01chouser== is for numbers, = is for other things
12:01chouserdetails beyond that depend on which version of Clojure you're talking about
12:02mrBlisslaurus: (defmacro print-eval [x] `(let [x# ~x] (println '~x) x#))
12:02mrBlisslaurus: (print-eval (list 1 2 3)) will print (list 1 2 3) and evaluate it
12:02kevinclarkchouser: is it changing for 1.3? Any idea if the 1.2 semantics are stable?
12:02kevinclark(in this case)
12:02fliebellaurus: I think it's clojure.java.io/reader or something int that package.
12:03laurusmrBliss, ah, that's interesting
12:03fliebel*namespace
12:03laurusmrBliss, I think the first code you wrote is closest to what I need actually
12:03laurus(binding [*out* (writer ...)] ...
12:05chouserkevinclark: rhickey wrote it up somewhere, but I'm not sure where
12:06kevinclarkchouser: ok, I'll google for it. thanks
12:07chouserhttps://www.assembla.com/wiki/show/b4-TTcvBSr3RAZeJe5aVNr/Enhanced_Primitive_Support
12:07arohnertechnomancy: re: the patch that uses wall-hack-method, is it ok to just copy the function into lein? Otherwise I'm basically just reimplementing wall-hack-method
12:07chouserarohner: that's in clojure.contrib.reflect
12:08arohnerchouser: yes. I used it in a patch for lein, while lein dropped its dependency on contrib
12:08chouserah
12:08arohnersince they're both EPL...
12:08technomancyarohner: is it possible the bug you're working around has been fixed in a newer maven-ant-tasks?
12:08kevinclarkchouser: oh, cool, thanks
12:09arohnertechnomancy: possibly. I thought you were stuck on that version because of some other bug?
12:09chouserkevinclark: I *think* the top one "equiv" is what's in master now
12:10laurusIs there a version of spit that appends to a file rather than overwriting it?
12:10technomancyarohner: someone gave me the impression the other one may have been fixed; can't remember the details =\ plus the guy doing debian packaging wanted to pull in a newer one, so I kind of want to revisit that
12:11laurusAh, append-spit.
12:11arohnertechnomancy: I'll check out the source of the newest ant tasks, see if it's fixed there
12:12laurusEr, spit-append.
12:12technomancyarohner: that'd be grand; thanks
12:13laurusEr, what?
12:13laurusDoes that function still exist?
12:13arohnertechnomancy: not fixed. Another hack is to call a public method that I know calls getContainer(), but that's...
12:15mrBlisslaurus: it's still in clojure.contrib.io
12:16laurusThanks :)
12:16technomancyarohner: what does the other method do? as long as it's well-explained in the comments we should be able to trace it down once we do upgrade in case the behavioru changes
12:17arohnerthe one I would call, getSupportedProtocols() just returns an array of strings of protocols the task knows how to download over
12:20technomancysounds like the lesser of two evils
12:21arohnertechnomancy: ok
12:24alexykdnolen: any luck with cake 0.4.16*?
12:24alexykninjudd: cake install from today's pull of 0.4.16 created a file cake/0.4.16 instead of a directory, had to manually remove and repeat cake install to finish
12:24alexyk(in maven repo)
12:25dnolenalexyk: nope, didn't have time to check it out yesterday, did you try 0.4.15?
12:25alexykdnolen: I was asking ninjudd how can I fall back on the 0.4.15 jar I have in the maven repo...
12:29laurusI thought spit closed the file when it was done with it, but I'm getting "java.lang.Exception: Cannot change an open stream to append mode." when I try to run clojure.contrib.io/append-spit on the same file. Why?
12:31mrBlisslaurus: when append-spit is in the scope of spit (handling the same file)
12:31laurusmrBliss, but I thought spit closed the file.
12:31laurusAlso, it's in a completely separate function
12:32mrBlissafter the ) matching (spit ...
12:32laurusmrBliss, I have: http://paste.lisp.org/submit
12:32laurusEr
12:32laurus:P
12:32laurushttp://paste.lisp.org/display/114781
12:33mrBlissmmm, looks fine
12:34laurusRight, but I'm getting "java.lang.Exception: Cannot change an open stream to append mode."
12:34laurusMaybe a bug?
12:34mrBlissmaybe you opened the file before (in the REPL) with a reader without closing it ?
12:35laurusNo, even if I run it as a standalone file it happens.
12:37mrBlisslaurus: I think with-out-str is the problem
12:38mrBlisswhen I execute your code and look in hello.txt, I only see "yo"
12:39laurusThat's because the bug hits before it finishes, I think
12:39laurusBe right back, sorry!
12:39arohnertechnomancy: how do you attach a second pull request to an issue?
12:40arohnertechnomancy: http://github.com/arohner/leiningen/commit/b5ebd46ea1464841b1def4bea549a786940dcd86
12:46mrBlisslaurus: I think it's a bug in append-spit http://clojure-log.n01se.net/date/2010-08-04.html#09:10
12:47bhenrylaurus: with-out-str only returns results of print statements within. it's going to give "yo" to the spit call and that's it. (unrelated to the error message)
12:52alexykwith today's cake pull of 0.4.16, I get class not found on: org.apache.tools.ant.Project
12:52alexykanybody else? where does this live in? some ant version?
13:04laurusmrBliss, ah, thank you :)
13:06laurusmrBliss, I think I'll play around with that macro you pasted and try to use that: (defmacro print-eval [x] `(let [x# ~x] (println '~x) x#))
13:06laurusThanks for the help!
13:06mrBlissnp
13:20ohpauleezDoes Bradford Cross hangout in here?
13:21alexykdnolen: where does cake/*env* is set? it's nil which causes my errors
13:22alexykninjudd: cake/*env* is nil in 0.4.16...
13:23dnolenalexyk: ah yes that got renamed.
13:37jashmennsorry, noob question here, but is there a way to get the effect of (:require ... :as ...) with (:import) ?
13:38jashmenne.g. :import a java class but alias it with :as
13:38chouserno, there's currently no way to alias a java class
13:38chouserthough it's a frequently requested feature.
13:38jashmennokay, np. just wanted to make sure i wasn't missing something obvious
13:38jashmennthanks
13:39chouserI've been known to write macros to get around particularly long class names.
13:42LauJensenchouser has been known to write macros for most things actually :)
13:42chouser:-D
13:49technomancyI think I just saw an instance where a namespace showed up in a stack trace that hadn't been loaded yet.
13:53ohpauleezI think there may be a bug in repl-utils in 1.3
13:53ohpauleezI haven't looked into too much, but show is throwing an exception regarding the lt stuff
13:53ohpauleez(NoSuchMethod)
13:54chouserohpauleez: I was seeing that before, but I think I fixed it. or something.
13:54ohpauleezchouser: Let me re pull my deps. I noticed it two days ago and made a note to look into it more
13:55chouseryeah, I pushed a commit on Thursday
13:55ohpauleezAwesome (I was secretly hoping I was going to get to write the simple patch:) )
14:10jweissi know i saw docs somewhere on what legal names are for clojure identifiers
14:11chouserclojure.org/reader I think
14:12jweissthe rules for symbols?
14:12chouseryeah
14:12jweissk thanks
14:22alexykdnolen: I'm back... so you use cake/*env* everywhere! no surprise then it causes errors :)
14:23dnolenalexyk: well that's there in the official cake release, will change when they roll out the next version.
14:31alexykdnolen: 0.4.16 is out
14:37dnolenalexyk: ahh, k, fixed on master
14:40alexykdnolen: should I pull the master then as well?
14:41dnolenalexyk: aria42 merged master, and I think the likelihood of mcgrana taking our fairly major changes is slim, so we're on master now.
14:43alexykdnolen: uff, finally works. You had me see the guts of your bundle now. :)
14:44alexyk^X is fun
14:44dnolenalexyk: good :) Maybe you'll start sending us patches :) Yeah the project needs a bit of cleanup now.
14:44dnolenalexyk: yes.
14:45alexykdnolen: I wonder what happens with franks42 etc. There should be a consensus... Let's create a google group?
14:45fliebeldnolen, alexyk: Is this about Ring, or some other project?
14:45dnolenalexyk: I think that's a good idea.
14:46dnolenfliebel: SLIME-y TextMate bundle for Clojure
14:46alexykfliebel: TextMate plugin with cake
14:46rickmodeIs there any push to "normalize" the differences between the java interop kinda things and the lisp things? Example: use vs import; functions vs methods. I like the Lisp style more-so than the Java interop style. More importantly, I dislike the syntax differences.
14:46fliebelAh, nice :)
14:47alexykdnolen: textmate-clojure or clojure-textmate? That is the question :)
14:47dnolenalexyk: noooooooooooooooooooooo ... :)
14:47alexykthe deepest question of all double things...
14:47kotarakrickmode: syntax difference? (fn-with some args) (.method-with some args)?
14:47technomancy"Programming Clojure" or "Clojure Programming"?
14:47technomancy"Programming Scala" or "Programming Scala" or "Programming in Scala"?
14:47alexyktechnomancy: this is religious
14:48alexyk"In Clojure we Program"
14:48technomancyalexyk: I was refering to book titles actually
14:48rickmodekotarak: more like (defn foo "comment" [x y] {:pre [test]} ...) vs within a defrecord / deftype (foo [this x y] ...)
14:48alexyktechnomancy: I understand
14:49alexyktechnomancy: so words should be used which don't allow reshuffling, like "the joy of clojure" or "on clojure"
14:49kotarakrickmode: nobody forces you to write inline methods. You can write them as normal functions and extend the protocol to the type with extend.
14:50ninjuddtechnomancy: i prefer programming books that don't have the word Programming in the title
14:50alexykdnolen: textmate-clojure seems right, like your project suggests, since TextMate is primary here
14:50alexykninjudd: we fixed TM-cake. cake/*env* was to blame
14:51alexykninjudd: why, oh why did you rename *env* to *shell-env*?
14:51rickmodekotarak: I haven't explored that. I have a sneaking suspicion my current use of protocols and defrecord isn't ideal anyway as I get over my OO-hangover
14:51ninjuddah yes. dnolen: did lancepantz warn you about that?
14:51dnolenninjudd: yes, but been a bit too busy to act on it sooner.
14:52alexykN hours at M $$/hour...
14:52ninjuddalexyk: lancepantz is the one who made the change. send the bill to him
14:52alexykok
14:53kotarakrickmode: shameless self promotion: http://bit.ly/c7R5pJ This might help. Although the colorscheme seems to be the most interesting aspect..
14:53ninjuddalexyk: sorry about that. did you post a trace yesterday?
14:53alexykunix is always ENV, WTF is *shell-env*? it's $ENV etc everywhere
14:53kotarakrickmode: it explains the trade-offs for inline vs. extend
14:53alexykninjudd: it was hard to catch from TextMate's guts
14:54alexykbut, I saw the beauty of dnolen's bundle, implemented itself in Ruby stubs and Clojure innards, like cake itself
14:54rickmodekotarak: cool. so far I've been trying to grok protocols and datatypes reading "Joy of Clojure".
14:54ninjuddah kotarak, that's your blog. your entries on gen-class and proxy were very useful to me!
14:54kotarakninjudd: you are welcome
14:55ninjuddand the color scheme is nice too ;-)
14:55kotarakrickmode: joy of clojure is not necessaritly an introductory text as far as I understoof
14:55dnolenalexky: that's the nice thing about the Clojure bundle, nearly 100% clojure. No reason not to contribute.
14:56dsopis there a recording of ricks talk at javaone?
14:57rickmodekoyarak: no... I read "programmign clojure" and most of "practical common lisp" before it
14:58rickmodeand "the little schemer"
14:58rickmodeI've done OO programing for most of the last 20 years... I'm trying to rewire my brain ;)
14:58kotarakrickmode: yeah. That's a task. :)
15:02rickmodekotarak: i'm getting there.... though, as I said, I seem to be falling into the trap of using defprotocol and defrecord as a flat inheritance mechanism. I suspect this will eventually become a clojure anti-pattern
15:09amalloydsop: wasn't the clojure talk at javaone cancelled?
15:10dsopI just saw a tweet that he presented clojure
15:14_fogus_kotarak: No love for Common Lisp?
15:15kotarak_fogus_: not really. I fail to appreciate it's beauty.
15:15_fogus_kotarak: Anything in particular?
15:16kotarakFor example this Lisp-2 stuff. I prefer Scheme and Clojure in this respect.
15:17technomancyI always have to laugh at the alphabet-soup function naming.
15:17cemerickAND-ALL-CAPS
15:17technomancyget the feeling it was optimized for Wheel of Fortune.
15:18kotarakAh yes. This ALL-CAPS stuff is ridiculuous. lower-case is much better to read. And names like car, cdr and cadadadadr... pfff
15:18duncanmla la la
15:18kotarakI like Clojure's attitude to break with the "tradition".
15:19_fogus_CL has first and rest also. In fact, I think they are the more accurate than car/cdr
15:19cemerickthe declare, proclaim, and declaim stuff was mind-boggling as well.
15:20bhenryeasiest way to get a one in ten probability of truthy in a random value. go!
15:20duncanmi'm trying to come up with a nice expression to count the number of items (in some range) from a matrix that looks like ([a b c ...] ...)
15:21duncanmso i'd end up with something like {:one-to-five 5 :six-to-ten 0 }
15:21chouser,(zero (rand-int 10))
15:21clojurebotjava.lang.Exception: Unable to resolve symbol: zero in this context
15:22chouser,(zero? (rand-int 10))
15:22clojurebotfalse
15:22_fogus_I think much of what people dislike about CL has more to do with reading poorly written code
15:23_fogus_cemerick: all caps?
15:23bhenryoh chouser you always come up with something better.
15:23cemerick_fogus_: yeah, what about it?
15:23kotarak_fogus_: maybe (do you consider On Lisp badly written code?). Maybe also the difference in atmosphere in c.l.l and g.g.c.
15:24chouserbhenry: you want something better than that?
15:24cemerickAFAIRemember, only lispworks has a case-sensitive mode, and it's semi-broken (or had some niggling issue the last time I looked at it)
15:24_fogus_kotarak: I would say On Lisp is not representative of Common Lisp style at all
15:25bhenrychouser no, yours was way better than mine. as usual
15:25chouserbhenry: heh, oh I see. sorry.
15:25cemerickhow about...
15:25cemerick,(< (rand) 0.1)
15:25clojurebotfalse
15:25bhenrypretty good.
15:26cemericknot as good for reading, though :-)
15:26_fogus_cemerick: I can't speak for LispWorks, but AFAIK no CL implementation requires all caps. They do tend to print at the REPL in all caps, but that is representational only.
15:26bhenrythat's what i was thinking.
15:28_fogus_kotarak: I will not say that Common Lisp is perfect, but much of the "ugliness" derives from a culture of creating control structures that are easy for macro writers to reason about rather than end users.
15:29kotarak_fogus_: you don't have to defend CL. It's not in the dock.
15:29_fogus_dock?
15:30chouseron trial?
15:30kotarakaccording to dict.leo.org this means "Anklagebank".
15:30kotarakchouser: right
15:31cemerickkotarak: "on the docket", I think you're looking for :-)
15:31kotarak_fogus_: I don't appreciate its beauty. But I also don't appreciate the beauty of van Gogh's paintings.
15:31_fogus_kotarak: Fair enough.
15:31kotarak_fogus_: the world won't stiop turning.
15:31_fogus_well that a relief
15:31cemerick_fogus_: I guess I've forgotten what my specific beef was. I was doing a pile of XML the last time I was futzing with CL, and I suspect that tag names were being upcased or something.... *shrug*
15:33kotarakcemerick: will have a look at nREPL
15:34cemerickkotarak: many thanks. I hope it'll be helpful. I've yet to add good launching mechanisms, but that's up next.
15:35amalloy,(count (filter (apply hash-set (range 1 5)) (range 1 10)))
15:35clojurebot4
15:35amalloyduncanm: ^^
15:42_schulte_hi, I often find myself using (apply hash-map (apply concat (map...))) to convert the resutls of a map to a hash, is there a better(idiomatic) way?
15:43chouser,(apply hash-map (apply concat (map identity [[1 2] [3 4] [5 6]])))
15:43clojurebot{1 2, 3 4, 5 6}
15:43chouser,(into {} [[1 2] [3 4] [5 6]])
15:43clojurebot{1 2, 3 4, 5 6}
15:43mrBlissmapcat is shorter than (apply concat (map ..
15:43_schulte_thanks I'll look into `into'
15:44andyfingerhutBasic question here. I know how to get the latest clojure and clojure-contrib from github. I can build clojure. For clojure-contrib, the readme file says to use 'mvn install' to build it. When I do that, it seems to pull down and use clojure-1.2.0 to do that compilation. How can I build clojure-contrib using the latest clojure compiler?
15:46LauJensencemerick: ^^ your monster is acting up again
15:47cemerickLauJensen: heh, nREPL isn't a monster yet :-)
15:48LauJensencemerick: nREPL? I meant Maven of course
15:48cemerickI don't think I mentioned maven at all?
15:49amalloy_fogus_: i think trailing parens should go on their own lines
15:49cemerick_fogus_: you can blame it on my earlier pissyness :-P
15:49_fogus_amalloy: not about *that* topic however. ;-)
15:49ohpauleezhahaha
15:50_fogus_cemerick: first drink is on me then. that should soften me up a bit. :p
15:50ohpauleezI like when these conversations happen in this channel
15:50LauJensencemerick: andyfingerhut has tried building contrib with maven, that naturally fails, thus Im directing your attention to it since all problems related to Maven are you doing, right?
15:50ohpauleezit cracks me up every time
15:50ohpauleezcan we start talking about AwesomeWM again and window managers in general?
15:51cemerickLauJensen: if it makes you feel better, then yes, you can blame all maven problems everywhere on me
15:51LauJensenohpauleez: Naah, its time for another round of Emacs vs Vi
15:51ohpauleezLauJensen: You're on
15:51cemerick_fogus_: kamaikazes all around, then.
15:51amalloyLauJensen: you use an editor? i write my clojure with cat from the command line
15:51LauJensenHmm. I wonder how we ever got the Germans to stop thinking they won the war, maybe we can use the same strategy on Vim users
15:51andyfingerhutOh, the build seemed to succeed. No error messages, at least. I want to do some performance testing with the latest Clojure, and want to ensure I'm using it to compile contrib. Maybe it is and it just isn't obvious.
15:52ohpauleezlet me tell you all the things I can do in Vim and why I like them, and you can tell me the exact thing in emacs, that requires a long keystroke sequence
15:52duncanmwhat's the idiomatic way to get a seq of 10 random numbers?
15:52AWizzArdduncanm: repeatedly and #(rand-int 700)
15:52duncanmi thought i'd be using 'repeatedly'
15:52duncanmand
15:52duncanmoh
15:52ohpauleezduncanm: usually take and repeatedly
15:52AWizzArd,(repeatedly 4 #(rand-int 77))
15:52clojurebot(36 36 37 32)
15:53ohpauleezwow, I never knew that
15:53amalloyclojurebot: that's not very random-looking. trying to fool us humans?
15:53clojurebotExcuse me?
15:53AWizzArdohpauleez: repeatedly originally did not take an "n"-argument.
15:53ohpauleezahhh
15:53ohpauleezok
15:54_fogus_chouser: BTW, did you ever settle on a replacement WM?
15:54chouserno, still using ion.
15:54chouserdiscovered awesome wm is ... not.
15:54_fogus_chouser: it does look pretty sweet (ion)
15:55ohpauleezchouser: You're breaking my heart man
15:55ohpauleezWhat didn't you like about awesome
15:55ohpauleez(I came from ion, still really like, use awesome more)
15:55chousertabs
15:55chousertabs tabs tabs tabs
15:57ohpauleezas in you didn't like the tabs in awesome?
15:58chouserohpauleez: the didn't seem to exist except in an unmaintained plugin
15:58chouserthey
15:58chouserdid I miss them somehow?
15:59ohpauleezI use tabs just fine. They were default in my awesome. hmm
15:59ohpauleezBut no bother, ion rocks pretty hard too
16:00chouserhm. Well, maybe I'll try again later. :-)
16:01amalloyduncanm: http://pastie.org/1175275 if you're still looking for ideas about counting stuff
16:06andyfingerhutIf you build latest clojure-contrib 1.3.x, and use the latest clojure 1.3 to compile it, what commands do you use?
16:08chouserandyfingerhut: I thought I did that last time I built contrib, but looking at the readme again I may have built contrib using clojure 1.2. :-/
16:10andyfingerhutAh, I think I found the answer: http://groups.google.com/group/clojure/browse_thread/thread/2df8cfecb2d30fa9/eeb23dcff39eb316?lnk=gst&amp;q=build+contrib+latest+clojure#eeb23dcff39eb316
16:29svs`hello, while using congomongo, if I say (fetch :stops :as :json), the resulting JSON will not parse. With (fetch-one :stops :as :json), there are no problems. Could someone please let me know what i'm doing wrong?
16:32dpritchetti'm guessing fetch returns an entire sequence rather than a single element of it
16:37svs`yes it does....though why would the :as :json bit create syntactically incorrect JSON?
16:37ohpauleezsvs`: is the fetch lazy?
16:37svs`the JSON returned is { "_id" : { "$oid" : "4c9a18fc92427c5b337f2e07"} , "lng" : "73.84325695064035" , "lat" : "18.51638658242021" , "name" : "Deccan"}{ "_id" : { "$oid" : "4c9a298d92427c5b347f2e07"} , "lng" : "73.85279273999913" , "lat" : "18.512751236261558" , "name" : "Shanipar"}
16:37ohpauleezie: can it not decode the response because it doesn't have the full response?
16:38svs`it's returning both items, but will not parse. I tried the ruby json parser and got the same results
16:40dpritchettit looks like it just concatenates the results of all fetch-ones with no delimited character.
16:41dpritchettthis part is the end of the first and beginning of the second, yes? : "Deccan"}{ "_id" : {
16:41duncanmhow do i write a comparator for ranges represented by [lower-bound upper-bound] ?
16:42svs`i get it ... it should be "[{ <first record>},{<second-record>}]"....i can fix that...cheers
16:45dpritchettare you talking about something like this duncanm ? "The java.util.Comparator interface can be used to create objects to pass to sort methods or sorting data structures. A Comparator must define a compare function which takes two Objects and returns a -1, 0, or 1"
16:45kotarak#(< lower-bound % upper-bound)
16:48bobo_hm, with enlive templating, how can i create <tr><td>... for each entry in a map? http://gist.github.com/592526 that just gives me <td>..</td> for each row.
16:53amalloyduncanm: i posted a pastie link above, but the general idea is (into #{} (range lower upper))
16:53amalloyassuming you only want to compare integers, anyway, which was the impression i got
17:04rickmodewhen generating the new state of a defrecord object, is it more idiomatic and/or fast to instantiate a new record in the next state, or to use assoc?
17:04AWizzArdrickmode: assoc
17:06chouserAWizzArd: really? why?
17:07AWizzArdcode documentation
17:07rickmodeAWizzArd: Either way is very readable
17:11rickmodeAWizzArd: chouser: (assoc rec :foo a) vs (MyRec. :x (:x rec) :foo a) ... new record can be more verbose as here when the assoc doesn't modify :x. So I'm just wondering what assoc does with a defrecord under the covers.
17:11kotarakrickmode: records are used like maps. Hence to update a record field one uses (assoc r :field value)
17:11kotarakrickmode: + assoc is more robust against future changes of the fields of the record
17:12kotarakrickmode: + you can assoc "fields" which are actually not contained in the record
17:12rickmodekotarak: it must be instantiating a new record under the covers. Hopefully things are as efficient as persistent maps under the covers
17:13kotarakrickmode: believe: they are. Otherwise they wouldn't have made their way into clojure.
17:14chouser(assoc my-rec :a 1 :b 2) will create intermediate ephemeral garbage than a single ctor call wouldn't
17:14chouserthat
17:16amalloykotarak: i think chouser must be right here: assoc can't be as efficient as Record. for multiple fields
17:17kotarakamalloy: And it is more fragile. There is always a trade-off
17:17chouserwhich doesn't mean you shouldn't use it. I imagine an overwhelming majority of the time that extra garbage won't matter.
17:17kotarakspeed is overrated
17:17kotarakchouser: exactly. Just as one should not be afraid of extend
17:18amalloyi like to use assoc when i'm changing fewer than half of the fields, and Record. when i'm modifying most of them. though i probably should define a (make-record [{:keys}]) function and use that instead of raw Record.
17:18chouserit's just not obvious to me that the purpose and meaning of (assoc x :a b) is *always* clearer than (MyThing. b)
17:18rickmodechouser: well wait, what about the persistent nature? not knowing the implementation, I would expect a defrecord to work like a map with regard to persistence... and this would argue using assoc is more memory efficient despite ephemeral garbabe
17:19kotarakI think assoc is for modifying an existing record, while Record. should be used to create a new one.
17:19chouserhash-maps don't share structure below 32 elements
17:19chouserrecords never share structure
17:20chouserrecords never share structure on declared keys
17:20chouserhash-maps support transients
17:20chouserassoc doesn't use transient support
17:20rickmodesure the semantics are more clear using assoc vs. construction. However many datastructure example create new objects *and* maps as they enter a new state
17:20rickmodechouser: ah now this is more clear
17:21rickmodeso favor assoc vs. construction with an eye to readability... but consider construction if testing reveals a performance issue
17:21chouserin all, performance should generally be a very late concern. My dubious tone toward AWizzArd's statement was not because of performance.
17:21AWizzArdThen again, transient maps are interesting for cases when one wants to add lots of entries, while records will typically have just a few fields.
17:35lpetitHi, just wanted to let you know that a new release of ccw is available
17:36lpetitworthy bug fix release, + (now working) automatic installation of labrepl project ! (it even auto loads a browser in Eclipse at the end of the installation ! )
17:43lpetitOf course I don't expect you to bang your head on your ceiling due to this announcement ;-)
17:51defni thought "rickmode" might be rhickey's alter-ego
17:52rickmodeheh - no ... just another software hack
17:52defna more "chill" version of rich, no code to think about: "rick mode"
17:54duck1123It made me think of a minor mode that changes buffers to read never gonna give you up
17:56duck1123it's too bad you can't embed youtube videos inside emacs yet.
17:57stain_http://clojure.org/search/view/tutorial :-(
17:58rickmodeduck1123: ack... I picked the moniker before rick astley stole my name
17:59stain_instead the getting_started page immediately says how you can deug using JSwat. Not quite the smooth tutorial ride I was hoping for..
17:59stain_debug
18:02dakronestain_: were you looking for debugging tutorials, or just general clojure tutorials?
18:13jfieldsis there a fn or some java that will give me a list of all files in a dir and all subdirs?
18:13mrBlissjfields: file-seq
18:14jfieldsmrBliss, awesome. thanks
18:15arohnerare there any known bugs in require? I'm seeing a behavior where if a require blows up because of an exception, re-requiring the file doesn't attempt to reload the file that threw
18:19ohpauleezI wanted to run an idea by the channel... I've been playing around with distributed message and job queues in clojure, and started writing something similar to a remote namespacer
18:19ohpauleezwould anyone ever find interest in an ns like macro for doing xmlrpc in clojure?
18:23konrIf I have a structure set with (def foo (ref [{:meta {:foo 'bar}}, {:meta {:baka 'waka}}])), how can I alter one of the inner hashmaps to, say, [{:meta {:foo bar :bak wak}} {:meta {:baka waka}}]?
18:24mrBliss,(doc update-in)
18:24clojurebot"([m [k & ks] f & args]); 'Updates' a value in a nested associative structure, where ks is a sequence of keys and f is a function that will take the old value and any supplied args and return the new value, and returns a new nested structure. If any levels do not exist, hash-maps will be created."
18:25ohpauleezkonr, you can use assoc-in
18:25ohpauleezor update-in
18:25mrBlissthat's the one I meant :)
18:26arohnerohpauleez: you mean magically exposing clojure fns in a file/ns over xmlrpc?
18:26ohpauleezyes
18:26ohpauleezintroducing an :expose
18:26arohnerohpauleez: I don't need that in my current projects, but I would have loved it in some of my previous ones
18:26ohpauleezand :remote-use :remote-require
18:27arohnerI wrote a half-assed version of that in ruby a couple of years ago
18:28ohpauleezcool, thanks for the feedback arohner
18:30arohneroh that's cool. I hung emacs by trying to connect via slime
18:30arohnerah, hit C-g enough, and the problem goes away
18:31konrhmmm, how about when I have only the reference to part of the structure I want to change? Like to {:meta {:foo bar}} on [{:meta ...} {:meta ...} ...] - Do I need to keep track of where I am?
18:32lpetitkonr: sure
18:32lpetitkonr: since you do not change a structure in place, but create a new value from an old one
18:45lpetit,(update-in [{:meta {:foo 'bar}} {:meta {:baka 'waka}}] [0 :meta] assoc :bak 'wak)
18:45clojurebot[{:meta {:bak wak, :foo bar}} {:meta {:baka waka}}]
18:45lpetitkonr: ^^^
18:46konrlpetit: thanks :) I wasn't aware I could reference the elements of a vector using the position!
18:47lpetityes, their index is their key when vectors are seen as "associable/dictionaries"
19:04cmd_exit
19:04cmd_exit
19:04cmd_exit
19:04cmd_quit
19:04cmd_quit
19:04cmd_exit
19:04arohneralso, the ns already refers to exception is broken. If I ns foo :uses ns bar, and then I (require 'foo :reload), I get an unconditional exception
19:04arohnereven though the var that's being stomped on is "the same"