#clojure log - Nov 27 2010

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

0:00 clojurebot: Cool story bro.

0:00 _mst: beauty :)

1:23 notsonerdysunny: is there a way to get the name of the struct which was used to create it from the instance

1:23 using the class function just says it is a struct-map

1:24 leifw: just a guess, but what does the meta-map have?

1:25 or, if it doesn't help, can you change the way you create the struct, to add the name to the metadata for your struct?

1:25 I am picturing you want to print out the name for debugging, or something like that

1:41 hippiehunter: does anyone have any blog posts/tutorials that discuss how named parameters work(I don't think they're called that in clojure but I hope you get the idea).

1:42 Raynes: hippiehunter: Do you want a detailed explanation about how they're implemented, or do you just want to know how to use them?

1:42 hippiehunter: If by implemented you mean how i would go about making functions that take named parameters, then i mean implemented

1:43 Raynes: The latter, then. http://stackoverflow.com/questions/3337888/clojure-named-arguments/3337967#3337967 I wrote this answer to a similar question. It should be helpful.

1:44 There is a blog post 'round here somewhere.

1:44 hippiehunter: awsome, thanks

1:45 Raynes: &(let [{:keys [a b]} {:a 1 :b 1}] (+ a b)) ; It's just map destructuring.

1:45 sexpbot: ⟹ 2

1:46 Raynes: &(let [{n :a n2 :b} {:a 1 :b 2}] (+ n n2)) ; This is another, longer form of the above. It's useful if you need to destructure deeply nested structures.

1:46 sexpbot: ⟹ 3

1:47 Raynes: &(let [{{a :a b :b} :numbers} {:numbers {:a 1 :b 1}}] (+ a b)) ; like so

1:47 sexpbot: ⟹ 2

1:47 hippiehunter: whats the deal with :or

1:48 Raynes: It's a way to provide defaults for keys that aren't provided.

1:48 &(let [{:keys [a b] :or {a 1}} {:b 1}] (+ a b))

1:48 sexpbot: ⟹ 2

1:49 hippiehunter: did you mean {a 1} or {:a 1} ?

1:49 Raynes: {a 1}

1:50 It's saying "... or, if a is not present, it should be bound to the number 1"

1:50 hippiehunter: I think the simplicity of it all is blowing my mind

1:51 Raynes: :)

1:53 hippiehunter: whats the & doing in front of the (let ?

1:53 Raynes: That just tells sexpbot to evaluate the code.

1:53 & (println "blah")

1:53 sexpbot: ⟹ blah nil

2:11 mroessler: I'm trying to call a nested joda class: DateTime lastDayOfMonth = dt.dayOfMonth().withMaximumValue(); I'm using (.dayofMonth$withMaximumValue mydatetime) and getting "no matching field found". Direct calls such as .getMaximumValue do work.

2:13 replaca: mroessler: you're just calling a method on a result. Do this (.withMaximumValue (.dayOfMonth dt)).

2:14 mroessler: replaca: Many thanks!

2:15 replaca: mroessler: Or you can get fancy and say (-> dt .dayOfMonth .withMaxumumValue)

2:15 mroessler: np

4:34 trybeingarun: 2/c

10:50 kaiser: hi, guys

10:50 is there any way to get the returning value of the time function?

10:51 Guest43529: i mean, the time elapsed...it's returning nil

10:51 when i try to get the returning value

10:52 LauJensen: &(with-out-str (time (Thread/sleep 200)))

10:52 sexpbot: ⟹ "\"Elapsed time: 203.868 msecs\"\n"

10:54 LauJensen: Guest43529:

10:54 Guest43529: well, this way i'll have to parse the string...isn't there any nicier way?

10:54 LauJensen: &(first (re-find #"(\d+\.\d+)" (with-out-str (time (Thread/sleep 200)))))

10:54 sexpbot: ⟹ "202.716"

10:54 LauJensen: ~source time

10:54 Guest43529: its quite easy to implement yourself

10:56 Guest43529: thanks, LauJensen, anyway

10:56 http://tinyurl.com/2dywtf7

10:56 sorry, wrong pasting..

13:02 Guest28709: ,(pr "huh")

13:02 clojurebot: "huh"

13:05 serp__: ,(do (pr "hurr") (pr "durr"))

13:05 clojurebot: "hurr""durr"

13:06 serp__: ,(do (pr "hurr") (pr "durr") :herp)

13:06 clojurebot: "hurr""durr"

13:06 :herp

13:17 Guest28709: has anybody used aleph?

13:43 Raynes: $seen LauJensen

13:43 sexpbot: LauJensen was last seen quitting 4 minutes and 28 seconds ago.

14:57 Guest28709: anybody know why using content-type of "application/json" fails in aleph?

14:57 I'm confused as to why it's even processing the headers

15:08 headlessClown: Is there a central source for any recorded presentations from the con?

15:10 stuartsierra: eventually there will be

15:10 At http://clojure.blip.tv/

15:10 replaca: headlessClown: last I heard, those were still being prepared. I'm sure there will be an announcement in the group when they're ready

15:10 Raynes: s_s

15:11 I'm going to be on one of those.

15:11 * Raynes shudders

15:11 Raynes: Damn you, Aaron Bedra.

15:11 stuartsierra: don't sweat it

15:11 replaca: Raynes: time for your 15seconds of fame!

15:11 Raynes: :p

15:27 danlarkin: clojurebot!!!111111

15:32 replaca: danlarkin: it's checkins that are making it do that. Rich just checked something into clojure master

15:32 danlarkin: where's hiredman when you need him

15:32 replaca: he hasn't been around this weekend

15:33 the nerve! :)

15:33 danlarkin: inconceivable!!!

15:51 * Raynes hugs sexpbot's working commit reporting. <3

15:51 danlarkin: superburn

15:54 Raynes: Github's post-receive hooks are lovely.

16:13 replaca: Raynes: where did it report?

16:14 Raynes: replaca: sexpbot? It doesn't report Clojure commits. It uses the post-receive hooks from Github, so if somebody wanted sexpbot commit reporting, they'd have to add my URL to their hooks in the admin section of their repository's page.

16:14 Never bothered offering since clojurebot already seems to have that covered. Or, will, in any case.

16:16 $max

16:16 sexpbot: The most users ever in #clojure is 317

16:16 * Raynes rolls for 400

16:18 kumarshantanu: why can't I write something like this? (is it reader associated?) -- (let [x ['a 10]] (let x (println a)))

16:18 replaca: Raynes: ah, ok

16:19 Raynes: clojurebot does it by polling, so it lags

16:21 Raynes: replaca: https://gist.github.com/718283 Is an example.

16:21 ninjudd and friends uses it in #cake.clj

16:24 neotyk: kumarshantanu: what are you trying to do?

16:24 Raynes: It looks better when pieces of it are in bold, but bold from IRC doesn't copy to gist. :p

16:24 kumarshantanu: neotyk: trying to bind multiple vars to some values

16:25 neotyk: but the number can be variable, depending on the call

16:26 neotyk: kumarshantanu: I don't get second let, why?

16:26 kumarshantanu: neotyk: I want the inner let to be expanded like this -- (let [a 10] (println a))

16:26 Raynes: You can't do that without a macro.

16:27 kumarshantanu: Raynes: how can I do this inside a macro?

16:27 Raynes: Actually, I'm not sure you can even do that in a macro. Why do you want to do this?

16:28 kumarshantanu: Raynes: I am trying to bind either or both of *out* and *err* to some values depending on the call

16:31 Raynes: https://gist.github.com/718293 Here is an example.

16:32 That'll only work if you pass a vector literal.

16:32 I highly doubt this is really what you want to do. It seems odd.

16:33 * kumarshantanu intently looking at Raynes' gist

16:36 kumarshantanu: Raynes: got it...in fact I am trying to refactor this function -- http://pastebin.com/N6GZjnUJ

16:37 s/function/macro/

16:37 sexpbot: <kumarshantanu> Raynes: got it...in fact I am trying to refactor this macro -- http://pastebin.com/N6GZjnUJ

16:43 Raynes: kumarshantanu: You can use str rather than .toString, and the (do ..) around ~@body shouldn't be necessary.

16:44 kumarshantanu: Raynes: right

17:18 jjido: how do I (use) a Java class that was not compiled part of a package?

17:20 replaca: Raynes: looks nice

17:23 jjido: I don't understand your question. In general for a class, you use (ns (:import classname)) and make sure that it's on your classpath

17:24 technomancy: jjido: in some circumtances, java classes that are not part of any package simply can't be used.

17:24 not sure of the details, but it's probably a sign you're trying to do something you shouldn't.

17:25 jjido: ,(doc ns)

17:25 clojurebot: "([name docstring? attr-map? references*]); Sets *ns* to the namespace named by name (unevaluated), creating it if needed. references can be zero or more of: (:refer-clojure ...) (:require ...) (:use...

17:26 replaca: jjido: http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/ns

17:26 dnolen: hmm how do you get deftype/record to convert properly when str is called on them ?

17:27 replaca: dnolen: define toString?

17:35 kumarshantanu: bye all

17:35 LauJensen: dnolen: I actually showed that in one my recent tumblr posts, so thats what you get for not keeping up :)

17:35 dnolen: heh

17:37 LauJensen: link?

17:37 LauJensen: dnolen: http://offtopic.bestinclass.dk

17:37 dnolen: LauJensen: thx

17:37 LauJensen: np

17:38 Raynes: LauJensen: Did you consider posterous?

17:38 LauJensen: Raynes: no

17:43 jjido: So, I recompiled with a package name.

17:43 mheld: hey y'all

17:44 LauJensen: mheld: hey all ya'll

17:45 mheld: does the .net version of clojure use TCO?

17:46 jjido: do I need some prefix if the package is not 'java....'?

17:48 wooby: mheld: no

17:48 mheld: bummer

17:48 bsteuber: mheld: so use recur

17:48 mheld: I'll check it out

17:49 are there any cloqure web frameworks?

17:49 clojurebot: webjure is http://code.google.com/p/webjure/

17:49 mheld: oh neat

17:52 Raynes: mheld: Compojure, Moustache, Webjure, Conjure, and probably others I'm not thinking of.

17:52 The first too are the most popular.

17:52 two*

17:52 KirinDave: For those who are into REST apis, Clothesline is in clojars now http://clojars.org/clothesline

17:53 mheld: Raynes: gracias

17:53 emacs or eclipse?

17:54 jjido: still can't import it

17:55 Raynes: Most people use Emacs, but I've heard some exciting things about Eclipse lately. counterclockwise is under heavy development.

17:55 If you're already familiar with Eclipse, but not Emacs, it's worth giving it ago.

17:55 a go*

17:56 jjido: (ns foo (:import (java.util Vector))) works fine

17:57 (ns foo (:import (mypackage MyClass))) gives class not found

17:58 the directory named after mypackage is in the class path

17:58 and it contains the .class file

18:00 wjlroe: When you run `lein swank` - how can you configure the classpath? It's not finding a .clj file in the same dir as the file I'm compiling - if that makes any sense

18:01 FYI, this is an appengine project

18:03 technomancy: wjlroe: you can see the classpath using "lein classpath"

18:04 jjido: Thought I already tried this... (ns foo (:import MyClass)) did work. Good.

18:07 wjlroe: hmmm, so I guess this classpath is from the build.xml file?

18:09 jjido: how do I pass a int[] to a Java class? Do I need a Java wrapper?

18:10 technomancy: wjlroe: no, lein swank only looks at project.clj. I don't know how the app engine stuff works into it though. where's the file that it can't find?

18:10 wjlroe: actually no. how is the classpath put together? I guess you can configure that in the project.clj

18:10 technomancy: yeah - so it's got src/ in the CP, but not the package - so I think I need to add stuff to the classpath

18:11 technomancy: what's "the package"?

18:11 wjlroe: I mean src/packagename/

18:11 jjido: nice there is (ints)

18:11 wjlroe: like src/woot/blah.clj

18:12 technomancy: wjlroe: so you're saying (require 'woot.blah) fails?

18:12 wjlroe: yeah so in blah.clj I say (:use something.clj) <- in the same dir... it doesn't find it

18:13 so

18:13 I need the full NS

18:13 technomancy: yeah, without the .clj

18:13 wjlroe: mmm, ok

18:14 technomancy: it might help to read through some more examples if you're running into problems with the ns form

18:14 jjido: ,(ints [3 2 5])

18:14 clojurebot: java.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to [I

18:14 wjlroe: yeah, the PragProg book doesn't go into details

18:14 technomancy: wjlroe: I mean projects on github, etc.

18:15 wjlroe: anyway, I'm getting a completely different error now so that's wonderful

18:15 jjido: ,(ints (to-array [3 2 5]))

18:15 clojurebot: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [I

18:15 wjlroe: technomancy: yeah sure, I was looking through Composure, Ring, clj-gae-datastore mainly

18:16 Does anyone know what happened to compojure.control ?

18:17 jjido: ,(into-array Integer/TYPE [3 2 5])

18:17 clojurebot: #<int[] [I@ed09f6>

18:17 jjido: aaahh

18:20 Raynes: The majority of compojure ended up as ring middleware and other, related projects like hiccup.

18:20 wjlroe: yeah, can't find it in ring or compojure

18:21 but then again I don't know what it does - this is error driven development

18:22 raek: wjlroe: you can use the older version of compojure, if you just want to follow a tutorial

18:22 wjlroe: I like the challenge

18:22 and new stuff

18:23 Raynes: Error driven development. :>

18:23 raek: Moustache and Enlive are worth to check out too

18:23 Raynes: $learn edd Error Driven Development

18:23 sexpbot: My memory is more powerful than M-x butterfly. I wont forget it.

18:23 wjlroe: At work we have a really good system - it's called Complaint Driven Development

18:24 it's really relaxing

18:24 raek: (Moustache does routing and Enlive does html templating and scraping)

18:25 Raynes: I think I'm the only person who still uses Hiccup rather than enlive these days for html templating.

18:26 wjlroe: I like hiccup

18:26 the smartrevolution peeps are using it also it appears

18:47 replaca: wjlroe: what's smartrevolution?

18:48 wjlroe: replaca: https://github.com/smartrevolution/clj-gae-datastore <- actually I think they're caled something else - it's Steven Richter's company

18:48 replaca: wjlroe: oh, yeah, I see now. I read about that before. Cool stuff.

18:48 wjlroe: people who wrote TheDeadline

18:49 bsteuber: freiheit

19:07 dnolen: has anyone tried doing a REPL w/in the REPL ?

20:36 samx: What does '&' mean in when attached to a formal parameter in 'fn' arglist, e.g... (fn [&foo bar] ...)

20:37 jjido: samx: isn't that (fn [& foo bar] ...)?

20:38 samx: no

20:39 for example, from the definition of 'defn' in core.clj: (fn defn [&form &env name & fdecl] ...

20:40 jjido: just a var name

20:42 ,(letfn [(foo [&blue &red] &blue)] (foo 3 4))

20:42 &(letfn [(foo [&blue &red] &blue)] (foo 3 4))

20:42 sexpbot: ⟹ 3

20:44 wjlroe: there used to be a function compojure.http/static-file and I can't find where it's gone to... anyone know?

20:44 samx: i guess.. just seemed weird to use & as part of a parameter name, so figured it might have some kind of a side effect

21:26 Raynes: samx: Those are implicit parameters. I imagine that's Riches own little convention. It's nothing special.

21:28 https://gist.github.com/718515

23:22 Intertricity_: Woo, I just saw clojure-clr binaries, does that mean it's now in beta?

23:22 Or at least relatively useable?

23:33 tensorpudding: is there a way to convert a String[] to a list of strings?

23:34 or maybe, in general, converting java arrays to clojure lists

23:37 eh, nevermind, clojure-contrib has what i want

23:41 Raynes: tensorpudding: You should just be able to call seq on it.

23:43 &(type (seq (into-array String ["one" "two" "three"])))

23:43 sexpbot: ⟹ clojure.lang.ArraySeq

Logging service provided by n01se.net