#clojure log - Sep 18 2009

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

0:29 fullets: What's the equivalent of CL's find in clojure? (some #(= item %) collection)?

0:31 JAS415: find?

0:31 fullets: That's just for maps, no?

0:32 JAS415: what do you want to do with it?

0:32 you just want to filter the collection?

0:32 or you want to get an index or something?

0:34 you could try filter

0:36 you can do .indexOf

0:36 at least on vectors

0:36 ,(.indexOf [1 2 3 4 5 6] 4)

0:36 clojurebot: 3

0:36 JAS415: i think index of is closest yes

0:37 hiredman: ,(find [1 2 3 4 5 6] 4)

0:37 clojurebot: [4 5]

0:37 hiredman: hmm

0:37 interesting

0:37 ,(doc find)

0:37 clojurebot: "([map key]); Returns the map entry for key, or nil if key not present."

0:37 JAS415: kind of like an assoc list

0:40 arbscht: ,(doc clojure.contrib.seq-utils/find-first)

0:40 clojurebot: Pardon?

0:40 arbscht: ,(doc find-first)

0:40 clojurebot: "clojure.contrib.seq-utils/find-first;[[pred coll]]; Returns the first item of coll for which (pred item) returns logical true. Consumes sequences up to the first match, will consume the entire sequence and return nil if no match is found."

0:40 arbscht: ,(doc positions)

0:40 clojurebot: "clojure.contrib.seq-utils/positions;[[pred coll]]; Returns a lazy sequence containing the positions at which pred is true for items in coll."

0:41 somnium: getting null pointer exception trying to serve static files via compojure, anyone who might be able to help?

0:41 hiredman: ,(use 'clojure.contrib.seq-utils)

0:41 clojurebot: nil

0:42 arbscht: somnium: sure. you might want to ask in #compojure though :)

0:42 hiredman: ,(find-first (partial (comp = key) :a) {:a 1 :b 2})

0:42 somnium: ah, didn't know it existed

0:42 clojurebot: java.lang.RuntimeException: java.lang.IllegalArgumentException: Wrong number of args passed to: core$key

0:43 hiredman: ,(find-first (comp (partial = :a) key) {:a 1 :b 2})

0:43 clojurebot: [:a 1]

0:43 somnium: arbscht: well, since you seem helpful and knowledgeable, it serves the template defined in the file ok, but throws an exception looking for static files, so something is wonky

0:44 running (start-server) from slime, don't know if that affects things

0:44 arbscht: somnium: can you paste your code?

0:45 hiredman: :D

0:46 ,((partial find-first (comp (partial = :a) key)) {:a 1 :b 2})

0:46 clojurebot: [:a 1]

0:46 arbscht: brought to you by the department of redundancy department :p

0:55 hiredman: ,((comp (partial apply find-first) (partial (flip update-in) (comp (partial apply comp) reverse (partial list key)) [0]) (partial (flip update-in) (partial partial =) [0]) vector) :a {:a 1 :b 2})

0:55 clojurebot: [:a 1]

0:55 hiredman: too bad flip isn't in core

0:56 somnium: arbscht: okay, in the act of pasting it I found a typo that was probably causing the null pointer, now I'm getting a 404 so its some improvement

0:56 JAS415: i like the one where the guy does church calculus in clojure

0:56 arbscht: somnium: great

0:56 hiredman: actually

0:57 ,((comp (partial apply find-first) (partial (flip update-in) (comp (partial apply comp) reverse (partial list key) (partial partial =)) [0]) vector) :a {:a 1 :b 2})

0:57 clojurebot: [:a 1]

0:58 hiredman: removes the second update-in, because you can just compose the update-in functions

0:59 lisppaste8: somnium pasted "compojure" at http://paste.lisp.org/display/87269

1:01 somnium: nm, finally got it

1:03 my typo led me to screw with my paths...they were right to begin with. thanks for your help arbscht :-)

1:03 arbscht: somnium: no problem

1:17 danlarkin: rhickey: Hey Rich, four of us clojure guys were in seattle this week hacking and we heard you spoke at microsoft earlier in the week

1:17 rhickey: danlarkin: yes, I was there Tuesday

1:18 I did a talk and an interview for their Channel 9

1:18 dysinger: what would M$ want with clojure ? we are curious :D

1:19 hiredman: there are a lot of haskell guys in MS research

1:19 and they have that STM project for .NET

1:20 dysinger: neat

1:20 Makoryu: MS figured out pretty early that Java was a bad idea, so they made a point internally to stop copying Java and start copying (and funding!) functional languages

1:20 danlarkin: rhickey: we were bummed that you didn't come hang out with us :-D

1:21 rhickey: danlarkin: I was only in town for one evening and the day and was booked up - it would have been fun to get together

1:22 dysinger: They have a monthly talk in the languages group and have invited speakers. They invited me and were very gracious hosts.

1:23 dysinger: awesome

1:26 danlarkin: rhickey: we understand... next time, though!

1:27 we won't be so understanding again

1:28 dysinger: :) lol

1:29 rhickey: we did have an awesome team-sonian week in Seattle pair programming (technomancy, gjahad, dysinger & danlarkin)

1:29 rhickey: dysinger: cool

1:32 keynote went well today, slides are here: http://wiki.jvmlangsummit.com/Clojure_Keynote

1:32 directly: http://wiki.jvmlangsummit.com/images/a/ab/HickeyJVMSummit2009.pdf

1:33 travisbrady: rhickey: is there video anywhere?

1:33 rhickey: travisbrady: not yet, as far as I know

1:33 travisbrady: ok, i'll keep an eye out

1:34 rhickey: that may end up being an InfoQ thing, so many months away

1:34 hiredman: there is a vidoe of the last 3 minutes on youtube

1:34 Makoryu: rhickey: I like these slides

1:35 dnolen: rhickey: very inspiring slides! i posted it on Hacker News people seem to be digging it there.

1:35 rhickey: Makoryu: It could be a bit hard to get the full ideas behind the talk from the slides

1:35 Makoryu: rhickey: I know :(

1:36 rhickey: dnolen: I saw that, thanks

1:42 cgrand: rhickey: inspiring slides indeed!

1:59 JAS415: I'm pleased that there are Whitehead quotes sprinkled throughout those slides

3:02 LauJensen: Good morning gents

3:14 cgrand: morning Lau!

3:33 sgtarr: howdy

3:33 (+ 1234 567)

3:33 clojurebot: *suffusion of yellow*

3:33 sgtarr: err

4:23 pixelman: should I look for native clojure methods to do string operations or just go for (. message toLowerCase) or (. message beginsWith "foo") ?

4:24 hiredman: (.toLowerCase message)

4:24 (.beginsWith message "foo")

4:25 pixelman: thanks!

4:25 that's simpler :)

4:26 hiredman: static methods are (Class/method args)

4:26 ,(Class/forName "String")

4:26 clojurebot: java.lang.ClassNotFoundException: String

4:26 hiredman: bah

4:27 ,(Class/forName "java.lang.String")

4:27 clojurebot: java.lang.String

4:42 licoresse: ...

4:43 adityo: are there any other alternatives to clojure.contrib.zip-filter.xml to query the parsed xml from clojure.xml/parse?

4:44 Chousuke: well, it's just a map so you can of course access it directly :)

4:44 pixelman: I cant find how to make a regexp case insensitive other than writing it in the regexp (re-find #"foo|FOO" message)

4:46 hiredman: ,(re-find #"(?i)foo" "FOO")

4:46 clojurebot: "FOO"

4:46 hiredman: ,(re-find #"(?i)foo" "FoO")

4:46 clojurebot: "FoO"

4:46 pixelman: thanks!

4:46 Chousuke: pixelman: http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html :)

4:47 pixelman: thanks! I did not know about the special constructs in java. I've always used the constants option to regexp!

4:53 mtd: anyone know of good discussion behind http://wiki.jvmlangsummit.com/Clojure_Keynote 's statement that "Static/Dynamic typing" is "not so different"? Seems an unusual thing to say.

4:56 (s/"not so different"/"superficial differences"/, sorry)

5:07 Chousuke: mtd: where does it say that?

5:08 mtd: you mean the statement in the "background" section?

5:09 pixelman: is there a more clojure variant of (Integer/valueOf "1") (int "1") doesn't seem to do the trick

5:09 Chousuke: nope. use the java method

5:09 mtd: Chousuke: yes..."Not so Different -> Differences are superficial -> Static/Dynamic typing".

5:09 pixelman: ok!

5:10 mtd: Chousuke: was it not meant to be interpreted as "static/dynamic typing is a difference that's superficial and at the level of semicolons/indentation"?

5:10 Chousuke: I don't even see where it mentions typing at all.

5:10 mtd: Chousuke: I admit I was nodding along with the presentation until I was hit by that bullet and stunned for a second.

5:11 Chousuke: it's a great presentation overall :)

5:11 Chousuke: but yeah, I don't think he meant that.

5:11 though usually static vs. dynamic typing really only changes *when* the typing happens rather than based on what

5:11 mtd: Chousuke: ah, ok.

5:11 Chousuke: so it's not that big a change, fundamentally :P

5:12 mtd: Chousuke: I guess I can only speak from a pragmatist perspective, and say "with mature java and python source code trees in front of you, it sure seems to matter a lot"

5:12 Chousuke: but yeah theoretically I can see your point :)

5:13 Chousuke: and you have to admit that most languages are simply clones of each other :P

5:13 C# and Java for example. the differences aren't *that* big :)

5:18 mtd: Chousuke: I have no argument with that as a casual statement :).

5:18 licoresse: religiously, the diff. is great

5:18 adityo: whats the diff between xml-seq and clojure.zip/xml-zip

5:18 vy: I use http://pastebin.com/d7f205d67 file as my clojure launcher script and while there exists clojure-contrib.jar in the given path, in the REPL, (use clojure.contrib.str-utils) throws a ClassNotFoundException. Any ideas?

5:20 licoresse: '

5:20 vy: Perfect!

6:25 rafsoaken: starter question: why does (take 10 (iterate #([(last %) (reduce + %)]) [1 1])) give me an IllegalArgumentException ?

6:26 JAS415: ,(doc iterate)

6:26 clojurebot: "([f x]); Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free of side-effects"

6:27 JAS415: ,(take 10 (iterate #([(last %) (reduce + %)]) [1 1]))

6:27 clojurebot: java.lang.RuntimeException: java.lang.IllegalArgumentException: Wrong number of args passed to: LazilyPersistentVector

6:27 jdz: the anonymous function is wrong

6:27 the first thing in #( must be a function

6:28 JAS415: ,(take 10 (iterate #([(last %) (apply + %)]) [1 1]))

6:28 clojurebot: java.lang.RuntimeException: java.lang.IllegalArgumentException: Wrong number of args passed to: LazilyPersistentVector

6:28 JAS415: right

6:29 jdz: well, anything that implements IFn or something

6:29 in this case it is being given a vector, which is fine

6:29 but then, no arguments are passed to it, and generally it's not what rafsoaken wants

6:30 JAS415: ,(take 10 (iterate #(vector (last %) (apply + %)) [1 1]))

6:30 clojurebot: ([1 1] [1 2] [2 3] [3 5] [5 8] [8 13] [13 21] [21 34] [34 55] [55 89])

6:30 JAS415: i think vector the fn rather than vector the data-structure

6:32 jdz: ,(take 10 (iterate (fn [[a b]] [b (+ a b)]) [1 1]))

6:32 clojurebot: ([1 1] [1 2] [2 3] [3 5] [5 8] [8 13] [13 21] [21 34] [34 55] [55 89])

6:33 jdz: #() is not always shorter

6:34 rafsoaken: thanks jdz and JAS415, I see some light there, although I didnt entirely understand the difference

6:34 jdz: ,([:x :y :z] 2)

6:34 clojurebot: :z

6:34 rafsoaken: i also like the unpacking of arguments..

6:35 jdz: vectors can be called like functions, too

6:35 and that's what you were doing, originally

6:35 rafsoaken: ahhhh, now i got it! thx a lot!

6:56 spuz: hello, I was asking yesterday how to compile and run a clojure program with the ClojureBox package. However, when I type Ctrl-C Ctrl-K it simply says "Compiling c:\clojure\celcius.clj..." and does nothing...

6:56 This program is taken from here by the way: http://clojure.org/jvm_hosted

6:57 any idea what i

6:57 'm doing wrong...?

7:09 jdz: don't know about clojurebox, but works for me without it.

7:11 spuz: I can use the normal java -cp clojure.jar etc. method, just trying to setup a proper editor though.

7:12 ClojureBox uses emacs+SLIME and that's what I can't seem to get my head around

7:22 ClojureBox uses emacs+SLIME and that's what I can't seem to get my head around

7:22 whoops, wrong window...

7:43 crios: hi

7:48 cgrand: crios: hi

8:01 crios: FYI: http://bestinclass.wordpress.com/2009/09/17/scala-vs-clojure-round-2-concurrency/

8:04 LauJensen: crios: Did you like it ?

8:05 ambient: interesting article

8:05 crios: interesting comparison, for a newbe on Clojure like me

8:06 ambient: i find it amusing how emotionally charged some programming discussions can get

8:06 LauJensen: ambient: I find that very tedious :)

8:06 ambient: amusing is better for my mental health :p

8:06 LauJensen: True - I'm glad you both liked it

8:07 crios: The author is... /Lau

8:07 mmm :)

8:07 LauJensen: That's me

8:07 crios: I was guessing it

8:10 I found amusing this sentence: "If your team is not able to adobt and fully appreciate Clojure in all it’s aspects I would not hesitate a moment in recommending Scala"

8:10 how do you know if the team is Clojure-compliant?

8:10 LauJensen: Yea, did you see I got quote of the week on ycombinator? :) For my remark on Static typing having it's place

8:10 ambient: well in Clojure the functional style is the only way to do things properly, afaict

8:10 LauJensen: crios thats a management issue :)

8:11 crios: Are you meaning that the team should already know a functional language, in order to adopt Clojure ?

8:12 ambient: it certainly would shorten the time required to grok it

8:12 LauJensen: No - If the average IQ in the room is above 120 and the lowest IQ is > 110, then you should give it a whirl

8:12 ambient: but im a noob, so my knowledge of this is very limited

8:12 i do well in IQ tests but dont do so well in clojure D:

8:13 LauJensen: ambient: Then just give it some time and read cgrands blog, you'll get in shape in no time

8:13 ambient: do i have to use monads for stuff?

8:13 LauJensen: Well, I never do :)

8:13 ambient: what is the idiomatic way of doing side effect-y stuff?

8:13 jdz: ambient: you just do it

8:14 ambient: you just have to be careful about it, and the consequences

8:14 ambient: for instance, doing logging in the wrong place may log the same thing more than once

8:14 LauJensen: hehe, there should be NO idiomatic way for doing that :)

8:18 crios: LauJensen: about the IQ: what if an average Java team IQ is lower < 80?

8:18 just joking :)

8:19 ambient: hmm, i dont have cgrands blog bookmarked, got link?

8:19 kunley: Hi.

8:20 AWizzArd: Compojure users: can I force to return html error codes? For example, if someone gave a wrong user/pass during Basic Auth, then I want to return 403 Forbidden

8:20 kunley: What's the idiomatic way of serializing Clojure stuff? Say I don't need to store Java objects, just Clojure immutables.

8:21 Think sth as easy as Erlang's term_to_binary

8:21 cgrand: ambient: clj-me.blogspot.com

8:22 ambient: cgrand thanks

8:24 LauJensen: crios, I was actually considering answering that as a blogpost, but I'm afraid people will get offended

8:25 ambient: one shouldn't worry about people who get offended by impassionate rational arguments

8:25 i mean dispassionate

8:28 cgrand: kunley: pr and read

8:30 Fossi: AWizzArd: return [401]

8:30 cgrand: if you want to serialize to something more compact, pipe it through a GZIPOutputStream

8:31 crios: LauJensen: sure people will get offended if you discard their IQs :)

8:31 kunley: cgrand: just checked, but it doesn't work for lambdas

8:32 cgrand: or does when i write to real stream instead of a terminal?

8:32 cgrand: no it doesn't work with closures

8:33 AWizzArd: Fossi: I have a (GET "/fossi" (return [401])) but when I visit /fossi I see only a blank page.

8:34 kunley: f

8:35 oops. Anyway is it possible/easy to store a portable representation of a closure? Assume we lost its source forms and we only have a compiled closure

8:38 crios: from the mailinglist: http://www.azulsystems.com/events/javaone_2009/session/2009_J1_JVMLang.pdf

8:40 cgrand: kunley: possible yes, easy no. eg: terracotta does it under the hood

8:40 Fossi: AWizzArd: for authentification you also have to return a WWW-Authentificate header field with a challenge

8:40 try returning something more visible like 500

8:41 AWizzArd: also "return" was just me saying that you should return it, not using "return" in the code

8:56 kunley: cgrand: will check that underhood then. I lost a track what's going on in the Java world in a couple of days. Now when it's easy to marry FP with JVM, there's lots of new stuff discovering on the way.

8:57 cgrand: s/days/for years/. Huh time for coffee ;)

9:39 crios: in a word, what is the exact sequence from text to executable code? reader -> compiler (to byte code) -> jit ?

9:39 manic12: just one word?

9:40 crios: three ;)

9:40 well just an overview

9:41 the APIs name also a "loader"

9:42 manic12: read compile [link] run[on runtime possibly with jit]?

9:42 knobo: Is it possible to load clojure-swank through beanshell?

9:42 I don't know so much about Java and beanshell and stuff like that..

9:44 jdz: what's beanshell?

9:44 manic12: i dunno what beanshell is but as long as swank loads and it doesn't take the swank/slime ports it should work

9:46 knobo: sorry I'm a bit foggy today. I mean to load just clojure, not swank

9:47 As logn as I can load clojure, I could start swank from there

9:47 manic12: I have successfully made some clojure code look like C

9:47 isn't that wonderful?

9:47 knobo: I can also make diamonds look like sh..t

9:47 :p

9:48 manic12: what do you mean? and why is that wonderful?

9:49 manic12: i have to either rewrite a large and highly mathematical library in a lisp or the ff calls make the program look like a c program

9:49 knobo: jdz: http://www.beanshell.org/

9:50 jdz: knobo: why do you want beanshell if you got Clojure?

9:50 manic12: it passes lots of double float arrays by value and also does a lot of `&' and `*&'

9:50 knobo: jdz: I want to boot clojure from beanshell

9:51 manic12: looks like beanshell has it's own repl

9:51 gotta pick one or the other or take the source of both and write your own

9:53 i'm sure if you take compiled clojure code you can call it from bean shell just like any jvm program

9:53 but i agree with jdz, porque?

9:57 knobo: I'm thinking it would be easy to add support for making extension clojure for openoffice.org if I could load and boot clojure from beanshell

9:57 as openoffice.org has support for beanshell

9:58 jdz: knobo: well, you have clojure.jar, don't you?

9:58 manic12: I am sure you can make an extension for openoffice without beanshell just with clojure

9:58 knobo: manic12: yes, that should also be possible

9:58 manic12: i once made a plugin for excel out of allegrocl

9:58 clojurebot: for is a loop...in Java

10:00 manic12: i am sure clojure & open office would be even easier

10:03 knobo: just use this recipes http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Scripting/Writing_a_LanguageScriptProvider_UNO_Component_using_the_Java_Helper_Classes

10:05 I would have to learn java, then..

10:08 manic12: java is easy enough to stumble through if you know any other languages

10:37 pixelman: omg the java interop JUST WORKS LIKE A CHARM!!!!!!!!!!! :)

10:37 one (.. to rule them all!

10:39 AWizzArd: ~max people

10:39 clojurebot: max people is 164

10:43 cgrand: pixelman: no, -> beats ..

10:44 pixelman: what do you mean ->?

10:46 Chouser: (doc ->)

10:46 clojurebot: "([x form] [x form & more]); Threads the expr through the forms. Inserts x as the second item in the first form, making a list of it if it is not a list already. If there are more forms, inserts the first form as the second item in second form, etc."

10:48 pixelman: wow

10:50 first day coding with clojure, but I've managed to build a pretty decent website with compojure and mysql connectivity, a full test suite, and I can leverage all the java libraries we have. I'm hooked :)

10:55 shoover: pixelman: Nice work! Testing with clojure.test?

10:55 pixelman: yep!

10:56 tnx

10:57 the only thing that's left is getting at the User-Agent header in compojure - I need to do some browser sniffing for mobiles

11:16 weissj: i am trying to play around with error-kit and getting this message: java.io.FileNotFoundException: Could not locate clojure/stacktrace__init.class or clojure/stacktrace.clj on classpath: (error_kit.clj:0)

11:17 i assume this is because my contrib isn't meant to be used with clojure-1.0.0.jar?

11:17 Fossi: i've had a similar problem and updating everything (clojure & contrib) helped

11:17 weissj: so 2 questions - is there a good doc or example for error-kit (besides halloway's log file parse example) and what versions of clojure/contrib do you recommend

11:17 stuartsierra: weissj: yes, that's it

11:18 weissj: should i just build my own clojure.jar then?

11:18 or is there something more stable than HEAD and less stable than 1.0.0?

11:19 Fossi: latest-greatest from git worked for us so far

11:19 weissj: k

11:19 Fossi: things tend to be really stable since most (major) development is done in branches anyway

11:19 weissj: Fossi: right

11:20 just wasn't sure if merges were synced with contrib or not

11:20 stuartsierra: no, no sync

11:22 weissj: anyone have hints what to read to understand error-kit?

11:22 besides source :)

11:25 cgrand: weissj: I think stuart halloway wrote something about error-kit

11:27 weissj: http://www.pragprog.com/magazines/download/1.pdf

11:27 weissj: cgrand yeah i read that already

11:29 here's my problem, i have web UI testing program that moves thru the app, doing various tasks. the app (when there's a problem) puts up a red error bar. some of my tests *expect* an error bar, but I need to handle this error just on the page where it's expected.

11:29 so i can define a red-error-bar error, but i need a way to let the caller specify where he expects to see it

11:41 crios: the private function legacy-repl in main.clj starts the real REPL ?

11:44 the commet says: "Called by the clojure.lang.Script.main stub to run a script"

11:44 *comment

11:45 pardon: "called by the clojure.lang.Repl.main stub to run a repl"

11:45 Chouser: weissj: with-handler ?

11:46 weissj: Chouser: and then how does the low-level callee unwind the stack to let the high level caller give the thumbs up on the expected error, and move on to the next test?

11:47 Chouser: weissj: I'm not sure I understand what you're saying. did you see the examples at the end and Halloway's writeup?

11:49 crios: ah ok, legacy-repl in the end calls the repl function

11:50 weissj: Chouser: yeah, but that's not quite what i'm trying to do. In java terms, i have a "RedErrorBarException" that can get thrown in 10 different places in a complex method, including methods it calls, etc. But my caller wants to know which of those 10 places threw it. becuase 9/10 of them are a problem, but the other 1 isn't.

11:51 now, it doesn't need to figure this out by the stack trace, in java maybe i'd have a field in the exception with an enum value or something. but this is a crazy way to do this

11:51 Chouser: the site that raise the exception have to somehow indicate which they are. Does CL provide something different?

11:51 weissj: Chouser: i'm much more of a newb in CL than clojure :)

11:51 Chouser: oh, ok.

11:52 so how do you *want* it to work?

11:52 if not figuring out based on stack trace, what should it use?

11:53 weissj: Chouser: well, it basically works in java when i put a field in the exception class. the caller catches that exception class, examines the contents, and if it is not a match, rethrows it. but i want to avoid the catch/rethrow

11:53 and just have it catch when there's a match.

11:54 Chouser: ah. why do you want to avoid the rethrow?

11:54 weissj: well, i want to avoid catching stuff that's not meant to be caught

11:55 java only lets you catch by exception type

11:55 Chouser: ok, I think you can do this.

11:55 raise with some flag indicating which kind of raise it is, right?

11:56 weissj: Chouser: yeah

11:56 Chouser: then in your handler, check the flag -- if you really want to throw something, throw a new exception that's not being handled.

11:57 otherwise do a continue-with

11:58 weissj: Chouser: perhaps another way is to just have different error types. the reason i don't do that in java is because i'd end up with 8000 different exception types, but maybe in clojure the error types are cheaper (in terms of LOC at least)

12:00 to restate the problem, the caller says "try this procedure, which can throw 'not-found-error' in lots of places, but i want to make sure the thing that wasn't found is the thing i am working with, not some other low level thing that i know nothing about'

12:09 Chouser: what is the args-destruct-map of deferror? it has something to do with raise only being able to take 1 arg?

12:11 Chouser: gah, so much complexity. I really need to figure out what can be torn out of there.

12:11 looks like deferror can take either a vector of args or a map of args.

12:12 I can't even think at the moment how you'd use the map version. but you can specify a vector of arg names in deferror, and a matching list of values in raise.

12:13 duncanm: sigh, i have to write Java code (and not clojure right now), but is there a method like 'map' in Java's collection library?

12:19 Makoryu: duncanm: No.

12:22 duncanm: Imagine for a moment what that would look like, actually.

12:23 There would be, at a minimum, a multiparameter generic interface or abstract class describing the type of the function you'd be calling, with some arbitrary name for calling it.

12:24 Chousuke: FunctionalTools.map(new UnaryFunction() { public void invoke(Object o) { o.whatever(); ... } }); ? :P

12:24 Makoryu: Pretty much.

12:25 Chouser: returns an object not void, right? maybe should be generic...

12:25 Chousuke: hmm, right.

12:25 in any case, too horrible to actually use :)

12:32 stuartsierra: Chousuke: that exists, it's called Functional Java http://functionaljava.org/

13:20 dthomas: What's the difference between clojure.contrib.greatest-least/greatest-by and the core function max-key?

13:21 hiredman: ,(doc max-key)

13:21 clojurebot: "([k x] [k x y] [k x y & more]); Returns the x for which (k x), a number, is greatest."

13:21 hiredman: ,(doc greatest-by)

13:21 clojurebot: "clojure.contrib.greatest-least/greatest-by;[[f & args]]; Return the argument for which f yields the greatest value."

13:21 Chousuke: hm

13:21 dthomas: Maybe the difference there is "number" vs. "value"?

13:52 crios_: what is the function which unmap a symbol from a Var object?

13:52 Chousuke: ns-unmap? :)

13:53 crios_: mmm :)

13:54 thank you

14:17 ambient: hmm, arity based dispatching is supposed to be a good way to introduce helper functions in clojure, but wouldn't scheme's way of doing things with putting function definitions inside function definitions be better?

14:18 like (defn foo [x] (defn bar [y] (+ y 1)) (bar x))

14:18 hiredman: you can, using letfn or plain let

14:18 :||

14:18 don't do that

14:18 ambient: why?

14:18 hiredman: def, defn, defmacro, etc

14:19 they create global bindings of names to vars

14:19 ambient: aaaa..

14:19 so its not lexically scoped?

14:19 hiredman: clojurebot: clojure is also not scheme

14:19 clojurebot: Roger.

14:19 ambient: :p

14:19 hiredman: if you want lexical scope, use let or letfn

14:19 ambient: ok

14:19 hiredman: clojurebot: what is clojure?

14:19 clojurebot: clojure is a very attractive hammer with a nice heft to it

14:31 deafmacro: hello, I would appreciate it if someone could explain how to use 'constantly'. I have looked at the example on the site but could not think of real world scenario for it.

14:32 ambient: well if my doctor is going to tell me to say "a" i shall write (constantly \a) ;)

14:32 and he can then take as many as he likes

14:32 hiredman: it can be useful because the mutation functions for atoms, refs, and agents all take a function

14:32 ,(send-off (agent 0) (constantly 1))

14:32 clojurebot: #<Agent@4aca27: 0>

14:33 hiredman: ,(let [a (send-off (agent 0) (constantly 1))] @a)

14:33 clojurebot: 0

14:33 hiredman: bah

14:33 ,(let [a (send-off (agent 0) (constantly 1))] (await a) @a)

14:33 clojurebot: 1

14:33 hiredman: ,(doc await)

14:33 clojurebot: "([& agents]); Blocks the current thread (indefinitely!) until all actions dispatched thus far, from this thread or agent, to the agent(s) have occurred."

14:34 Chouser: it doesn't get used a whole lot. You could say #(do 1) instead, but 'constantly' may be a bit clearer.

14:34 hiredman: hmmm

14:34 Chouser: #(do 1) takes no args

14:34 Chouser: ah, good point!

14:34 hiredman: what does await return?

14:34 Chouser: #(do %& 1)

14:34 yuck

14:34 deafmacro: hiredman: didn't quite get it. from what ambient said it seems like some lazy thingy

14:34 hiredman: ,(await (agent 1))

14:34 clojurebot: nil

14:35 ambient: ignore me

14:35 Chouser: deafmacro: 'constantly' just returns a function. that's it. Other things that return a function are the (fn ...) form and the #(...) form

14:35 hiredman: deafmacro: if you had an agent A how would you set its value to 1

14:35 deafmacro: ah

14:36 I get the picture

14:36 instead of writing (fn [x] x) I can you constantly

14:36 Chouser: almost

14:36 what you wrote there is actually called 'identity'

14:37 hiredman: constantly is more like (fn [& x] 1)

14:37 Chouser: 'constantly' is more like (fn [x y z & etc] 5)

14:38 * deafmacro is trying to grok it

14:38 hiredman: (fn [x] (fn [& y] x))

14:38 Chouser: heh

14:38 hiredman: (((fn [x] (fn [& y] x)) 1) :foo :bar :baz)

14:38 ,(((fn [x] (fn [& y] x)) 1) :foo :bar :baz)

14:38 clojurebot: 1

14:40 deafmacro: ah so is it basically like writing a function to return a function?

14:40 hiredman: constantly is a function that returns a function

14:40 Chouser: ,(((((fn [x] (fn [] x)) (fn [] (fn [x] x))))) 5)

14:40 clojurebot: 5

14:40 Chousuke: whoa, that's some paren soup :P

14:40 Chouser: that, on the other hand, is just nonsense.

14:41 :-)

14:41 hiredman: ,(#(% %) #(% %))

14:41 clojurebot: java.lang.StackOverflowError

14:41 deafmacro: my head is spinning looking at that :)

14:41 Chouser: don't look at mine. It's nothing.

14:41 hiredman: ~def constantly

14:41 clojurebot: well?

14:41 clojurebot: I don't understand.

14:41 Chouser: actually, it's 'identitiy'

14:41 identity

14:41 hiredman: clojurebot: well?

14:41 clojurebot: excusez-moi

14:41 hiredman: ~def constantly

14:41 wtetzner: ,(doc identity)

14:41 clojurebot: "([x]); Returns its argument."

14:42 wtetzner: ,(doc constantly)

14:42 clojurebot: "([x]); Returns a function that takes any number of arguments and returns x."

14:43 hiredman: ugh

14:44 deafmacro: I still dont see the point. pardon me. let me ruminate over this for a while and get back

14:44 Chouser: deafmacro: really, 'constantly' is hardly ever used.

14:44 ,(map (constantly 5) (range 10))

14:44 clojurebot: (5 5 5 5 5 5 5 5 5 5)

14:45 Chousuke: deafmacro: the point is that some higher-order functions take other functions as parameter and constantly is a good way to give a "constant"

14:45 Chouser: ,(repeat 5 10)

14:45 clojurebot: (10 10 10 10 10)

14:45 Chouser: ,(repeat 10 5)

14:45 clojurebot: (5 5 5 5 5 5 5 5 5 5)

14:45 deafmacro: ah the higher order function thing made sense :)

14:46 ambient: (take 5 (whats-this? 10)) => [10 10 10 10 10] ?

14:46 Chouser: ambient: repeat

14:46 ,(take 5 (repeat 10))

14:46 clojurebot: (10 10 10 10 10)

14:46 Chousuke: ,(let [a (atom 1)] (println "atom is " @a) (swap! a (constantly 2)) (println "atom is " @a))

14:46 clojurebot: atom is 1 atom is 2

14:46 ambient: oh, it works like that too

14:46 Chouser: ambient: yeah, there used to be 'repeat' and 'repeatedly', but that just ended up seeming kinda silly

14:47 Chousuke: (doc repeatedly)

14:47 clojurebot: "([f]); Takes a function of no args, presumably with side effects, and returns an infinite lazy sequence of calls to it"

14:47 Chousuke: repeatedly is different. :)

14:47 (take 5 (repeatedly rand-int)

14:47 ,(take 5 (repeatedly rand-int))

14:47 clojurebot: java.lang.RuntimeException: java.lang.IllegalArgumentException: Wrong number of args passed to: core$rand-int

14:47 Chousuke: hm, damn

14:47 ambient: (repeat 5) broke my repl :(

14:48 Chousuke: well, you tried to print an infinite seq :)

14:48 Chouser: ambient: (set! *print-length* 103)

14:48 ambient: right...

14:48 Chouser: Chousuke: you're right. what was I thinking of?

14:48 replicate!

14:49 ambient: hmm, exterminate

14:49 no such symbol :(

14:49 Chouser: repeat has subsumed replicate -- repeatedly is indeed different.

14:50 deafmacro: ambient, Chouser, hiredman : thanks!

14:50 Chouser: ,(take 10 (iterate (constantly 5) nil))

14:50 clojurebot: (nil 5 5 5 5 5 5 5 5 5)

14:50 Chouser: hm

14:51 ambient: it seems iterate doesnt apply the function to the first value

14:51 Chouser: (take 10 (cons nil (repeat %)))

14:51 ambient: right.

14:54 hiredman: 3

15:02 clojurebot: egal?

15:02 clojurebot: I don't understand.

15:02 hiredman: clojurebot: egal is http://home.pipeline.com/~hbaker1/ObjectIdentity.html

15:02 clojurebot: Ok.

15:11 hiredman: ~def =

15:12 clojurebot: why do you treat me so?

15:12 clojurebot: http://clojure.org/rationale

15:12 hiredman: $%@#$

15:13 Chousuke: :P

15:14 hiredman: ~def =

15:14 ~def =

15:14 hmmm

15:14 whoops

15:18 ~def =

15:20 ~def clojure.lang.Util

16:21 stuartsierra: Updated Clojure-Hadoop with custom readers/writers. http://github.com/stuartsierra/clojure-hadoop

16:37 ordnungswidrig1: Can anybody enlighten me about multimethod dispatching on a keyword hierachy? I'd like to use sth. like (draw :rect 1 2) and (draw :ellipse 1 2) where :rect and :ellipse are of type :shape and there is a method instance (draw :shape) which shall be the fallback if no method was declared for a certain sub type

16:37 stuartsierra: Well, you (defmethod :rect...) (defmethod :shape ...) etc.

16:38 dnolen: ,(doc derive)

16:38 stuartsierra: Then (derive :rect :shape)

16:38 clojurebot: "([tag parent] [h tag parent]); Establishes a parent/child relationship between parent and tag. Parent must be a namespace-qualified symbol or keyword and child can be either a namespace-qualified symbol or keyword or a class. h must be a hierarchy obtained from make-hierarchy, if not supplied defaults to, and modifies, the global hierarchy."

16:38 stuartsierra: But you'll have to use namespaced keywords, like ::rect and ::shape

16:40 Chouser: and defmethod needs a method name (defmulti draw ...) (defmethod draw ::rect ...)

16:40 dnolen: ,(isa? (derive ::rect ::shape) ::shape)

16:40 clojurebot: false

16:40 Chouser: but yes, 'derive' is the key

16:40 ,(derive ::rect ::shape)

16:40 clojurebot: nil

16:40 Chouser: ,(isa? ::rect ::shape)

16:40 clojurebot: true

16:41 Chouser: ,(isa? ::dnolan ::shape)

16:41 clojurebot: false

16:41 dnolen: ,(do (derive ::rect ::shape) (isa? ::rect ::shape))

16:41 clojurebot: true

16:41 dnolen: heh :) it's good to be a shape

16:41 Chousuke: note that hierarchies are completely separate from multimethods

16:41 that is, you can use them for your own purpose as well

16:41 Chouser: dnolen: derive modifies (yes, mutates!) a global hierarchy -- no need to scope it with 'do'

16:42 dnolen: Chouser: yeah, but derive doesn't return the tag, returns nil right?

16:42 ordnungswidrig1: why namespace keywords?

16:42 Chousuke: ordnungswidrig1: to avoid collisions

16:42 ordnungswidrig: ok, I will try

16:43 dnolen: ordnungswidrig: so that code in other namespaces can extend your multimethods

16:43 ordnungswidrig: dnolen: I see

16:43 I'll talk to my repl now :-)

16:45 Chouser: dnolen: yes

16:46 * ordnungswidrig gets NPEs

16:47 ordnungswidrig: How must I use defmulti?

16:47 (defmulti draw) ?

16:49 dnolen: ordnungswidrig: http://clojure.org/multimethods, look at the example at the bottom of the page.

16:52 ordnungswidrig: dnolen: the page confuses me. the second to last example is using namespaced keywords and the last one hierachies.

16:52 dnolen: but the last one decides on the value of the :Shape attribute of the record, right?

16:57 stuartsierra: yes

17:14 ordnungswidrig: http://gist.github.com/189297

17:14 Wrong number of args passed to: user$fn

17:14 * ordnungswidrig scratches his head

17:16 ordnungswidrig: I'll better go to bed for now. see you all

17:18 hiredman: (println (draw ::triangle 1 2)) <-- three args

17:19 (defmethod draw ::shape [x y] "shape") <-- two args

17:43 scottj: Anyone know if there was a recording made of the Rich's entire JVM Summit talk this year or if it's going to be posted?

17:52 hiredman: scottj: I hear yes and yes

17:53 spaceman_stu: danlarkin: boat computing, eh? nice

17:54 scottj: hiredman: cool. hopefully the one where you can see everyone's heads and the camera isn't on a tripod isn't the only one :)

17:58 In Rich's slides he says "parallel code needs to be declarative - no loops!" and as examples of declarative he has "map/reduce etc." What other clojure functions fall under "etc"? Is this the seq library, or more or less than that?

17:59 Chousuke: map, reduce, filter, whatever? :)

17:59 hmm, I wonder what a whatever function would do

17:59 "spend some CPU cycles if you like, I don't really care"

18:02 scottj: Chousuke: haha

18:04 Chousuke: the ultimate in declarative programming would be the do-what-i-mean function, but the implementation is tricky :/

18:08 danlarkin: spaceman_stu: :)

18:14 beutdeuce: how can I do file input in Clojure?

18:14 where i can read by line

18:14 spaceman_stu: danlarkin: cool. I'm jsut across the canadian border from you guys - nice day for it

18:14 danlarkin: spaceman_stu: yeah it's perfect out

18:14 last day of our seattle trip, wrapping it up now

18:17 scottj: beutdeuce: line-seq maybe

18:56 beutdeuce: how would i be able to iterate through the elements of a lazy sequence?

18:58 spaceman_stu: beutdeuce: whether it's lazy won't affect consuming it really

18:59 beutdeuce: alright, how would i be able to iterate through each element of a sequence without specifying a binding for loop

19:00 hamza`: hey guys, is it possible use apply to turn a [:a 1 :b 2] vector to a map {:a 1, :b 2}?

19:01 spaceman_stu: hamza`: (into {} (partition 2 {:a 1 :b 2}))

19:02 hamza`: thx i was way of, been trying (apply {} [2 3]) :)

19:03 spaceman_stu: beutdeuce: is something like (doseq [c your-collection] (whatev)) what you're looking for?

19:03 beutdeuce: not really, that is just looping, i need iteration

19:08 spaceman_stu: beutdeuce: why iteration? and what specifically do you mean by looping rather than iteration

19:09 beutdeuce: nvm, i was just thinking of a map

19:09 m4nic: Hi all, I am working with clojure regexpes and am making a parser

19:09 for org-files, for this i need an multi-line regexp. Is there a nice

19:09 way, without going to java that is, to define such a regexp.

19:12 hamza`: (into {} (partition 2 (re-split #":" "test: asd" ))) doesn't this work for sequences?

19:15 ankou: hi, is there a possibility to call the method of the superclass in proxy? or what would be a better way to override the paintmethod of a swingcomponent?

19:16 hamza`: m4nic: you can use flags in side regex's such as (?s)

19:17 beutdeuce: clojure cannot apply re-seq to a lazy sequence of a string?

19:18 why doesnt this work

19:18 (defn runprogram [file]

19:18 (with-open [buffer (java.io.BufferedReader. (java.io.FileReader. file))

19:18 lines (line-seq buffer)]

19:18 (map #(re-seq #"\s" %1) lines)))

19:21 hamza`: is it possible to get a map test->asd from (re-split #":" "test: asd" )?

19:25 beutdeuce: how can i convert a lazy sequence to a vector?

19:26 _mst: ,(into [] (range 5))

19:26 clojurebot: [0 1 2 3 4]

19:26 beutdeuce: thnx

19:26 spaceman_stu: or vec

19:27 (vec (range 5))

19:27 beutdeuce: huh. No matching field found: close for class clojure.lang.LazySeq

19:27 [Thrown class java.lang.IllegalArgumentException]

19:27 _mst: beutdeuce: you don't want that call to line-seq inside the with-open

19:27 beutdeuce: yeah,

19:27 _mst: it's going to try to call .close on the resulting seq, which won't work

19:28 ankou: anyone?

19:29 _mst: ankou: does proxy-super do what you want?

19:30 ankou: maybe for the moment it leads to very confusing behaviour

19:31 okay yes, thanks

19:36 hamza`: is it possible to get a map test->asd from (re-split #":" "test: asd"

19:36 )?

19:38 _mst: ,(apply hash-map (re-split #": " "test: asd"))

19:38 clojurebot: java.lang.Exception: Unable to resolve symbol: re-split in this context

19:38 _mst: ah :) That sort of thing anyway

19:39 hamza`: got it thx alot

19:48 scottj: m4nic: out of curiousity, what are you going to do with the org-files?

20:21 deshkanna: hi

Logging service provided by n01se.net