#clojure log - Feb 27 2010

The Joy of Clojure
Main Clojure site
Google Group
List of all logged dates

0:33 chouser: slyphon: I'd use a vector there.

0:33 slyphon: I'd use a vector there.

0:34 slyphon: yeah, i thought so

0:34 chouser: helps suggest to people that that's where 'ctx' is being introduced or defined.

0: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

0:35 should i make it like [sym jmx-url] so it's like a 'let'

0:35 Apage43: waha

0:36 i saved the day at work today.. with the power of clojure

0:39 cemerick: sheesh, the funders page is *long* now

2:05 slyphon: you know you're getting silly when you start writing (defmacro dosomething `(defmacro ...))

2:10 Crowbar7: lol

2:11 slyphon: You're Doing it Wrong

2:11 G0SUB: slyphon, http://www.xach.com/img/doing-it-wrong-at-a4.jpg

2:11 slyphon: hahaha

2:12 G0SUB: :)

2:12 slyphon: who is that in the picture?

2:12 * slyphon feels a little silly asking

2:12 G0SUB: slyphon, I have that pic pasted on my office wall

2:12 slyphon: :D

2:12 G0SUB: slyphon, dude!

2:12 slyphon: :/

2:12 G0SUB: slyphon, that's Uncle John

2:12 slyphon: is that knuth?

2:13 G0SUB: slyphon, John McCarthy. the discoverer of Lisp.

2:13 slyphon: ohhhhhh

2:13 right right right

2:13 i don't think i've ever seen a photo of him before

2:13 i imagined him tweedier

2:13 G0SUB: slyphon, well, he was handsome :)

2:13 slyphon: :D

2:14 heh, i haven't seen 'xach' in forever

2:14 since i stopped harrasing him in #lisp

2:15 G0SUB: slyphon, hehe. He is active on proggit.

2:16 slyphon: ah, right on

2:19 LauJensen: Morning team

2:28 G0SUB: LauJensen, it's afternoon here :)

2:29 LauJensen: its a big earth :)

2:29 G0SUB: LauJensen, indeed :)

5:31 hamza: gents i have a list of true false values (true false) how can i

5:31 apply or or and on them?

5:35 morphling: hamza: and and or aren't functions, you have to wrap them like this: (fn [a b] (and a b))

5:35 ska2342: hamza: can't you use every?

5:37 ,(every? true? '(true true))

5:37 clojurebot: true

5:38 ska2342: ,(some true? '(false true false))

5:38 clojurebot: true

5:39 hamza: thanks a lot guys, every and some would work.

6:07 dsop: does someone know the license of the clojure logo

6:08 spariev: dsop: http://groups.google.com/group/clojure/browse_thread/thread/7f179c79f0d0bb3e - might be relevant

7:16 Licenser: *sighs*

7:55 bsteuber: am I the only person not satisfied with (comment foo bar) returning nil instead of being completely ignored by the preprocessor?

8:02 Chousuke: bsteuber: use #_ if you want to ignore a form

8:03 bsteuber: comment is just a macro so the reader can't do anything about it :)

8: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..

8:07 bsteuber: Chousuke: I know, I'd just prefer comment to be "special" so I could use it everywhere like other comment syntax

8:07 or have something like #_ to ignore multiple forms

8:07 Chousuke: bsteuber: you can do #_(comment ...) :)

8:07 bsteuber: og, I can use #_(foo bar), right? stupid me :)

8:08 Chousuke: I think the comment macro is mostly intended for example code at the top level rather than any inline comments

8:09 bsteuber: hm, I see

8:09 Chousuke: the contents of the comment macro get properly syntax highlighted and can be easily evaluated using eg. slime

8:09 bsteuber: ok, so I'll use #_(...) to comment out binding forms etc.

8:10 thanks for clarification

8:23 hamza: why subvec? I guess my naive implementation would me something like

8:23 (map (fn [[x y]] [x (f y)]) some-seq)

8:24 how does your code look like?

8: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..

8:29 jeffmess: has anyone here got clojure in action and joy of clojure? which would you recommend out of the two?

8:34 bsteuber: jeffmess: hard to tell with unfinished books - I'll probably read both once they're out :)

8:38 spariev: jeffmess: imo Joy Of Clojure is more polished at the time being

8:40 jeffmess: spariev: thats what i was leaning towards

8:41 thanks!

8: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 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 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 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 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 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 {:pre [(valid? foo arg1) (valid? bar arg2)]}

14:59 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 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 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 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 but then, (System/getProperty "java.class.path") shows that compojure and all the dependencies are in classpath

16:11 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 http://paste.org/pastebin/view/15839

16:24 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:28 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 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 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 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 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 will this work?

16:58 eglyph: the .jar from repo is twice as big the one i've built

16:59 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 dying saying "First argument to def must be a Symbol"

20:43 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 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 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 so now if i replace ~args with [] it works

20:57 (~methods works fine)

20:57 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 Chousuke: it is, it's the 3rd part of each vector in fb-methods

21:00 (prn (type args)) on L78 says thats right

21:01 clojure.lang.PersistentVector

21:01 Chousuke: maybe you have the error somewhere else

21:01 because as far as I can tell, that's fine :/

21:02 ... ah

21:02 never mind

21:02 you're never actually passing a vector to the macro

21:03 you're passing the symbol args

21:03 you can't use macros in a doseq like that .P

21:03 maxhodak: oh?

21:03 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 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 i just don't want to list out all of the methods as separate fxns

21:05 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 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 though a little wasteful

21:06 yeah

21:06 Chousuke: but hm, the non-toplevel def in your make-facebook-connection is also suspect :P

21:07 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 Chousuke: no but *fb-conn* is references in call-method

21:07 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 destructive?

21:07 Chousuke: yes

21:08 it redefines a global variable, so it's destructive

21:08 or has side-effects, whichever terminology you prefer :P

21:08 maxhodak: ok

21:09 renaming it init-facebook!

21:09 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 yeah.

21:10 maxhodak: Chousuke: yeah i've never seen an fb app that's dealt with more than one api key

21:10 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 I think (eval `(define-method ~symb ~map ~args)) in the doseq would work just fine :P

21:14 * somnium wonders if the moral foundations of #clojure have deteriorated

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 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 (right?)

21:19 technomancy: maxhodak: you need that to get line numbers in stack traces

21:20 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 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 (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 and build a hashmap of {:integration_point_name integration_point_name ...}

21:56 like let me push to github so i can show you exactly what i mean

21:59 http://github.com/myfit/clj-facebook/blob/master/src/facebook/client.clj#L65

22:00 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 just through a let around the body of the macro and deconstruct keys.

22:08 s/through/throw

22:19 maxhodak: fanatico: well, its a macro for generating functions (defn's)

22:19 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 maxhodak: something like http://gist.github.com/317153

23:47 DeusExPikachu: what are some common pitfalls/gotchas for using eval?

Logging service provided by n01se.net