2010-02-27
| 00:33 | chouser | slyphon: I'd use a vector there. |
| 00:33 | chouser | slyphon: I'd use a vector there. |
| 00:34 | slyphon | yeah, i thought so |
| 00:34 | chouser | helps suggest to people that that's where 'ctx' is being introduced or defined. |
| 00:35 | slyphon | chouser: 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:35 | slyphon | should i make it like [sym jmx-url] so it's like a 'let' |
| 00:35 | Apage43 | waha |
| 00:36 | Apage43 | i saved the day at work today.. with the power of clojure |
| 00:39 | cemerick | sheesh, the funders page is *long* now |
| 02:05 | slyphon | you know you're getting silly when you start writing (defmacro dosomething `(defmacro ...)) |
| 02:10 | Crowbar7 | lol |
| 02:11 | slyphon | You're Doing it Wrong |
| 02:11 | G0SUB | slyphon, http://www.xach.com/img/doing-it-wrong-at-a4.jpg |
| 02:11 | slyphon | hahaha |
| 02:12 | G0SUB | :) |
| 02:12 | slyphon | who is that in the picture? |
| 02:12 | G0SUB | slyphon, I have that pic pasted on my office wall |
| 02:12 | slyphon | :D |
| 02:12 | G0SUB | slyphon, dude! |
| 02:12 | slyphon | :/ |
| 02:12 | G0SUB | slyphon, that's Uncle John |
| 02:12 | slyphon | is that knuth? |
| 02:13 | G0SUB | slyphon, John McCarthy. the discoverer of Lisp. |
| 02:13 | slyphon | ohhhhhh |
| 02:13 | slyphon | right right right |
| 02:13 | slyphon | i don't think i've ever seen a photo of him before |
| 02:13 | slyphon | i imagined him tweedier |
| 02:13 | G0SUB | slyphon, well, he was handsome :) |
| 02:13 | slyphon | :D |
| 02:14 | slyphon | heh, i haven't seen 'xach' in forever |
| 02:14 | slyphon | since i stopped harrasing him in #lisp |
| 02:15 | G0SUB | slyphon, hehe. He is active on proggit. |
| 02:16 | slyphon | ah, right on |
| 02:19 | LauJensen | Morning team |
| 02:28 | G0SUB | LauJensen, it's afternoon here :) |
| 02:29 | LauJensen | its a big earth :) |
| 02:29 | G0SUB | LauJensen, indeed :) |
| 05:31 | hamza | gents i have a list of true false values (true false) how can i |
| 05:31 | hamza | apply or or and on them? |
| 05:35 | morphling | hamza: and and or aren't functions, you have to wrap them like this: (fn [a b] (and a b)) |
| 05:35 | ska2342 | hamza: can't you use every? |
| 05:37 | ska2342 | ,(every? true? '(true true)) |
| 05:37 | clojurebot | true |
| 05:38 | ska2342 | ,(some true? '(false true false)) |
| 05:38 | clojurebot | true |
| 05:39 | hamza | thanks a lot guys, every and some would work. |
| 06:07 | dsop | does someone know the license of the clojure logo |
| 06:08 | spariev | dsop: http://groups.google.com/group/clojure/browse_thread/thread/7f179c79f0d0bb3e - might be relevant |
| 07:16 | Licenser | *sighs* |
| 07:55 | bsteuber | am I the only person not satisfied with (comment foo bar) returning nil instead of being completely ignored by the preprocessor? |
| 08:02 | Chousuke | bsteuber: use #_ if you want to ignore a form |
| 08:03 | Chousuke | bsteuber: comment is just a macro so the reader can't do anything about it :) |
| 08:05 | hamza | gents, 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:07 | bsteuber | Chousuke: I know, I'd just prefer comment to be "special" so I could use it everywhere like other comment syntax |
| 08:07 | bsteuber | or have something like #_ to ignore multiple forms |
| 08:07 | Chousuke | bsteuber: you can do #_(comment ...) :) |
| 08:07 | bsteuber | og, I can use #_(foo bar), right? stupid me :) |
| 08:08 | Chousuke | I think the comment macro is mostly intended for example code at the top level rather than any inline comments |
| 08:09 | bsteuber | hm, I see |
| 08:09 | Chousuke | the contents of the comment macro get properly syntax highlighted and can be easily evaluated using eg. slime |
| 08:09 | bsteuber | ok, so I'll use #_(...) to comment out binding forms etc. |
| 08:10 | bsteuber | thanks for clarification |
| 08:23 | bsteuber | hamza: why subvec? I guess my naive implementation would me something like |
| 08:23 | bsteuber | (map (fn [[x y]] [x (f y)]) some-seq) |
| 08:24 | bsteuber | how does your code look like? |
| 08:28 | hamza | bsteuber: that looks much better than mine, i'll go with yours. I was splitting them with nth then putting them back together.. |
| 08:29 | jeffmess | has anyone here got clojure in action and joy of clojure? which would you recommend out of the two? |
| 08:34 | bsteuber | jeffmess: hard to tell with unfinished books - I'll probably read both once they're out :) |
| 08:38 | spariev | jeffmess: imo Joy Of Clojure is more polished at the time being |
| 08:40 | jeffmess | spariev: thats what i was leaning towards |
| 08:41 | jeffmess | thanks! |
| 08:41 | spariev | np |
| 11:02 | joshua-choi | Is anyone watching? I have a question—is there a more efficient way to change a map? |
| 11:02 | joshua-choi | For instance, I want to do (->> my-map (filter #(< (val %) 10)) (into {})), but that seems so inefficient to me. |
| 11:04 | Raynes | joshua-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:07 | joshua-choi | Yeah, 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:07 | joshua-choi | I 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:10 | bsteuber | maybe you could manually loop through the map and directly build the transient? |
| 11:19 | Chousuke | joshua-choi: that's pretty much the most efficient way to do it. |
| 11:20 | joshua-choi | bsteuder's suggestion? Or filter/into? |
| 11:20 | Chousuke | filter/into |
| 11:21 | Chousuke | the 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:22 | Raynes | I'm so into into. |
| 11:23 | joshua-choi | Chousuke: Okay, thanks. That's reassuring. |
| 11:23 | Chousuke | of course, you could be more efficient by using mutable data structures, but then you forfeit all the benefits of functional programming |
| 11:23 | joshua-choi | Well, I guess you could do what bsteuder suggested. Make a function that internally mutated a transient. |
| 11:24 | Chousuke | I don't think that would be much more efficient than the into approach |
| 12:14 | krumholt | hi 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:34 | dabd | 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:23 | dsop | are there plans to get clojure dev on gmane? |
| 13:41 | rhickey_ | dsop: not if that opens a gateway to posts from gmane |
| 14:40 | Raynes | It's quiet... |
| 14:40 | Raynes | Too quiet. |
| 14:41 | ordnungswidrig | shhhhhh |
| 14:52 | arohner | I'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:52 | arohner | Does anyone know of a library like this? Is there anything worth copying from other languages? |
| 14:56 | AWizzArd | arohner: 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:58 | arohner | AWizzArd: 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:58 | arohner | {:pre [(valid? foo arg1) (valid? bar arg2)]} |
| 14:59 | arohner | I'm starting to want a pre/post conditions that run in production. i.e. a "debug" pre/post and "always" pre/post |
| 15:02 | webben | arohner: Not something I've used, but http://rjbs.manxome.org/rx/ might be worth a look. (Very similar problem space.) |
| 15:03 | arohner | webben: thanks! exactly the kind of example I'm looking for |
| 15:04 | webben | yw |
| 15:06 | hiredman | arohner: there was a jcromartie in here working on some kind of validation system for structs |
| 15:06 | hiredman | http://gist.github.com/314809 |
| 15:07 | arohner | hiredman: yeah, I saw some of his examples. It seemed geared towards web input validation. I need something more general purpose, for backend code |
| 15:07 | arohner | and I need working code, rather than example usage :-) |
| 15:07 | hiredman | right |
| 15:11 | ordnungswidrig | arohner: I just pushed clj-validate to github the other day. |
| 15:11 | rsh | what is the difference between a ref and an atom? I can't figure it out from the clojure.org doc |
| 15:11 | ordnungswidrig | arohner: not complete but working for me |
| 15:12 | StartsWithK | rsh you can place a ref in a transaction |
| 15:14 | rsh | thanks StartsWithK |
| 15:19 | mabes | arohner: 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:07 | eglyph | hello 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:10 | eglyph | if 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:10 | eglyph | but then, (System/getProperty "java.class.path") shows that compojure and all the dependencies are in classpath |
| 16:11 | eglyph | what elese should i check? |
| 16:17 | StartsWithK | Can you place something else on cp and check that it also fails? |
| 16:19 | eglyph | I just tried compojure without emacs. it fails too, so it's definitely classpath related |
| 16:21 | StartsWithK | Are you using the same version of clojure in all your tools? Is something maybe using -bootclasspath option? |
| 16:21 | eglyph | yes, the version is the same. it's just symlinked everywhere |
| 16:22 | StartsWithK | Can you paste java cmd call you use |
| 16:22 | eglyph | one moment |
| 16:24 | eglyph | http://paste.org/pastebin/view/15839 |
| 16:24 | eglyph | my ~/.clojure contains clojure.jar and clojure-contrib.jar |
| 16:25 | StartsWithK | Heh, can you paste it here :) i'm on a (cheep) phone |
| 16:26 | eglyph | java -cp $HOME/.clojure/*:/opt/compojure:/opt/compojure/deps/*: clojure.main |
| 16:26 | eglyph | |
| 16:28 | eglyph | putting jline somewhere in classpath works. it makes me wonder |
| 16:28 | StartsWithK | Weird |
| 16:28 | eglyph | agreed |
| 16:29 | StartsWithK | I think thats a new one :) |
| 16:29 | eglyph | basically all the tutorials on compojure boil down to "put everything into your classpath" |
| 16:30 | eglyph | so i even tried to copy them all into classpath instead of symlinking |
| 16:32 | StartsWithK | And with jline it all works in emacs too? |
| 16:33 | eglyph | let me check it. i was playing with it from a shell |
| 16:39 | eglyph | emacs gives the same error as for compojure. so I'm doing something completely wrong |
| 16:41 | StartsWithK | Anything i compojure aot compiled with different clojure version? |
| 16:44 | eglyph | i think no, because i've built it from git repo. so it should use my version of clojure |
| 16:44 | eglyph | but i'm not sure |
| 16:47 | somnium | eglyph: maybe try getting it from clojars via lein. its easy and likely to resolve any classpath/versioning issues |
| 16:50 | eglyph | never heard of clojars. :) how do i use it? they explain how to "push", but i need "pull", do i? |
| 16:53 | qed | eglyph: clojars.org |
| 16:54 | StartsWithK | clojars.org/repo |
| 16:55 | StartsWithK | Find a jar manualy if you dont want to use any extra tools |
| 16:57 | eglyph | works. thank you. |
| 16:58 | StartsWithK_home | java -cp "/home/you/.clojure/*:/opt/compojure:/opt/compojure/deps/*" clojure.main |
| 16:58 | StartsWithK_home | will this work? |
| 16:58 | eglyph | the .jar from repo is twice as big the one i've built |
| 16:59 | eglyph | exactly this string doesn't work. it was my initial attempt. |
| 18:36 | technomancy | _ato: having some trouble scping to clojars@clojars.org; any idea what's up? |
| 20:42 | maxhodak | http://github.com/myfit/clj-facebook/blob/master/src/facebook/client.clj#L58 |
| 20:42 | maxhodak | dying saying "First argument to def must be a Symbol" |
| 20:43 | maxhodak | but (prn (type method)) gives "clojure.lang.Symbol" |
| 20:50 | the-kenny | maxhodak: generate-methods must be a macro too, you can't supply a variable containing a symbol as the first argument |
| 20:54 | the-kenny | Oh, and I'd also not use (def ...) inside a function. That's not good |
| 20:54 | maxhodak | the-kenny: so i got it to work when i replaced the (first method) (second method) ... with a let |
| 20:55 | maxhodak | i guess the macro acts *directly* on the arguments, not the arguments' evaluations |
| 20:56 | the-kenny | exactly |
| 20:56 | maxhodak | the-kenny: http://github.com/myfit/clj-facebook/blob/master/src/facebook/client.clj#L58 |
| 20:57 | maxhodak | so now if i replace ~args with [] it works |
| 20:57 | maxhodak | (~methods works fine) |
| 20:57 | maxhodak | but the ~args part is dying |
| 20:58 | Chousuke | maxhodak: you have ~@args |
| 20:58 | maxhodak | Chousuke: yeah thats me playing with combinations to see what it does |
| 20:58 | the-kenny | (do ~@`(1 2 3)) expands to (do 1 2 3). You want ~ without the @ |
| 20:58 | maxhodak | Chousuke: (since ~args wasn't working, i tried ~@args) |
| 20:59 | Chousuke | ~args should work |
| 20:59 | clojurebot | what should I do today, it is the weekend and all |
| 20:59 | Chousuke | providing it's a vector, of course |
| 20:59 | maxhodak | Chousuke: Don't know how to create ISeq from: clojure.lang.Symbol |
| 20:59 | maxhodak | Chousuke: it is, it's the 3rd part of each vector in fb-methods |
| 21:00 | maxhodak | (prn (type args)) on L78 says thats right |
| 21:01 | maxhodak | clojure.lang.PersistentVector |
| 21:01 | Chousuke | maybe you have the error somewhere else |
| 21:01 | Chousuke | because as far as I can tell, that's fine :/ |
| 21:02 | Chousuke | ... ah |
| 21:02 | Chousuke | never mind |
| 21:02 | Chousuke | you're never actually passing a vector to the macro |
| 21:03 | Chousuke | you're passing the symbol args |
| 21:03 | Chousuke | you can't use macros in a doseq like that .P |
| 21:03 | maxhodak | oh? |
| 21:03 | maxhodak | hmm |
| 21:03 | Chousuke | arguments 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:03 | Chousuke | as arguments, even :P |
| 21:04 | maxhodak | i guess i could just put the defn in the doseq |
| 21:04 | Chousuke | that won't work very well either. |
| 21:04 | maxhodak | well, no that wouldn't work |
| 21:04 | maxhodak | i just don't want to list out all of the methods as separate fxns |
| 21:05 | maxhodak | it's duplicating basically all of the code for each |
| 21:05 | Chousuke | well you can always access the method table directly in the macro |
| 21:05 | maxhodak | i could do (define-method 'admin-get-allocation "admin.getAllocation" []) ... |
| 21:05 | maxhodak | rather than looping through it |
| 21:06 | Chousuke | that would be (define-method admin-get-allocation "..." []) |
| 21:06 | maxhodak | that'd be simple enough with a column-oriented selection |
| 21:06 | maxhodak | though a little wasteful |
| 21:06 | maxhodak | yeah |
| 21:06 | Chousuke | but hm, the non-toplevel def in your make-facebook-connection is also suspect :P |
| 21:07 | Chousuke | it's not actually making a connection :P |
| 21:07 | maxhodak | Chousuke: it is; i should use Java sockets or a with-facebook type construct |
| 21:07 | maxhodak | Chousuke: no but *fb-conn* is references in call-method |
| 21:07 | maxhodak | s/references/referenced |
| 21:07 | Chousuke | at least call it init-facebook-info! or something that indicates it's destructive. |
| 21:07 | maxhodak | so you don't need to pass a "conn" variable anywhere |
| 21:07 | maxhodak | destructive? |
| 21:07 | Chousuke | yes |
| 21:08 | Chousuke | it redefines a global variable, so it's destructive |
| 21:08 | Chousuke | or has side-effects, whichever terminology you prefer :P |
| 21:08 | maxhodak | ok |
| 21:09 | maxhodak | renaming it init-facebook! |
| 21:09 | maxhodak | does the bang operator usually denote side-effects? |
| 21:10 | Chousuke | an 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:10 | Chousuke | yeah. |
| 21:10 | maxhodak | Chousuke: yeah i've never seen an fb app that's dealt with more than one api key |
| 21:10 | maxhodak | Chousuke: but, it is possible, and should be refactored to use some kind of open-stack eventualy |
| 21:13 | Chousuke | since you're doing ugly things anyway, you could perhaps just use eval in generate-methods :P |
| 21:13 | Chousuke | I think (eval `(define-method ~symb ~map ~args)) in the doseq would work just fine :P |
| 21:15 | Chousuke | somnium: the dark side is tempting |
| 21:16 | technomancy | that can be done with a macro instead of eval; see clojure.http.resourcefully |
| 21:17 | Chousuke | sure. I was just suggesting a quick'n'dirty fix :P |
| 21:17 | technomancy | http://p.hagelb.org/define-method.html |
| 21:18 | maxhodak | technomancy: yeah i was basing my implementation off of resourcefully's example |
| 21:19 | maxhodak | technomancy: 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:19 | maxhodak | (right?) |
| 21:19 | technomancy | maxhodak: you need that to get line numbers in stack traces |
| 21:20 | technomancy | otherwise you can use a doseq |
| 21:34 | maxhodak | to build a hashmap of {:foo foo :bar bar ... } can you do something like (doseq [arg args] `{:~arg ~arg}) ? |
| 21:44 | fanatico | maxhodak: http://gist.github.com/304345 |
| 21:45 | somnium | Chousuke: is your reader on github? |
| 21:46 | somnium | Chousuke: ah, found it |
| 21:47 | fanatico | maxhodak: damn, actually that's an older version that doesn't work with locals. I'll try to dig up the current version. |
| 21:48 | maxhodak | fanatico: awesome.. that looks like what i'm trying to do though |
| 21:53 | fanatico | maxhodak: (defmacro named-map [& keys] `(zipmap (map keyword '~keys) (list ~@keys))) |
| 21:53 | fanatico | (let [a 1, b 2] (named-map a b)) ; => {:a 1, :b 2} |
| 21:56 | maxhodak | so that's not quite what i'm trying to do... i want to pass in a vector like [integration_point_name] |
| 21:56 | maxhodak | and build a hashmap of {:integration_point_name integration_point_name ...} |
| 21:56 | maxhodak | like let me push to github so i can show you exactly what i mean |
| 21:59 | maxhodak | http://github.com/myfit/clj-facebook/blob/master/src/facebook/client.clj#L65 |
| 22:00 | maxhodak | i'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:06 | fanatico | something like (let [a 1 b 2] (named-map [a b])) => {:a 1 :b 2} ? |
| 22:07 | fanatico | just through a let around the body of the macro and deconstruct keys. |
| 22:08 | fanatico | s/through/throw |
| 22:19 | maxhodak | fanatico: well, its a macro for generating functions (defn's) |
| 22:19 | maxhodak | so rather than {:a 1 :b 2}, i want {:a a :b b} to be filled in by my defn's arguments [a b] |
| 22:20 | fanatico | just merge the named map with the defaults. |
| 22:26 | fanatico | maxhodak: something like http://gist.github.com/317153 |
| 23:47 | DeusExPikachu | what are some common pitfalls/gotchas for using eval? |