#clojure log - Dec 25 2011

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

0:49 chewbranca: amalloy: alright, tracked down the issue, was with the http lib I was using

0:50 anyone have any recommendations for a maintained http lib?

1:41 hiredman: chewbranca: dakrone's fork of clj-http

1:43 chewbranca: hiredman: so I see he forked it back in sept, any indication he's going to be using it long term? ie using it in a known large project?

1:44 I almost feel dirty using clj-http, that thing has been passed around so many times its not even funny

1:44 hiredman: yes

1:44 dakrone official took it over from mark, and pledged to keep it maintained

1:44 officially

1:45 and I know he uses it at work

1:45 chewbranca: I switched over to https://github.com/rplevy/clj-apache-http tonight which is a forked and fixed version of the fork I was using from diamondap

1:45 oh excellent!

1:45 dakrone: you rock!! thanks!!

1:46 good stuff, I'll port over to using that

1:46 looks like he also added a simpler http verb based DSL as well, very nice

1:49 hiredman: and using slingshot for exceptions, which can be a little odd if you are not used to it

1:51 chewbranca: ahhh thanks for pointing that out, haven't tried slingshot yet

2:20 amalloy: i'd like to echo that slingshot is pretty sweet once you're used to it. i can barely use it but it's still better than plain exceptions

4:26 kdo: merry christmas everyone

4:57 LoganLK: Which book would be better suited for one who knows java, but has never done any functional/lispy programming. 'Clojure in action' or 'the joy of clojure' ?

5:01 clojure_0000: how do I modify a deftype

5:01 to modify what (stf obj) outputs, where obj is of the type of the deftype

5:01 i.e. I want to tell clojure how to "print as a string" the deftype

5:08 ah; found it

5:08 overwrite toString

5:08 yay

5:47 why does "> (str (doall (range 10)))" output (0 1 2 3 4 5 6 7 8 9) ?

5:47 why is it still a lazyseq if I have thrown in a doall?

5:50 can anyone hear me?

5:58 thorwil: clojure_0000: i guess doall does force evaluation, yet does not change the type

5:59 what about that output is unexpected?

6:01 clojure_0000: what I wanted instead was:

6:01 (apply str (range 10))

6:01 I now have a different question. Does = do elementwise comparison for deftypes?

6:01 I want something that defines equality as "equality of all members of a deftype"

6:01 is something like that avilable?

7:56 suppose foo.clj has (defrecord Cat .. ); am I, from main.clj, not allowed to do (foo/Cat. ... ) ?

7:56 [this seesms to be the error I am facing]

7:59 Borkdude: clojure_0000: I don't know about defrecord but you have to require foo probably first

8:00 clojure_0000: ah; got it figured out :-)

8:00 thanks :-)

8:03 so I'm reading clojure.org/libs and I't still not clear to me how import, use, and require differ

9:19 etosch: anyone around?

9:26 rata_: hi

9:28 clojure_0000: someone please enlighten me. why are classes indexed like some.long.path.ClassName ; but vars and functions are some.long.path.name/blah ? the . vs / constantly confuses me

9:29 someone please enlighten me. why are classes indexed like some.long.path.ClassName ; but vars and functions are some.long.path.name/blah ? the . vs / constantly confuses me

9:29 (sorry if repost; vm was hibernating; not sure if irssi msgs got sent)

9:51 rata_: clojure_0000: afaik, / is for static fields in a class

9:59 sgronblo2: Ok, so what was special about these *something* variables in clojure?

10:04 rata_: sgronblo2: nothing I think

10:04 just that they have an asterisk at the beginning and the end

10:04 sgronblo2: http://stackoverflow.com/questions/1986961/how-is-the-var-name-naming-convention-used-in-clojure well i already managed to find this

10:45 rata_: sgronblo2: that's what I mean, it's just a convention, there's nothing special about those vars

10:47 sgronblo2: ah

10:49 daaku: anyone have suggestions for libraries for html "widgets"?

10:49 i'm trying to wrap a bunch of functionality from http://twitter.github.com/bootstrap/

10:49 but can't seem to come up with a minimal api that is elegant

10:50 it all seems to become a mess rather quickly (and i've only gotten around to forms, grids and alerts so far)

10:50 i'm using hiccup underneath

10:52 in a way it seems silly, and maybe i should just use html directly

10:52 but there's a decent amount of repetition - generated ids, labels based on input name etc which makes me think i need something

10:54 rata_: daaku: if you get something, please let me know =)

10:55 daaku: rata_: hope i do :)

11:02 rata_: daaku: good luck! I'm sure it'd be very useful to have something like that (especially for projects where you don't have designers around to make templates for you)

11:30 sgronblo2: Is the clojure cheat sheet not updated for newer versions? I didn't find flatten in there for example?

11:41 bleh, i have a loong stacktrace and I can't really figure out what I did wrong...

11:44 rata_: is it a long stacktrace with a sort of cycle between functions?

11:44 sgronblo2: ah nvm, I figured it out

11:44 I forgot to cast my input from argv to ints :)

11:44 did the same thing at first when I wrote the same thing in Haskell

11:51 So how do you something like (int "123) ?

11:52 rata_: that's not the way from what I remember

11:52 is it maybe read like in haskell

11:52 ?

11:53 sgronblo2: yeah apparently int is for coercion not conversion/parsing

11:53 doesnt seem like its read either

11:55 rata_: yes

11:56 I think it's Integer/parseInt or something like that

11:56 sgronblo2: Well at least I can use . Integer parseInt I suppose

11:56 rata_: or Int/...

12:09 replaca: ,(Integer/parseInt "786")

12:09 clojurebot: 786

12:28 sgronblo2: Ok I was unable to figure out how to print every string in a vector on its own line...

12:28 tried mapping println and tried using for

12:30 jodaro: try doseq

12:38 sgronblo2: whee, cool thanks

16:05 kenth: On page 133 of the Joy of Clojure book, what kind of destructuring is being used in (defn slope [& {:keys [p1 p2] ...). Isnt [{:keys [x y]}] usually for maps?

16:07 In the sample, (slope :p1 [4 15] :p2 [3 21]) is valid but I would assume {:p1 [4 15] :p2 [3 21]} should be passed as arguments instead

16:28 tmciver: kenth: yes, :keys is a special kind of destructuring used for maps and talked about on page 49 of JoC.

16:29 kenth: the slope function is expecting a map as its argument with keys :p1 and :p2 which should both be two element vectors.

16:42 kenth: I'm still confused about the :keys destructuring. The (slope :p1 [ 4 15] :p2 [3 21]) contains 4 arguments but it works in the destructuring form that I would expect a map would be used in.

16:43 (defn slope [& {:keys [p1 p2]]) has a different destructuring than (defn slope [{:keys [p1 p2]}])

16:55 TimMc: tmciver: Oh hey, you got JoC?

16:57 &((fn [& {:keys [a b]}] b) :a 5 :b 6)

16:57 lazybot: ⇒ 6

16:58 TimMc: ...which is cool, except there is no map-apply

16:58 tmciver: TimMc: yup

16:59 I was just looking into this. So a map is created even though one wasn't passed in?

17:11 TimMc: Maybe?

17:11 You'd have to look at the implementation.

17:12 I think you can just pretend there is one.

17:12 &((fn [& {:keys [a b]}] b) :a 5 :b)

17:12 lazybot: java.lang.IllegalArgumentException: No value supplied for key: :b

17:13 TimMc: "Unroll optional named arguments. Callers should not have to wrap optional named arguments in a map literal: " <-- http://dev.clojure.org/display/design/Library+Coding+Standards

17:13 I think that's not a well-thought-out statement, given the lack of map-apply.

17:27 replaca: TimMc: You can add default args there

18:17 TimMc: replaca: Defaults args where?

18:17 With the example that throws an exception I was just checking what the behavior would be.

18:28 choffstein: Hey everyone. Merry Christmas for those celebrating. I have a quick question about the garbage collector and references in general in clojure. Let's say I have a huge table -- maybe a vector of vectors or a hash-map. Now let's say I create a new variable that points to a single value in that table, and all other refs to the table are lost (maybe we returned from a function that the table was created in, but kept the ref to the element). Will the

18:28 release the table and create a single clone of the element, or does the entire table stick around in memory?

18:31 amalloy: it doesn't create any clones of anything

18:32 you'll free the whole table, since nobody's using it; same for the other values in it. but the one you kept a pointer to doesn't get freed

18:34 choffstein: hmmm, okay. so is it safe to say the table is really just an object with a bunch of refs of its own? so once nothing points to the table, the table can get released, regardless of anything point to keys or values?

18:35 and if the refs in the table are the last things point to the keys / values, the keys and values will get released too?

18:35 amalloy: yes

18:36 it couldn't really work any other way, in the absence of an explicit free() function

18:36 choffstein: Hmm. Right. That's what I thought.

18:36 And that makes sense given what I learned in my functional programming class in undergrad

18:37 So can you explain something to me? I'm reading this post (http://ossareh.posterous.com/batch-consumption-of-crunchbase-with-clojure) and it says by extracting an element from a table keeps the table around, which really didn't make much sense to me

18:39 amalloy: ah

18:40 so i think what happens here is that read-json is probably using .substring

18:40 (.substring s 0 1) returns a new string that keeps a reference to its "parent", with a little note: "actually only the first character of that"

18:41 choffstein: Ahhh, I see.

18:42 So if read-json uses substring, it still has the entire String in memory somewhere

18:42 amalloy: more importantly, the :name you get out is a substring pointing into that whole string

18:43 choffstein: ah, interesting.

18:45 amalloy: i've been told that's an issue, anyway. skimming the source of String, i don't see that happening, but i assume it's in there somewhere

18:47 replaca: TimMc: (I was riding bikes with my kid) yeah, nothing solves the standalone keyword issue, but the error isn't too far off

18:47 that mechanism doesn't assign any meaning to keywords on their own

18:49 amalloy: ah, there it is. yeah, substring shares

18:51 choffstein: amalloy: Okay. I was just very confused as to what was going on. Appreciate the clarification

18:55 replaca: TimMc: But CommonLisp barfs at this construction, too, albeit with a slightly more helpful error message

18:55 Though we are used to it from shell programming where some -x options can stand alone and others take arguments

21:57 OneWhoFrogs: Is there a better way to express this function than what I have?

21:57 http://dpaste.com/677834/

22:08 amalloy: OneWhoFrogs: well. depends how you feel about false values

22:08 OneWhoFrogs: how do you mean?

22:09 amalloy: mostly i think i'm wrong :P

22:09 i mean...if you're okay with false being treated the same as nil, this is just (and one two), right?

22:10 OneWhoFrogs: oh, I see what you mean.

22:10 yep, I don't have any problems with that

22:10 just wondering if there's a built in solution that I'm overlooking

22:11 in Ruby this would be expressed as "one || two"

22:11 so I feel like I'm making things more complicated than they need to be with this function

22:13 amalloy: (a) one || two is totally different; (b) yes, just use (and one two)

22:13 (c) god damn i can't read. (or one two)

22:13 (d) cancel (a)

22:15 OneWhoFrogs: ah, great, thanks

22:15 I thought (or one two) wouldn't work because (or 0 5) was returning 0. But I was just confused

22:15 I appreciate it!

22:17 amalloy: 0 is not false

23:02 clojure_0000: is there a variant of eval; where I can specify an environment to do the lookups in? (and also disable other namespaces?)

23:02 almost like an 'eval jail' ... i.e. "eval this form; but only the following functions are allowed to be used"

23:02 amalloy: $google clojail

23:02 lazybot: [Raynes/clojail - GitHub] https://github.com/Raynes/clojail

23:02 amalloy: wrong repo. you want https://github.com/flatland/clojail

23:03 Raynes: Sigh. I guess it's time we delete that one.

23:03 amalloy: What do you think?

23:03 Surely there isn't still anybody on the planet who thinks it is the canonical repo.

23:03 Though, it is a fork...

23:04 Oh, it isn't.

23:04 The cogdis repo is the fork.

23:04 Yeah, this one needs to go.

23:07 clojure_0000: amalloy: noted; thanks

23:08 amalloy: Raynes: better to delete your whole github account, just to be safe

23:08 Raynes: amalloy: That is remarkably mean.

23:08 clojure_0000: http://speakerdeck.com/u/raynes/p/clojail-life-in-the-clojure-prison Here is some slides from my Conj talk to go with it. Might be helpful. I'd link you to the video if they'd ever release the damned thing.

23:09 amalloy: well, suggesting rm -rf ~ didn't work. one of these days i'll find something you fall for

23:09 Raynes: s/is/are/

Logging service provided by n01se.net