#clojure logs

2010-02-27

00:33chouserslyphon: I'd use a vector there.
00:33chouserslyphon: I'd use a vector there.
00:34slyphonyeah, i thought so
00:34chouserhelps suggest to people that that's where 'ctx' is being introduced or defined.
00:35slyphonchouser: in a similar vein, i'm doing a similar pattern with a MBeansServerConnection, only with that macro i'm handing in the jmx-url and the sym to bind to
00:35slyphonshould i make it like [sym jmx-url] so it's like a 'let'
00:35Apage43waha
00:36Apage43i saved the day at work today.. with the power of clojure
00:39cemericksheesh, the funders page is *long* now
02:05slyphonyou know you're getting silly when you start writing (defmacro dosomething `(defmacro ...))
02:10Crowbar7lol
02:11slyphonYou're Doing it Wrong
02:11G0SUBslyphon, http://www.xach.com/img/doing-it-wrong-at-a4.jpg
02:11slyphonhahaha
02:12G0SUB:)
02:12slyphonwho is that in the picture?
02:12G0SUBslyphon, I have that pic pasted on my office wall
02:12slyphon:D
02:12G0SUBslyphon, dude!
02:12slyphon:/
02:12G0SUBslyphon, that's Uncle John
02:12slyphonis that knuth?
02:13G0SUBslyphon, John McCarthy. the discoverer of Lisp.
02:13slyphonohhhhhh
02:13slyphonright right right
02:13slyphoni don't think i've ever seen a photo of him before
02:13slyphoni imagined him tweedier
02:13G0SUBslyphon, well, he was handsome :)
02:13slyphon:D
02:14slyphonheh, i haven't seen 'xach' in forever
02:14slyphonsince i stopped harrasing him in #lisp
02:15G0SUBslyphon, hehe. He is active on proggit.
02:16slyphonah, right on
02:19LauJensenMorning team
02:28G0SUBLauJensen, it's afternoon here :)
02:29LauJensenits a big earth :)
02:29G0SUBLauJensen, indeed :)
05:31hamzagents i have a list of true false values (true false) how can i
05:31hamza apply or or and on them?
05:35morphlinghamza: and and or aren't functions, you have to wrap them like this: (fn [a b] (and a b))
05:35ska2342hamza: can't you use every?
05:37ska2342,(every? true? '(true true))
05:37clojurebottrue
05:38ska2342,(some true? '(false true false))
05:38clojurebottrue
05:39hamzathanks a lot guys, every and some would work.
06:07dsopdoes someone know the license of the clojure logo
06:08sparievdsop: http://groups.google.com/group/clojure/browse_thread/thread/7f179c79f0d0bb3e - might be relevant
07:16Licenser*sighs*
07:55bsteuberam I the only person not satisfied with (comment foo bar) returning nil instead of being completely ignored by the preprocessor?
08:02Chousukebsteuber: use #_ if you want to ignore a form
08:03Chousukebsteuber: comment is just a macro so the reader can't do anything about it :)
08:05hamzagents, i have a seqence of sequences i would like to transfor every say second item in the inner sequences, ((:a :b) (:c :b)) to ((:a :d) (:c :d)) is there a better way to do it then maping over the outer sequence and using subvec replace the item..
08:07bsteuberChousuke: I know, I'd just prefer comment to be "special" so I could use it everywhere like other comment syntax
08:07bsteuberor have something like #_ to ignore multiple forms
08:07Chousukebsteuber: you can do #_(comment ...) :)
08:07bsteuberog, I can use #_(foo bar), right? stupid me :)
08:08ChousukeI think the comment macro is mostly intended for example code at the top level rather than any inline comments
08:09bsteuberhm, I see
08:09Chousukethe contents of the comment macro get properly syntax highlighted and can be easily evaluated using eg. slime
08:09bsteuberok, so I'll use #_(...) to comment out binding forms etc.
08:10bsteuberthanks for clarification
08:23bsteuberhamza: why subvec? I guess my naive implementation would me something like
08:23bsteuber(map (fn [[x y]] [x (f y)]) some-seq)
08:24bsteuberhow does your code look like?
08:28hamzabsteuber: that looks much better than mine, i'll go with yours. I was splitting them with nth then putting them back together..
08:29jeffmesshas anyone here got clojure in action and joy of clojure? which would you recommend out of the two?
08:34bsteuberjeffmess: hard to tell with unfinished books - I'll probably read both once they're out :)
08:38sparievjeffmess: imo Joy Of Clojure is more polished at the time being
08:40jeffmessspariev: thats what i was leaning towards
08:41jeffmessthanks!
08:41sparievnp
11:02joshua-choiIs anyone watching? I have a question—is there a more efficient way to change a map?
11:02joshua-choiFor instance, I want to do (->> my-map (filter #(< (val %) 10)) (into {})), but that seems so inefficient to me.
11:04Raynesjoshua-choi: I don't know about the efficiency of such a thing, but I'm pretty sure that's how it's usually done.
11:07joshua-choiYeah, I was afraid so. But it seems to create a lazy sequence of map-entries, puts some of them into a completely new map transient, makes the transient persistent, and then destroys the old map.
11:07joshua-choiI don't know how Clojure's data structures work internally that well, but I was hoping that there would be a less wasteful way. Oh well.
11:10bsteubermaybe you could manually loop through the map and directly build the transient?
11:19Chousukejoshua-choi: that's pretty much the most efficient way to do it.
11:20joshua-choibsteuder's suggestion? Or filter/into?
11:20Chousukefilter/into
11:21Chousukethe seq is just a view to the original map, so "building" it doesn't cost much at all, and into is the most efficient way to build a map out of a sequence
11:22RaynesI'm so into into.
11:23joshua-choiChousuke: Okay, thanks. That's reassuring.
11:23Chousukeof course, you could be more efficient by using mutable data structures, but then you forfeit all the benefits of functional programming
11:23joshua-choiWell, I guess you could do what bsteuder suggested. Make a function that internally mutated a transient.
11:24ChousukeI don't think that would be much more efficient than the into approach
12:14krumholthi i want to compile a file. I can require it but when i try to compile it i get an exceptionj ava.io.IOException: No such file or directory (heightmap.clj:1) what could be the problem?
12:34dabd I have the following on my classpath "/home/foo/" and a clojure file in "/home/foo/bar/baz.clj" but if I try to use clojure.lang.RT.loadResourceScript("bar/baz.clj") from a Java class it doesn't find the file. What am I missing?
13:23dsopare there plans to get clojure dev on gmane?
13:41rhickey_dsop: not if that opens a gateway to posts from gmane
14:40RaynesIt's quiet...
14:40RaynesToo quiet.
14:41ordnungswidrigshhhhhh
14:52arohnerI've been feeling the need to write a library to validate complex datastructures. Things like this datastructure is a nested map. it has keys foo, bar. Bar's value is a vector of length 5
14:52arohnerDoes anyone know of a library like this? Is there anything worth copying from other languages?
14:56AWizzArdarohner: this sounds useful and nice, and I would love to have such a tool. Just a comment though: when you create your complex datastructures through a constructor function (make-my-thing ...) then this fn should output only valid complex datastructures.
14:58arohnerAWizzArd: my general idea is a macro that will produce a fn. (valid? validator-fn object) returns a bool. (validate! validator-fn obj) throws an exception on failure. Then you can hook that into pre/post conditions
14:58arohner{:pre [(valid? foo arg1) (valid? bar arg2)]}
14:59arohnerI'm starting to want a pre/post conditions that run in production. i.e. a "debug" pre/post and "always" pre/post
15:02webbenarohner: Not something I've used, but http://rjbs.manxome.org/rx/ might be worth a look. (Very similar problem space.)
15:03arohnerwebben: thanks! exactly the kind of example I'm looking for
15:04webbenyw
15:06hiredmanarohner: there was a jcromartie in here working on some kind of validation system for structs
15:06hiredmanhttp://gist.github.com/314809
15:07arohnerhiredman: yeah, I saw some of his examples. It seemed geared towards web input validation. I need something more general purpose, for backend code
15:07arohnerand I need working code, rather than example usage :-)
15:07hiredmanright
15:11ordnungswidrigarohner: I just pushed clj-validate to github the other day.
15:11rshwhat is the difference between a ref and an atom? I can't figure it out from the clojure.org doc
15:11ordnungswidrigarohner: not complete but working for me
15:12StartsWithKrsh you can place a ref in a transaction
15:14rshthanks StartsWithK
15:19mabesarohner: if you end up writing a rx (or similar) validator it would be awesome it you shared your work (via the ML or back to the Rx project).. I'm just looking at it now and it seems very useful
16:07eglyphhello everybody. i'm trying to setup emacs together with clojure and compojure. slime plays fine with clojure, but i can't get compojure working.
16:10eglyphif i (require) it, it fails with No Message, if i (use) it it fails with java.lang.NoClassDefFoundError, so I guess, it's classpath related thing
16:10eglyphbut then, (System/getProperty "java.class.path") shows that compojure and all the dependencies are in classpath
16:11eglyphwhat elese should i check?
16:17StartsWithKCan you place something else on cp and check that it also fails?
16:19eglyphI just tried compojure without emacs. it fails too, so it's definitely classpath related
16:21StartsWithKAre you using the same version of clojure in all your tools? Is something maybe using -bootclasspath option?
16:21eglyphyes, the version is the same. it's just symlinked everywhere
16:22StartsWithKCan you paste java cmd call you use
16:22eglyphone moment
16:24eglyphhttp://paste.org/pastebin/view/15839
16:24eglyphmy ~/.clojure contains clojure.jar and clojure-contrib.jar
16:25StartsWithKHeh, can you paste it here :) i'm on a (cheep) phone
16:26eglyphjava -cp $HOME/.clojure/*:/opt/compojure:/opt/compojure/deps/*: clojure.main
16:26eglyph
16:28eglyphputting jline somewhere in classpath works. it makes me wonder
16:28StartsWithKWeird
16:28eglyphagreed
16:29StartsWithKI think thats a new one :)
16:29eglyphbasically all the tutorials on compojure boil down to "put everything into your classpath"
16:30eglyphso i even tried to copy them all into classpath instead of symlinking
16:32StartsWithKAnd with jline it all works in emacs too?
16:33eglyphlet me check it. i was playing with it from a shell
16:39eglyphemacs gives the same error as for compojure. so I'm doing something completely wrong
16:41StartsWithKAnything i compojure aot compiled with different clojure version?
16:44eglyphi think no, because i've built it from git repo. so it should use my version of clojure
16:44eglyphbut i'm not sure
16:47somniumeglyph: maybe try getting it from clojars via lein. its easy and likely to resolve any classpath/versioning issues
16:50eglyphnever heard of clojars. :) how do i use it? they explain how to "push", but i need "pull", do i?
16:53qedeglyph: clojars.org
16:54StartsWithKclojars.org/repo
16:55StartsWithKFind a jar manualy if you dont want to use any extra tools
16:57eglyphworks. thank you.
16:58StartsWithK_homejava -cp "/home/you/.clojure/*:/opt/compojure:/opt/compojure/deps/*" clojure.main
16:58StartsWithK_homewill this work?
16:58eglyphthe .jar from repo is twice as big the one i've built
16:59eglyphexactly this string doesn't work. it was my initial attempt.
18:36technomancy_ato: having some trouble scping to clojars@clojars.org; any idea what's up?
20:42maxhodakhttp://github.com/myfit/clj-facebook/blob/master/src/facebook/client.clj#L58
20:42maxhodakdying saying "First argument to def must be a Symbol"
20:43maxhodakbut (prn (type method)) gives "clojure.lang.Symbol"
20:50the-kennymaxhodak: generate-methods must be a macro too, you can't supply a variable containing a symbol as the first argument
20:54the-kennyOh, and I'd also not use (def ...) inside a function. That's not good
20:54maxhodakthe-kenny: so i got it to work when i replaced the (first method) (second method) ... with a let
20:55maxhodaki guess the macro acts *directly* on the arguments, not the arguments' evaluations
20:56the-kennyexactly
20:56maxhodakthe-kenny: http://github.com/myfit/clj-facebook/blob/master/src/facebook/client.clj#L58
20:57maxhodakso now if i replace ~args with [] it works
20:57maxhodak(~methods works fine)
20:57maxhodakbut the ~args part is dying
20:58Chousukemaxhodak: you have ~@args
20:58maxhodakChousuke: yeah thats me playing with combinations to see what it does
20:58the-kenny(do ~@`(1 2 3)) expands to (do 1 2 3). You want ~ without the @
20:58maxhodakChousuke: (since ~args wasn't working, i tried ~@args)
20:59Chousuke~args should work
20:59clojurebotwhat should I do today, it is the weekend and all
20:59Chousukeproviding it's a vector, of course
20:59maxhodakChousuke: Don't know how to create ISeq from: clojure.lang.Symbol
20:59maxhodakChousuke: it is, it's the 3rd part of each vector in fb-methods
21:00maxhodak(prn (type args)) on L78 says thats right
21:01maxhodakclojure.lang.PersistentVector
21:01Chousukemaybe you have the error somewhere else
21:01Chousukebecause as far as I can tell, that's fine :/
21:02Chousuke... ah
21:02Chousukenever mind
21:02Chousukeyou're never actually passing a vector to the macro
21:03Chousukeyou're passing the symbol args
21:03Chousukeyou can't use macros in a doseq like that .P
21:03maxhodakoh?
21:03maxhodakhmm
21:03Chousukearguments to macros are not evaluated, so when you call (define-method symb map args) you're calling it with three symbols as an argument
21:03Chousukeas arguments, even :P
21:04maxhodaki guess i could just put the defn in the doseq
21:04Chousukethat won't work very well either.
21:04maxhodakwell, no that wouldn't work
21:04maxhodaki just don't want to list out all of the methods as separate fxns
21:05maxhodakit's duplicating basically all of the code for each
21:05Chousukewell you can always access the method table directly in the macro
21:05maxhodaki could do (define-method 'admin-get-allocation "admin.getAllocation" []) ...
21:05maxhodakrather than looping through it
21:06Chousukethat would be (define-method admin-get-allocation "..." [])
21:06maxhodakthat'd be simple enough with a column-oriented selection
21:06maxhodakthough a little wasteful
21:06maxhodakyeah
21:06Chousukebut hm, the non-toplevel def in your make-facebook-connection is also suspect :P
21:07Chousukeit's not actually making a connection :P
21:07maxhodakChousuke: it is; i should use Java sockets or a with-facebook type construct
21:07maxhodakChousuke: no but *fb-conn* is references in call-method
21:07maxhodaks/references/referenced
21:07Chousukeat least call it init-facebook-info! or something that indicates it's destructive.
21:07maxhodakso you don't need to pass a "conn" variable anywhere
21:07maxhodakdestructive?
21:07Chousukeyes
21:08Chousukeit redefines a global variable, so it's destructive
21:08Chousukeor has side-effects, whichever terminology you prefer :P
21:08maxhodakok
21:09maxhodakrenaming it init-facebook!
21:09maxhodakdoes the bang operator usually denote side-effects?
21:10Chousukean approach like that is fine if you will only ever have one connection, but if you ever have the need for more, that'll become your primary pain :)
21:10Chousukeyeah.
21:10maxhodakChousuke: yeah i've never seen an fb app that's dealt with more than one api key
21:10maxhodakChousuke: but, it is possible, and should be refactored to use some kind of open-stack eventualy
21:13Chousukesince you're doing ugly things anyway, you could perhaps just use eval in generate-methods :P
21:13ChousukeI think (eval `(define-method ~symb ~map ~args)) in the doseq would work just fine :P
21:15Chousukesomnium: the dark side is tempting
21:16technomancythat can be done with a macro instead of eval; see clojure.http.resourcefully
21:17Chousukesure. I was just suggesting a quick'n'dirty fix :P
21:17technomancyhttp://p.hagelb.org/define-method.html
21:18maxhodaktechnomancy: yeah i was basing my implementation off of resourcefully's example
21:19maxhodaktechnomancy: the issue was that you have to call (define-method) directly for each arg set, rather than putting it in a doseq or map
21:19maxhodak(right?)
21:19technomancymaxhodak: you need that to get line numbers in stack traces
21:20technomancyotherwise you can use a doseq
21:34maxhodakto build a hashmap of {:foo foo :bar bar ... } can you do something like (doseq [arg args] `{:~arg ~arg}) ?
21:44fanaticomaxhodak: http://gist.github.com/304345
21:45somniumChousuke: is your reader on github?
21:46somniumChousuke: ah, found it
21:47fanaticomaxhodak: damn, actually that's an older version that doesn't work with locals. I'll try to dig up the current version.
21:48maxhodakfanatico: awesome.. that looks like what i'm trying to do though
21:53fanaticomaxhodak: (defmacro named-map [& keys] `(zipmap (map keyword '~keys) (list ~@keys)))
21:53fanatico(let [a 1, b 2] (named-map a b)) ; => {:a 1, :b 2}
21:56maxhodakso that's not quite what i'm trying to do... i want to pass in a vector like [integration_point_name]
21:56maxhodakand build a hashmap of {:integration_point_name integration_point_name ...}
21:56maxhodaklike let me push to github so i can show you exactly what i mean
21:59maxhodakhttp://github.com/myfit/clj-facebook/blob/master/src/facebook/client.clj#L65
22:00maxhodaki'm building a map of arguments to pass ingo call-method there; they have to be named and they don't necessarily have a default value
22:06fanaticosomething like (let [a 1 b 2] (named-map [a b])) => {:a 1 :b 2} ?
22:07fanaticojust through a let around the body of the macro and deconstruct keys.
22:08fanaticos/through/throw
22:19maxhodakfanatico: well, its a macro for generating functions (defn's)
22:19maxhodakso rather than {:a 1 :b 2}, i want {:a a :b b} to be filled in by my defn's arguments [a b]
22:20fanaticojust merge the named map with the defaults.
22:26fanaticomaxhodak: something like http://gist.github.com/317153
23:47DeusExPikachuwhat are some common pitfalls/gotchas for using eval?