#clojure logs

2011-12-25

00:49chewbrancaamalloy: alright, tracked down the issue, was with the http lib I was using
00:50chewbrancaanyone have any recommendations for a maintained http lib?
01:41hiredmanchewbranca: dakrone's fork of clj-http
01:43chewbrancahiredman: 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?
01:44chewbrancaI almost feel dirty using clj-http, that thing has been passed around so many times its not even funny
01:44hiredmanyes
01:44hiredmandakrone official took it over from mark, and pledged to keep it maintained
01:44hiredmanofficially
01:45hiredmanand I know he uses it at work
01:45chewbrancaI 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
01:45chewbrancaoh excellent!
01:45chewbrancadakrone: you rock!! thanks!!
01:46chewbrancagood stuff, I'll port over to using that
01:46chewbrancalooks like he also added a simpler http verb based DSL as well, very nice
01:49hiredmanand using slingshot for exceptions, which can be a little odd if you are not used to it
01:51chewbrancaahhh thanks for pointing that out, haven't tried slingshot yet
02:20amalloyi'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
04:26kdomerry christmas everyone
04:57LoganLKWhich 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' ?
05:01clojure_0000how do I modify a deftype
05:01clojure_0000to modify what (stf obj) outputs, where obj is of the type of the deftype
05:01clojure_0000i.e. I want to tell clojure how to "print as a string" the deftype
05:08clojure_0000ah; found it
05:08clojure_0000overwrite toString
05:08clojure_0000yay
05:47clojure_0000why does "> (str (doall (range 10)))" output (0 1 2 3 4 5 6 7 8 9) ?
05:47clojure_0000why is it still a lazyseq if I have thrown in a doall?
05:50clojure_0000can anyone hear me?
05:58thorwilclojure_0000: i guess doall does force evaluation, yet does not change the type
05:59thorwilwhat about that output is unexpected?
06:01clojure_0000what I wanted instead was:
06:01clojure_0000(apply str (range 10))
06:01clojure_0000I now have a different question. Does = do elementwise comparison for deftypes?
06:01clojure_0000I want something that defines equality as "equality of all members of a deftype"
06:01clojure_0000is something like that avilable?
07:56clojure_0000suppose foo.clj has (defrecord Cat .. ); am I, from main.clj, not allowed to do (foo/Cat. ... ) ?
07:56clojure_0000[this seesms to be the error I am facing]
07:59Borkdudeclojure_0000: I don't know about defrecord but you have to require foo probably first
08:00clojure_0000ah; got it figured out :-)
08:00clojure_0000thanks :-)
08:03clojure_0000so I'm reading clojure.org/libs and I't still not clear to me how import, use, and require differ
09:19etoschanyone around?
09:26rata_hi
09:28clojure_0000someone 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
09:29clojure_0000someone 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
09:29clojure_0000(sorry if repost; vm was hibernating; not sure if irssi msgs got sent)
09:51rata_clojure_0000: afaik, / is for static fields in a class
09:59sgronblo2Ok, so what was special about these *something* variables in clojure?
10:04rata_sgronblo2: nothing I think
10:04rata_just that they have an asterisk at the beginning and the end
10:04sgronblo2http://stackoverflow.com/questions/1986961/how-is-the-var-name-naming-convention-used-in-clojure well i already managed to find this
10:45rata_sgronblo2: that's what I mean, it's just a convention, there's nothing special about those vars
10:47sgronblo2ah
10:49daakuanyone have suggestions for libraries for html "widgets"?
10:49daakui'm trying to wrap a bunch of functionality from http://twitter.github.com/bootstrap/
10:49daakubut can't seem to come up with a minimal api that is elegant
10:50daakuit all seems to become a mess rather quickly (and i've only gotten around to forms, grids and alerts so far)
10:50daakui'm using hiccup underneath
10:52daakuin a way it seems silly, and maybe i should just use html directly
10:52daakubut there's a decent amount of repetition - generated ids, labels based on input name etc which makes me think i need something
10:54rata_daaku: if you get something, please let me know =)
10:55daakurata_: hope i do :)
11:02rata_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:30sgronblo2Is the clojure cheat sheet not updated for newer versions? I didn't find flatten in there for example?
11:41sgronblo2bleh, i have a loong stacktrace and I can't really figure out what I did wrong...
11:44rata_is it a long stacktrace with a sort of cycle between functions?
11:44sgronblo2ah nvm, I figured it out
11:44sgronblo2I forgot to cast my input from argv to ints :)
11:44sgronblo2did the same thing at first when I wrote the same thing in Haskell
11:51sgronblo2So how do you something like (int "123) ?
11:52rata_that's not the way from what I remember
11:52rata_is it maybe read like in haskell
11:52rata_?
11:53sgronblo2yeah apparently int is for coercion not conversion/parsing
11:53sgronblo2doesnt seem like its read either
11:55rata_yes
11:56rata_I think it's Integer/parseInt or something like that
11:56sgronblo2Well at least I can use . Integer parseInt I suppose
11:56rata_or Int/...
12:09replaca,(Integer/parseInt "786")
12:09clojurebot786
12:28sgronblo2Ok I was unable to figure out how to print every string in a vector on its own line...
12:28sgronblo2tried mapping println and tried using for
12:30jodarotry doseq
12:38sgronblo2whee, cool thanks
16:05kenthOn 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:07kenthIn 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:28tmciverkenth: yes, :keys is a special kind of destructuring used for maps and talked about on page 49 of JoC.
16:29tmciverkenth: the slope function is expecting a map as its argument with keys :p1 and :p2 which should both be two element vectors.
16:42kenthI'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:43kenth(defn slope [& {:keys [p1 p2]]) has a different destructuring than (defn slope [{:keys [p1 p2]}])
16:55TimMctmciver: Oh hey, you got JoC?
16:57TimMc&((fn [& {:keys [a b]}] b) :a 5 :b 6)
16:57lazybot⇒ 6
16:58TimMc...which is cool, except there is no map-apply
16:58tmciverTimMc: yup
16:59tmciverI was just looking into this. So a map is created even though one wasn't passed in?
17:11TimMcMaybe?
17:11TimMcYou'd have to look at the implementation.
17:12TimMcI think you can just pretend there is one.
17:12TimMc&((fn [& {:keys [a b]}] b) :a 5 :b)
17:12lazybotjava.lang.IllegalArgumentException: No value supplied for key: :b
17:13TimMc"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:13TimMcI think that's not a well-thought-out statement, given the lack of map-apply.
17:27replacaTimMc: You can add default args there
18:17TimMcreplaca: Defaults args where?
18:17TimMcWith the example that throws an exception I was just checking what the behavior would be.
18:28choffsteinHey 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:28choffsteinrelease the table and create a single clone of the element, or does the entire table stick around in memory?
18:31amalloyit doesn't create any clones of anything
18:32amalloyyou'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:34choffsteinhmmm, 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:35choffsteinand if the refs in the table are the last things point to the keys / values, the keys and values will get released too?
18:35amalloyyes
18:36amalloyit couldn't really work any other way, in the absence of an explicit free() function
18:36choffsteinHmm. Right. That's what I thought.
18:36choffsteinAnd that makes sense given what I learned in my functional programming class in undergrad
18:37choffsteinSo 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:39amalloyah
18:40amalloyso i think what happens here is that read-json is probably using .substring
18:40amalloy(.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:41choffsteinAhhh, I see.
18:42choffsteinSo if read-json uses substring, it still has the entire String in memory somewhere
18:42amalloymore importantly, the :name you get out is a substring pointing into that whole string
18:43choffsteinah, interesting.
18:45amalloyi'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:47replacaTimMc: (I was riding bikes with my kid) yeah, nothing solves the standalone keyword issue, but the error isn't too far off
18:47replacathat mechanism doesn't assign any meaning to keywords on their own
18:49amalloyah, there it is. yeah, substring shares
18:51choffsteinamalloy: Okay. I was just very confused as to what was going on. Appreciate the clarification
18:55replacaTimMc: But CommonLisp barfs at this construction, too, albeit with a slightly more helpful error message
18:55replacaThough we are used to it from shell programming where some -x options can stand alone and others take arguments
21:57OneWhoFrogsIs there a better way to express this function than what I have?
21:57OneWhoFrogshttp://dpaste.com/677834/
22:08amalloyOneWhoFrogs: well. depends how you feel about false values
22:08OneWhoFrogshow do you mean?
22:09amalloymostly i think i'm wrong :P
22:09amalloyi mean...if you're okay with false being treated the same as nil, this is just (and one two), right?
22:10OneWhoFrogsoh, I see what you mean.
22:10OneWhoFrogsyep, I don't have any problems with that
22:10OneWhoFrogsjust wondering if there's a built in solution that I'm overlooking
22:11OneWhoFrogsin Ruby this would be expressed as "one || two"
22:11OneWhoFrogsso I feel like I'm making things more complicated than they need to be with this function
22:13amalloy(a) one || two is totally different; (b) yes, just use (and one two)
22:13amalloy(c) god damn i can't read. (or one two)
22:13amalloy(d) cancel (a)
22:15OneWhoFrogsah, great, thanks
22:15OneWhoFrogsI thought (or one two) wouldn't work because (or 0 5) was returning 0. But I was just confused
22:15OneWhoFrogsI appreciate it!
22:17amalloy0 is not false
23:02clojure_0000is there a variant of eval; where I can specify an environment to do the lookups in? (and also disable other namespaces?)
23:02clojure_0000almost like an 'eval jail' ... i.e. "eval this form; but only the following functions are allowed to be used"
23:02amalloy$google clojail
23:02lazybot[Raynes/clojail - GitHub] https://github.com/Raynes/clojail
23:02amalloywrong repo. you want https://github.com/flatland/clojail
23:03RaynesSigh. I guess it's time we delete that one.
23:03Raynesamalloy: What do you think?
23:03RaynesSurely there isn't still anybody on the planet who thinks it is the canonical repo.
23:03RaynesThough, it is a fork...
23:04RaynesOh, it isn't.
23:04RaynesThe cogdis repo is the fork.
23:04RaynesYeah, this one needs to go.
23:07clojure_0000amalloy: noted; thanks
23:08amalloyRaynes: better to delete your whole github account, just to be safe
23:08Raynesamalloy: That is remarkably mean.
23:08Raynesclojure_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:09amalloywell, suggesting rm -rf ~ didn't work. one of these days i'll find something you fall for
23:09Rayness/is/are/