#clojure log - Oct 05 2009

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

0:15 lisppaste8: steiger pasted "Can someone explain to me this behavior?" at http://paste.lisp.org/display/88140

0:23 steiger: seems like a bug to me

0:26 hiredman: what does dist-map say now?

0:28 steiger: test> dist-map

0:28 #<Ref@7673a2: {}>

0:28 if I remove the last exp, (prn @dist-map), the function works as expected

0:29 hiredman: anyway

0:30 it works here on 1.0 and a snap shot of git master

0:31 I'd restart your repl and try again

0:31 steiger: i'm running clojure-box and it doesn't work here. (clojure-version) shows "1.0.0-"

0:31 i guess i'll update

0:32 hiredman: I tried it on 1.0.0- (the download from clojure.org) it worked like expected

0:33 if you haven't yet, restart the repl and try from scratch

0:34 konr: Where can I find clojure examples of java interoperability, particularly, uses of the proxy macro?

0:36 steiger: hiredman did it. still not working. this is very weird

0:36 hiredman: http://delicious.com/clojurebot/pastbin

0:37 I'm tempted to just blame emacs (being a vim guy)

0:40 briancarper: steiger: map is lazy, so I think the guts of initialize-dist-map are never evaluated in your second version of init.

0:41 Try using dorun or doseq.

0:42 steiger: briancarper hmm.. makes sence

0:42 *sense

0:43 briancarper worked :) thanks

0:43 hiredman thankyou also

0:45 hiredman: ah

0:45 I wasn't reseting dist-map between runs

0:45 no wonder

1:38 mikem: The repl started in VimClojure (with <LocalLeader>sr) doesn't like to output test results (functions defined with deftest from clojure.test). The clojure REPL launched from the command line does.

1:39 has anyone encountered this before?

3:00 adityo: (import '(java.math sqrt))

3:00 what am i doing wrong?

3:00 slashus2: adityo: You can do just (Math/sqrt 5)

3:01 adityo: slashus2: okie so i dont need to import it?

3:01 slashus2: no

3:01 That is correct.

3:02 adityo: okie thanks

3:03 slashus2: You are very welcome.

3:07 hiredman: there is no java.math, iirc

3:07 it is java.lang.Math

3:07 and Math is not a namespace, it is a utility class

3:08 which means it is a class with a lot of static methods

3:08 adityo: allright..much clearer now

3:12 hoeck1: hiredman: there is a java.math package, it houses the BigDecimal and BigInteger classes

3:15 hiredman: hoeck1: pardon me

3:47 konr: How can I turn `e.getActionCommand( ).equals("Metal")` into clojure? (.. e getActionCommand equals "Metal")?

3:53 hoeck1: konr: or (-> e .getActionCommand (.equals "Metal))

3:54 konr: or (= "Metal" (.getActionCommand e))

3:57 konr: hoeck1: thanks!

4:01 hoeck1: konr: the dotted-methodname syntax is preferred these days, and (. ) is only used in macros expanding to method calls

4:10 milep: can I assign multiple variables like in Ruby x, y = [1, 2]?

4:11 slashus2: ,(let [[a b] [1 2]] [b a])

4:11 clojurebot: [2 1]

4:12 milep: ok, thanks

5:03 konr: Should a (println "foo") print "foo" on the repl everytime it is evaluated, or the output can be redirected somewhere?

5:11 LauJensen: konr the output can be redirected, and in slime/emacs this sometimes happends without you asking for it, ie when using threads :)

5:11 ,(with-out-str (println "hi there"))

5:11 clojurebot: "hi there\n"

5:18 konr: LauJensen: haha, I knew! Thanks!

5:53 namor: Hmm, I found this fibonacci example from wikibooks, but I get the error message: Unable to resolve symbol: lazy-cons in this context

5:53 Where did lazy-cons go?

5:56 hoeck1: namor: it has been replaced by lazy-seq some time ago

5:57 namor: lazy-cons was too eager, it always computed the first value of the lazy seq

5:59 namor: I see. But I don't understand lazy-seq from just reading the api docs.. Lazy-cons was somewhat obvious if you come from lisp.

6:00 How would you recursively build a list with lazy-seq?

6:03 lisppaste8: hoeck pasted "lazy-seq fib" at http://paste.lisp.org/display/88148

6:03 hoeck1: namor: like ^

6:04 namor: Thanks!

6:04 hoeck1: namor: so you basically wrap your list building code with lazy-seq

6:21 angerman: can I ask clojure for a list of all files in ./**/*.wav?

6:28 yason: angerman: use file-seq and filter what you need from there

6:39 konr: I'm using swing, so it's hard to see the exceptions. Is there a way to capture every one of them and save in a file, or something like that?

6:47 Is Java's System.exit(0) the same as ((. System exit) "0"))?

6:49 Chousuke: no

6:49 it's (. System (exit 0))

6:49 or, better: (System/exit 0)

6:50 . is a "low-level" operator and it's usually better to instead use the sugary forms provided. :)

6:52 ie. (.method obj args...) for methods and instance fields and (Class/staticMethod args...) for static methods or fields

6:52 ,Math/PI ; no parens needed for static fields, either

6:52 clojurebot: 3.141592653589793

7:00 konr: Chousuke: hmm, so in the case of System.err.println("foo"), I can use (System/err/println "foo")?

7:00 Chousuke: konr: no, that's different.

7:00 err is an object

7:01 so (.println System/err "foo")

7:03 or (binding [*out* *err*] (println "foo")) :P

7:08 konr: interesting! Can I bind *out* to a file?

7:09 (handle)

7:10 Chousuke: any Writer object

7:10 (doc with-out-str)

7:10 clojurebot: "([& body]); Evaluates exprs in a context in which *out* is bound to a fresh StringWriter. Returns the string created by any nested printing calls."

7:11 Chousuke: you could make a similar macro, but for a file :)

7:47 cypher23: hello all, I put my clojure startup script online, maybe someone will find this useful: http://blog.nuclearsquid.com/writings/clj-startup-script

8:57 angerman: did anyone write a sould play wrapper for clojrue?

9:22 LauJensen: In Rich's description of transients .org/transients, he says that the return value must be captured and that thusly transients are not meant to be 'bashed into place', but why then, does this work? (def t (transient [1 2 3])) (assoc! t 1 10) (persitent! t) ?

9:24 hoeck1: LauJensen: by accident?

9:25 LauJensen: Its a bug?

9:25 angerman: how would I do something like reading from one stream and writing to another with clojure?

9:25 with java one would usually take some byte buffer, and loop until all is thogh

9:25 hoeck1: LauJensen: no, you just shouldn't do it this way, its not expected to work

9:26 LauJensen: so now that we can see that it does - that must constitute a bug, or a least unintended behaviour

9:27 hoeck1: LauJensen: of course, we could ad numerous modifiers to the language to forbid certain uses of things

9:29 LauJensen: to me, its roughly the same like (while (< x 10) (def x (inc x))), you shouldn't do that too, but its not a bug that it works

9:29 LauJensen: Ok - I don't see it that way

9:30 yason: angerman: check out clojure.contrib.duck-streams, there's (copy ...) for that

9:38 danlei: I see that swank-clojure's build.xml is gone. how would I just build swank-clojure.jar without using that clojure-install stuff now?

9:54 angerman: yason: thanks :)

9:54 how do i instantiate a static class?

9:54 this one: http://java.sun.com/j2se/1.4.2/docs/api/javax/sound/sampled/DataLine.Info.html

10:01 dliebke: angerman: (javax.sound.sampled.DataLine$Info. lineClass format)

10:06 angerman: dliebke: ohh thanks.

10:06 forgot about the $ notation

10:07 hmm, how can I call a multimethod straight?

10:07 I want to use copy.

10:07 but copy is a multimethod that switches on the types of the classes

10:08 but I know I want to call (defmethod copy [InputStream OutputStream] ...

10:09 dliebke: hmm, that's a good question. I don't know if you can call a multimethod directly (like you can in R)

10:10 angerman: hmm. well. looks like I'm gonna copy'n'paste :)

10:10 it's not clean though. I like the protocol idea better. why not make sure both objects just adhere to those methods you want to call with the given signature?

10:11 blitz_: how do I use clojure-contrib from within slime? it seems I have to add it to the classpath. but how?

10:12 angerman: blitz_: doing that post-init is not really possible i think.

10:12 you have to tweak your init paths

10:12 danlei: blitz_: add-classpath from the repl ("post-init") or swank-clojure-extra-classpaths in your .emacs

10:12 angerman: danlei: does that add-classpath really work?

10:12 blitz_: thx

10:12 danlei: yes, it works

10:13 angerman: danlei: hmm... i must have made something wrong then

10:13 danlei: it's considered bad style for anything but playing around though

10:13 blitz_: danlei: it is already in my classpath... strange

10:13 danlei: use it like this (add-classpath "file:///c:/.../my.jar")

10:15 it's in your classpath and doesn't work?

10:15 blitz_: danlei: sorry. it works. don't know what I did wrong

10:15 danlei: ok

10:16 angerman: http://gist.github.com/201412

10:16 whee :)

10:17 finally

10:17 now I just need to figure out how to work with unicode filenames :(

10:17 user> (.getName file-obj);; => "?.wav"

11:02 how can I make clojure handle japanese characters in the repl?

11:05 raek_: angerman: where are you using the REPL? in a terminal? emacs?

11:06 angerman: emacs

11:06 i though it should support unicode

11:06 so the int value of the charater is 12354

11:06 being the unicode codepoint for あ

11:07 raek_: I have no problem using UTF-8 encoded unicode characters in the REPL in my UTF-8 configured terminal

11:07 ,"åäö"

11:07 clojurebot: "åäö"

11:07 raek_: ,"あ"

11:07 clojurebot: "あ"

11:07 angerman: but for some reason when I do (prn my-str) it fails.

11:07 raek_: well, I'm not entering it that way. it's the filename

11:08 raek_: ,(prn "あ")

11:08 clojurebot: "あ"

11:08 raek_: ok

11:09 maybe java doesn't know which coding your filenames are in

11:09 danlei: how I love it ... an innocent "git pull" in swank-clojure, and nothing works anymore :)

11:09 raek_: to me, this looks like a java issue

11:10 angerman: what happens when you run (seq (.getName file-obj)) ?

11:11 does it treat the character boundaries right?

11:11 angerman: ,(prn "\u3042")

11:11 clojurebot: "あ"

11:11 angerman: hmm ok.

11:11 so it must be something with my repl-emacs bridge

11:12 raek_: no, it seems the file is read correctly

11:14 basically when I enter (prn "\u3042") at the repl in emacs I get a "?"

11:20 wow

11:20 here we go

11:20 (set-language-environment "UTF-8")

11:20 (setq slime-net-coding-system 'utf-8-unix)

11:20 why that wasn't default ... puzzledme

12:24 crios: hello. I don't understand this.

12:24 :

12:24 ,(cons '2' (seq 4))

12:24 clojurebot: (2 seq 4)

12:24 crios: but:

12:24 ,(seq 4)

12:24 clojurebot: java.lang.IllegalArgumentException: Don't know how to create ISeq from: Integer

12:25 crios: How is 'cons' working there?

12:28 ambient: cons isn't probably trying to evaluate seq as a functino

12:29 it just directly takes the list as input

12:30 which is weird because (cons 2 (df ij gh)) doesnt really work

12:31 crios: ,(cons '2' ((seq 4)))

12:31 clojurebot: (2 (seq 4))

12:31 crios: yes, I understand your point ambient, but it is weird

12:33 (doc cons)

12:33 clojurebot: "([x seq]); Returns a new seq where x is the first element and seq is the rest."

12:35 crios: so, if the second parameter would be evaluated, the doc would say "and seq is an expression which after evaluation become the rest"?

12:45 hiredman: crios: clojure doesn't single quote strings

12:45 (cons '2' (seq 4)) => (cons '2 '(seq 4))

12:46 ,('seq 4)

12:46 clojurebot: nil

12:46 hiredman: er

12:46 ,'(seq 4)

12:46 clojurebot: (seq 4)

12:46 crios: so the second parameter (seq 4) is read as a string?

12:47 hiredman: no

12:47 it is quoted

12:47 crios: ah ok, the second '

12:47 hiredman: ,(cons "2" (seq 4))

12:47 clojurebot: java.lang.IllegalArgumentException: Don't know how to create ISeq from: Integer

12:47 hiredman: ,(cons 2 (seq 4))

12:47 clojurebot: java.lang.IllegalArgumentException: Don't know how to create ISeq from: Integer

12:47 hiredman: ,(cons 2 '(seq 4))

12:47 clojurebot: (2 seq 4)

12:48 crios: my first argument should be a character

12:48 '2'

12:48 hiredman: no

12:48 crios: at least, my intention

12:48 hiredman: characters are preceded by \

12:48 \2

12:48 ,(class \2)

12:48 clojurebot: java.lang.Character

12:49 crios: ,'2'

12:49 clojurebot: 2

12:49 hiredman: no

12:49 try calling class on that

12:49 (you cannot do it)

12:50 'a' is not a character literal

12:50 crios: yes, you are right

12:50 hiredman: it is a quoted symbol followed by another quote, so the following form will also be quoted

12:51 crios: I have to refresh that basic topic! (too much different languages lately!)

12:51 thanks

12:52 Kototama: hi, i want to sort a list of list by length, can somebody explain me why (sort-by count '('(a b c) '(xx) '(aa bb cc dd) '(oo)) ) dont' do the job?

12:52 hiredman: (cons '2' (seq 4)) is kind of trippy, it took me a beat or two to realize what was going on

12:52 Kototama: that's an aweful lot of qouting

12:53 ,(sort-by count '((a b c) (xx) (aa bb cc dd) (oo)))

12:53 clojurebot: ((xx) (oo) (a b c) (aa bb cc dd))

12:53 hiredman: ,''(aa)

12:53 clojurebot: (quote (aa))

12:56 Kototama: oh ok

12:56 thx you :)

13:49 ambient: how do i autocomplete stuff that is in clojure.contrib in emacs?

13:50 dmiles_afk: rhickey wrote dotlisp yers ago . and now write clojure.. clojure is alot better?.. but i am seeing some things in .NET like event that JVM doesnt support.. i wonder about ClojureCLR if it will have these things

13:51 ClojureCLR > DotLisp > Clojure

13:51 ">" greater than

13:51 hiredman: eh?

13:51 dmiles_afk: right now i am up in the air about: DotLisp "what is here?" Clojure

13:52 DotLisp was in my interpretation the prototype of clojure

13:52 hiredman: are you actually writing any code?

13:52 dmiles_afk: mostly interpreting users code

13:52 ambient: i heard .NET supports TCO

13:52 dmiles_afk: but written a bit of DotLisp

13:53 which is clojure basically

13:53 hiredman: eh?

13:54 dmiles_afk: well i am trying to decide.. if i should replace the DotLisp.dll with Clojure

13:54 hiredman: there are surface syntax similarities

13:55 dmiles_afk: then trying to decide between ClojureCLR vs CLojure.IKVM.Compile

13:55 then trying to decide between ClojureCLR vs CLojure.IKVM.Compiled

13:55 hiredman: are you sure you want to go with the clr over the jvm?

13:55 dmiles_afk: Clojure.IKVM.Compiled (i tested this one and it basically works)

13:56 well the rest of the project is CLR.. but really i love the JVM more

13:56 and the only reason .NET/CLR sucks is the perfomarnce.. deep down is a little better

13:56 hiredman: I would go with the actaully port of clojure to clr over ikvm

13:57 dmiles_afk: so i live with performance degrdation for the ValueType feature

13:57 hiredman: a minivan has more cup holders than a ferrari

13:57 dmiles_afk: yeah i probly a mini van guy

13:58 ok i shall really give ClojureCLR a chance

13:59 just was scared its going to (eventualy if not now) get neglected

14:00 (when something neat happens the the Clojure JVM world - not propogate)

14:01 notallama: i think the plan is to rewrite clojure in itself. so in the long run at least, the ports shouldn't get hurt.

14:02 dmiles_afk: yet ClojureCLR has chances at features regular Clojure wishes the JVM could provide

14:02 cypher23: anyone knows why this happens: java.lang.SecurityException: class "javax.media.opengl.GL"'s signer information does not match signer information of other classes in the same package (core.clj:9)

14:03 I get this while trying to use Penumbra (http://github.com/ztellman/penumbra), and typing "(use 'examples.gears)" in the REPL

14:03 dmiles_afk: "rewrite clojure" - less progress in the shortterm but stll a good thing

14:03 cypher23: I'm on Snow Leopard, Clojure is the latest version from GitHub

14:05 notallama: is mono any good? my plan is to avoid clr like the plague anyway, but i'm curious.

14:07 Guest92834: why avoid it? it kicks ass

14:07 Makoryu: notallama: The big issue looming over Mono right now is the conservative garbage collector

14:16 notallama: it's bassically that it comes from microsoft. microsoft stuff costs money, so if i'm not being paid to use it, i'm not going near it.

14:18 dmiles_afk: mono is only 1/2 th speed of the jvm usually

14:19 well sometimes 1/4 .. but other than that it uses less memory for the same tasks

14:19 hiredman: how are you measuring that?

14:20 dmiles_afk: i large Lisp app framework (like larkc)

14:20 a large Lisp app framework (like larkc) .. originaly written in java.. it compiles lisp code to .java files... but also targeting .cs

14:21 notallama: could it be that it's more aggressive when compiling to .java?

14:22 dmiles_afk: so the comarison is slightly skewed.. but when we rewrite parts (not translatated) we end up feeling this way

14:22 it is.

14:22 the unbaiser is that more of the .cs was hand written

14:23 so even though the the .java is more mature.. the .cs is sometimes better done

14:23 notallama: that doesn't sound terribly scientific

14:24 dmiles_afk: so times a human wrote both.. you end up going.. wow "mono sure uses up less memory.. god i wish it was fast as java"

14:24 hiredman: how are you measuring that?

14:24 by that I mean the memory use

14:24 raek_: cypher23: I got a similar problem when I tried to use compojure

14:24 cypher23: raek_, did you solve it? how?

14:25 hiredman: mono tends to be more dynamic about memory use

14:25 raek_: in my case the problem was that I had multiple versions of jetty

14:25 dmiles_afk: for instance the FIXNUM cache in java is 500mb .. in csharp 0mb

14:25 raek_: so java loaded som classes from one place and other from another place

14:25 hiredman: dmiles_afk: how are you measuring that?

14:25 raek_: so the signatures didn't match package-internally

14:26 dmiles_afk: hiredman: that 500 vs 0 mb.. just in profilers.. the speed is more some benchmarks

14:26 the profiling though for mono was more ran .NET (not really mono)

14:26 but the memory consumption ti start the app framework in jjava is 6GB and in Mono onlly 1.5 mb

14:27 raek_: I had installed jetty with apt-get, and the other version was included with compojure

14:27 dmiles_afk: but thats of course our fault the java is that big.. the methoogy can be changed slightly

14:27 hiredman: I would be surprised if under load the memory usage was that different, but the jvm tends to hang on to unused memory (incase it needs it again)

14:27 raek_: but when I removed jetty from my system and used the jar supplied by compojure, everytihng worked

14:28 dmiles_afk: hiredman: difference is ValueTypes vs Objects representing Data

14:28 raek: so I guess that you have duplicate jars somewhere, cypher23

14:28 cypher23: raek, k. I'll search for that

14:28 raek: if your problem is the same as mine, that is

14:29 dmiles_afk: in mono we get to not have to use objects.. unstead .. byvalue structs

14:29 instead .. byvalue structs

14:29 hiredman: makes sense I guess

14:29 if only ram were dirt cheap...

14:29 dmiles_afk: in java every float/integer has to be an object

14:30 in clr.. they are just a byvalue thing

14:30 hiredman: still an object, just an object on the stack instead of the heap?

14:31 dmiles_afk: yeah.. they are not on heap.. but ctually they are TAGGED type

14:31 like a Union

14:31 some union values denote objects

14:31 some numbers

14:32 notallama: the jvm decides it it should allocate on the stack or heap, right? or does it always go for heap?

14:32 dmiles_afk: right JVM has locally stacked up objects

14:32 they might end up on heap if the program make them

14:33 our app startup makes a in memory table of 4 million rows times 10 columns.. bwe foree you even get a REPLK

14:33 hiredman: I could wrong but I am pretty sure the jvm allocates on the heap

14:34 dmiles_afk: our app startup makes a in memory table of 4 million rows times 10 columns.. beforee you even get a REPL

14:34 hiredman: at least hotspot

14:34 I think jrockit does some kind of escape analysis to allocate on the stack

14:35 dmiles_afk: yeah jrocket find places to keep them off the heap

14:35 hiredman: the same place I heard that jrockit does that I also heard it doesn't make a big difference

14:35 dmiles_afk: where the sun thing might make them pass thru gen0

14:36 yeah surprisingly just the standard sun jvm still kicks their butts

14:36 or less than 0.1% differnce

14:36 hiredman: ♥ hotspot

14:37 dmiles_afk: i cant say for sure.. i think java is finalyl doing it right.. where .. mono/.NET has huge room for imporvemnt

14:37 but once they catch up (4 more years?) jvM will be wishing for ValueTypes

14:37 hiredman: the jvm has been around a lot longer

14:38 dmiles_afk: jvm has built in ValueTypes int,int[],float,float[],Object, etc

14:39 but .NET lets users define more

14:39 notallama: i'm cooking up a toy vm/language of my own right now. i somehow doubt it will be as nice as hotspot, though

14:40 jmork: hello, I have a very basic enclojure question and haven't had much luck from their google group or #enclojure so I figured I'd ask here since someone may know. Should my clojure program stop on a line breakpoint set within the clojure source if I run it in debug mode?

14:42 dmiles_afk: notallama: include stucts and ValueTypes and unions ;)

14:43 *structs

14:45 chouser: unions? really?

14:46 dmiles_afk: well so people can use {int mytype, ...somepadding...}

14:46 or whatnot

14:46 hiredman: :(

14:46 padding? really?

14:47 dmiles_afk: yeah not the best design.. but at least the user has the rope

14:47 hiredman: unless you calling out to C all the time...

14:47 milep: how can I have a sorted map by values? (keys are structs and values integers and all integer are not unique)?

14:47 hiredman: defining interfaces based on the size of structures in memory :(

14:48 dmiles_afk: i know bad actually that is why the java version of the app framework runs 40% faster than the C version

14:48 the C versio is always tearing down its local allocations

14:49 notallama: my vm will be pretty crude in that sense. structs and pointers. no unions.

14:49 dmiles_afk: (the app framework i refered to earlier)

14:49 hiredman: I cannot see why you would to "pad" a datastructure in java

14:49 dmiles_afk: right the C version does.. not the java verion

14:49 the java version cant :)

14:49 hiredman: I know, but even if you could, what would be the point?

14:50 my brain hurts just trying to reason out how that would work and why you would want it

14:50 dmiles_afk: in C, evryone hoped the C compiler could do really smart things .. so they "just got used"

14:51 the C version was written by john mccarthy 30 years ago

14:51 notallama: c is fun stuff.

14:51 except the infix.

14:51 dmiles_afk: i think when he worked for Cycorp.. that was all that was available

14:51 hiredman: C will eat your children

14:52 Chousuke: hiredman: you need to have the binary interface at some level. :P

14:52 hiredman: sure

14:52 notallama: that's what i want. a non-garbage collected lisp that has 3 data types: chars, ints, and pointers

14:53 hiredman: Chousuke: cinc paired with llvm

14:53 Chousuke: are chars going to be 8 bits? if so, call them bytes ;P

14:53 hiredman: notallama: that is crazy

14:53 dmiles_afk: in the last 9 years people been slowing porting it to run in java instead... but the differnce is the java memory footprint for Objects is indeed much much larger than the "C unions"

14:53 hiredman: lisp has always had gc

14:54 gc was one of the reasons some people (in antiquity) called java an acceptable list

14:54 lisp

14:55 although something as direct as C with a nicer syntax might be nice

14:55 notallama: yeah, but gc doesn't play nice with pointers. given the choice, gc is probably the sane one, but i like pointers.

14:55 pixelman: is there work on getting better error messages in clojure?

14:57 hiredman: notallama: I have an idea

14:57 notallama: oh?

14:58 hiredman: do it as a concatenative language

14:58 instead of a lisp

15:00 notallama: probably a good idea. it doesn't need parens around everything if functions have fixed arity.

15:00 ambient: functional lisp is kinda concatenative

15:00 because it can be transformed into postfix notation :p

15:01 hiredman: concatenative languages seem to be more explicit about the stack, which seems like it would mix well with low level stuff where you care about the stack

15:03 * hiredman smells a project

15:05 cypher23: raek, turns out I had also included some jars from processing, which collided with the penumbra jars. Removing those from the classpath made the error go away

15:05 thanks for your help

15:14 milep: is there any helper functions to sort map by values?

15:16 johnmn31: maybe sort-by. I'll have to look.

15:19 if you're using keywords, no

15:19 (sort-by #(< 1 (key %)) {:a 1 :b 2})

15:19 java.lang.RuntimeException: java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to java.lang.Number

15:20 but if you're using comparable items as keys:

15:20 (sort-by #(< 1 (key %)) {2 :a 1 :b})

15:20 ([1 :b] [2 :a])

15:20 hiredman: johnmn31: that is not a sorted map

15:20 milep: ok, thanks, sort-by might do it, I have structs as keys and integer values

15:21 johnmn31: or you you could do:

15:21 (sort-by #(< 1 (val %)) {:a 1 :b 2})

15:21 ([:a 1] [:b 2])

15:21 hiredman:

15:21 johnmn31: hiredman: what do you mean?

15:21 hiredman: johnmn31: that is not a sorted map

15:22 you are taking a map and returning a sequence

15:22 johnmn31: oh, of course.

15:22 maps have no order

15:22 is there a sorted-map in clojure?

15:23 hiredman: yes

15:23 ,(doc sorted-map)

15:23 clojurebot: "([& keyvals]); keyval => key val Returns a new sorted map with supplied mappings."

15:23 johnmn31: indeed there is

15:24 and as long as the object implements comparable?

15:25 is there a way to do something like a seq on an array?

15:25 Chousuke: just call seq on it

15:26 ,(seq (int-array 1 2 3))

15:26 clojurebot: java.lang.IllegalArgumentException: Wrong number of args passed to: core$int-array

15:26 Chousuke: hm

15:26 well, anyway

15:28 johnmn31: ,(int-array 1 2 3)

15:28 clojurebot: java.lang.IllegalArgumentException: Wrong number of args passed to: core$int-array

15:28 johnmn31: ,(int-array [1 2 3)

15:28 clojurebot: Unmatched delimiter: )

15:28 johnmn31: ,(int-array [1 2 3)

15:28 clojurebot: Unmatched delimiter: )

15:28 johnmn31: ,(int-array [1 2 3])

15:28 clojurebot: #<int[] [I@10cdec1>

15:28 johnmn31: butter fingers

15:28 ,(seq (int-array [1 2 3]))

15:28 clojurebot: (1 2 3)

15:28 johnmn31: hmm

15:29 danlei: anyone else having problems with completion in latest slime (using swank.swank/start-server, installed without clojure-install)?

15:29 * danlei hates that clojure-install stuff

15:31 milep: hmm, is there somewhere example how to use sorted-map-by?

15:32 danlei: I used to just run ant after git pull and everything worked, but since the past few days everything seems to have changed. used maven now to get my swank.clojure.jar, but completion refuses to work.

15:34 johnmn31: ,(sorted-map-by #(< %1 %2) 1 2 3 4 5 6 7 8)

15:34 clojurebot: {1 2, 3 4, 5 6, 7 8}

15:34 johnmn31: ,(sorted-map-by #(> %1 %2) 1 2 3 4 5 6 7 8)

15:34 clojurebot: {7 8, 5 6, 3 4, 1 2}

15:35 danlei: ,(sorted-map-by > 1 2 3 4 5 6 7 8)

15:35 clojurebot: {7 8, 5 6, 3 4, 1 2}

15:36 johnmn31: ,true

15:36 clojurebot: true

15:36 milep: so the sorted-map-by comparator gets keys as arguments?

15:38 johnmn31: milep: I think it sends both the key and the val to the function

15:39 sends both the key and val to the comparator, that is.. I'm not sure though

15:39 milep: ,(sorted-map-by #(compare %1 %2) :c 1 :a 3 :b 2 :d 2)

15:39 clojurebot: {:a 3, :b 2, :c 1, :d 2}

15:40 milep: that got only keys?

15:40 danlei: (sorted-map-by compare :c 1 :a 3 :b 2 :d 2), no need for wrapping

15:41 johnmn31: I guess so

15:41 milep: but if I want to compare values?

15:46 johnmn31: hmm. I remember once seen a trick to reverse the keys with the vals in a map, but I don't remember how it's doene

15:47 milep: johnmn31: that doesn't help, because I lose values if they are equal

15:47 johnmn31: true

15:47 milep: tried that allready :)

15:48 johnmn31: (well, if you didn't mind ending up with vectors...

15:48 ,(sort-by #(< 1 (val %)) {:a 1 :b 2})

15:48 clojurebot: ([:a 1] [:b 2])

15:49 milep: can I make a map from that?

15:50 I don't mind if it is temporaly list of vectors

15:51 johnmn31: should be able to

15:52 milep: I think so also, but haven't found the syntax yet

15:54 danlei: (into {} (sort-by #(< 1 (val %)) {:a 1 :b 2}))

15:55 but that would loose order again :)

15:56 milep: danlei: thanks, it doesn't matter I need the order only temporaly

15:58 but the sorted-map would be better...

16:00 Chousuke: there's a sorted-map-by

16:01 milep: Chousuke: yes, but I didn't figure out how to use it to sort by values

16:02 johnmn31: should be a way to feed a vector of [:a 1] into hash-map

16:02 I was thinking desctructuring, but I don't really know how to use it

16:02 Chousuke: there is :p

16:02 (into {} [[:a 1] [:b 2]])

16:02 danlei: ugliest in town: (apply sorted-map (mapcat identity (sort-by #(< 1 (val %)) {:a 2 :b 1}))) :)

16:02 Chousuke: ,(into {} [[:a 1] [:b 2]])

16:02 clojurebot: {:a 1, :b 2}

16:03 raek: ,(conj {} [:a 1])

16:03 clojurebot: {:a 1}

16:03 Chousuke: ,(into (sorted-map) [[:r 1] [:b 2]])

16:03 clojurebot: {:b 2, :r 1}

16:03 danlei: Chousuke: :)

16:08 johnmn31: oh. so:

16:08 ,(into {} (sort-by #(< 1 (val %)) {:a 1 :b 2}))

16:08 clojurebot: {:a 1, :b 2}

16:09 danlei: (into {} (sort-by #(> 1 (val %)) {:a 1 :b 2})) ≡ (into {} (sort-by #(< 1 (val %)) {:a 1 :b 2}))

16:11 johnmn31: ,(let [a (sort-by #(< 1 (val %)) {:a 1 :b 2 :c 5 :d 0})] (pr a) (into {} a))

16:11 clojurebot: {:a 1, :d 0, :b 2, :c 5}

16:11 ([:a 1] [:d 0] [:b 2] [:c 5])

16:12 * danlei thinks . o O (funny how my brain refused to deduce (into (sorted-map) ...) from (into {} ...) )

16:12 johnmn31: hmm, 1 is not less than zero, though

16:13 ,(sort-by #(< 1 (val %)) {:a 1 :b 2 :c 5 :d 0})

16:13 clojurebot: ([:a 1] [:d 0] [:b 2] [:c 5])

16:13 johnmn31: ?

16:13 oh, I'm sorting by 1

16:14 danlei: oh :)

16:14 milep: ,(sort-by #(val %) {:c 1 :a 3 :b 2 :d 2})

16:14 clojurebot: ([:c 1] [:b 2] [:d 2] [:a 3])

16:14 Chousuke: #(val %) = val :P

16:15 johnmn31: Chousuke keeps trying to tell us

16:16 ,(let [a (sort-by val {:a 1 :b 9 :d 0})] (pr a) (into {} a))

16:16 clojurebot: {:d 0, :a 1, :b 9}

16:16 ([:d 0] [:a 1] [:b 9])

16:16 johnmn31: there we go

16:17 * danlei wants his completion back

16:18 Chousuke: johnmn31: do not trust that result

16:18 johnmn31: maps do not maintain order except by accident :)

16:18 johnmn31: oh I know, that's why I spit out a

16:19 the ordered data, for use

16:20 that map being ordered wasn't my intention

16:22 milep: Is there a way to access values in sorted-map-by comparator?

16:23 ,(sorted-map-by #(compare (val %1) (val %2)) :c 1 :a 3 :b 2 :d 2)

16:23 clojurebot: java.lang.RuntimeException: java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to java.util.Map$Entry

16:25 Guest92834: forgot the {}

16:25 ?

16:25 Chousuke: it only has access to the key, for obvious reasons :P

16:26 milep: so, it's not going to be easy to have sorted map by values

16:26 danlei: (sort '((a 1) (b 2) (c 3) (f 0)) #'< :key #'cadr) :P

16:26 * danlei couldn't resist

16:27 Chousuke: that's not a map :P

16:27 johnmn31: true, you might want to use a different datastructure

16:27 hiredman: keep two maps

16:28 one the inverse of the other

16:28 danlei: well, i'd call it the poor-cl-mans map :p

16:28 milep: hiredman: won't I lose some values if they are identical?

16:29 hiredman: yes

16:29 johnmn31: you could use a set of key-val pairs

16:30 Chousuke: and you wouldn't be able to look up by key then /:

16:30 danlei: just use a good old alist

16:33 hiredman: http://www.dreamsongs.com/Files/HOPL2-Uncut.pdf "The Evolution of Lisp" is pretty neat, if anyone hasn't seen it

16:35 danlei: also of (not only) historical interest: http://tinyurl.com/ye3tlko

16:52 * danlei got himself another coffee and heads back to reading LiSP

17:00 MarkVolkmann: Technically speaking, is a Var considered to be one of the "reference types"?

17:01 Chousuke: MarkVolkmann: yes.

17:14 raek: wow. prxml is really neat.

17:15 i've always wanted to generate xml and html in a lispy way

17:16 (prxml [:element {:attribute "value"} "content" [:subelement "sub"] "more text"])

17:17 prints: <element attribute="value">content<subelement>sub</subelement>more text</element>

17:19 btw, has anyone made a version of clojure.contrib.xml/parse that handles xml namespaces?

17:20 i've seen some ideas in the mail archive, but have anyone implemented this?

17:20 hiredman: ,(doc clojure.xml/parse)

17:20 clojurebot: "([s] [s startparse]); Parses and loads the source s, which can be a File, InputStream or String naming a URI. Returns a tree of the xml/element struct-map, which has the keys :tag, :attrs, and :content. and accessor fns tag, attrs, and content. Other parsers can be supplied by passing startparse, a fn taking a source and a ContentHandler and returning a parser"

17:20 raek: cause I'm thinking about doing it myself

17:21 hiredman: seems like that is something to be taken care of with the startparse bit

17:21 huh

17:21 maybe not

17:22 raek: i was thinking about a funktion that just takes the output from xml/parse, looks for xmlns attributes, and "updates" tag and attribute names

17:23 that is, returning a new xml tree

17:24 hiredman: tree map

17:25 I wonder why clojure.zip doesn't define a map

17:25 clojurebot: transform?

17:25 clojurebot: transform is http://github.com/hiredman/odds-and-ends/blob/8a84e6ddbad9d71f714ba16c3e1239633228a7eb/functional.clj

17:26 hiredman: transform is basically a map over a zipper

17:26 raek: {:tag :html :attribs {:xmlns "http://www.w3.org/1999/xhtml"}} => {:tag #^{:namespace "http://www.w3.org/1999/xhtml"} :html}

17:26 or something similar

17:26 hiredman: heck

17:27 raek: to have maps that share structure is really awesome

17:28 especially if you have to keep track of an environment with some sort of bindings when traversing data structures

17:28 like xml namespace prefixes

18:04 ztellman: what's the proper way to reference an internal class?

18:04 A$B ?

18:09 danlei: ztellman: yes

18:09 zaphar_ps: out of curiosity are there any clojure http-server libraries?

18:10 danlei: ah, finally I got my completion back

18:10 ztellman: danlei: it looks like you have to give the full classpath to have the inner class notation work

18:10 is that true, or am I just doing it wrong

18:12 danlei: ztellman: no, you don't have to. for example: (DefaultEditorKit$CopyAction.)

18:12 ztellman: danlei: well, this is for an enum rather than a class

18:12 maybe that makes a difference, I dunno

18:12 danlei: hm

18:12 I'm not sure

18:12 ztellman: it's not a big deal

18:12 danlei: but I don't think that makes a difference

18:14 I had to import them like this though: (javax.swing.text DefaultEditorKit$CopyAction DefaultEditorKit$PasteAction DefaultEditorKit$CutAction), maybe that helps

18:15 ztellman: danlei: I'll try that, thanks

18:53 poet: what's the usual turn around time for a new post on the clojure mailing list being approved ?

19:09 somnium: is there a standard java/clojure way to get all subdirs of a dir?

20:10 aja: What is the clojure idiom for a simple for loop? As in: For the values 1 to 20, I want ot call function foo with that value as the argument?

20:11 somnium: ,(for [x (range 20)] (* x x))

20:11 clojurebot: (0 1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361)

20:11 aja: somnium: Heh. Thanks. Once again, I bounce off the bloody square brackets.

20:12 somnium: youll get used to 'em

20:12 aja: somnium: I used to be annoyed by lisp newbs who complained about all the brackets -- I now have new empathy./

20:13 somnium: they make binding expressions more readable than common-lisp, imo

20:14 aja: somnium: Yeah -- I seee the point. I just have to re-train the part of my brain that was devoted to parsing that stuff.

20:16 somnium: Seems to work a charm. Thanks.

20:16 (Note to self: When in doubt, consider that the things that might be lets should be inside [])

20:53 danlei: shomehow I never got used to all the square brackets and curly braces. i still don't like them that much. they also don't help making anything more readable for me (that's what indentation is about imho), but rather distract ... but as long as that is the only thing I complain about, clojure remains one of my top five languages.e

20:54 somnium: you really prefer (hash-map :a :b :c :d) to {:a :b :c :d} ?

20:54 danlei: I didn't say it wasn't convenient

20:54 I still dont like the look

20:54 so, optically, yes i prefere the latter

20:54 somnium: or (let (a (hash-map :a :b :c :d)) ...

20:54 danlei: but still use the former

20:55 *prefer

20:55 i don't even mind the additional parens in the other lisp

20:55 somnium: I'm trying to think of an example using destructuring without brackets, but there's no way Ill get the parens right

20:55 danlei: that was never something I minded

20:55 well, in CL there's destructuring bind, but it's less general

20:56 somnium: for me its not the parens, its the lack of visual cues to distinguish types of expressions

20:56 danlei: anyway, I wasn't complaining about the language, it's just a more or less aesthetic thing. taste, if you will.

20:57 somnium: ,(for [{x [_ y]} {:a [1 2] :b [3 4]}] [x y])

20:57 clojurebot: java.lang.Exception: Unable to resolve symbol: _ in this context

20:58 danlei: I hate those visual cues somehow

20:58 somnium: :)

20:58 danlei: i like the ... hm

20:58 the "harmony" of just symbols and round parens

20:58 somnium: ok, but I don't know how I could write that and understand it without the reader macros

20:58 danlei: well, in the other lisps that is not much of a problem

20:59 since the usual destructuring (as in CL) just operates on lists

20:59 somnium: ,(for [{x [z y]} {:a [1 2] :b [3 4]}] [x y])

20:59 clojurebot: java.lang.Exception: Unable to resolve symbol: z in this context

20:59 danlei: there are libs though which manage that without reader macros

20:59 I just don't use them

20:59 for example cl-unification

21:00 it's actually more ...

21:00 but again: no complaints, it's purely subjective, I know

21:00 somnium: well, I never did anything substantial with a lisp before clojure, so I guess I don't haven anything to compare it to

21:01 but it has most of the literal sugar I'm used to from languages like python or ruby

21:01 danlei: and it really is convenient (and a very nice language in general)

21:02 I always felt that the sequence abstraction in CL should be more general

21:02 along came clojure ... :)

21:09 somnium: ,(apply merge (for [[x [y z]] {:a [1 2] :b [3 4]}] {x (+ y z)}))

21:09 clojurebot: {:b 7, :a 3}

21:09 somnium: I guess it is kind of noisy, what is equivalent with destructuring bind?

21:11 danlei: as I said, there is no real equivalent, since dest-bind operates on lists

21:11 you'd have to use something like metabang-bind or cl-unification, which I don't do usually. You'd just bind with lets.

21:12 somnium: metabang-bind is a nice name for a function

21:12 danlei: :)

21:15 also, when playing around or prototyping, you'd often use alists or plist, which could be destructured with destructuring-bind. of course there is a penalty for doing everything with lists, and the drawback is that when you want to optimize later and use hast-hables vectors &c, the code gets more ugly

21:18 then again ... I still find let-binding easier to read sometimes. depends ...

21:21 somnium: I think I like least calling java from clojure code, despite the power it gives. I always have a desire to wrap any java interaction in a clojure function to get the . .. dotos out of the code

21:22 danlei: me to :)

21:23 chouser: somnium: how long have you been using Clojure?

21:23 somnium: not long :)

21:23 maybe 5 months since I discovered it?

21:23 chouser: you're in a well known stage.

21:23 :-)

21:24 1. "oh! Java!?" 2. "Eww! Java!" 3. "Ah... Java..."

21:25 danlei: is apparently in a stage all his own. :-)

21:25 somnium: I used jruby before, but that is really grafted onto java, contorts java into its own syntax

21:26 maybe I'm just wanting to recreate that experience :)

21:27 ,(doc atom)

21:27 clojurebot: "([x] [x & options]); Creates and returns an Atom with an initial value of x and zero or more options (in any order): :meta metadata-map :validator validate-fn If metadata-map is supplied, it will be come the metadata on the atom. validate-fn must be nil or a side-effect-free fn of one argument, which will be passed the intended new state on any state change. If the new state is unacceptable, the validate-fn should return

21:28 somnium: if you have some mutable java thing in an atom that you can only alter with a side-effect causing method, what's the correct procedure?

21:32 chouser: bleh. probably not much point in putting it in an atom if it mutates on its own.

21:32 If you're willing to make a full copy each time you change it, you could do that -- pretend it's an immutable value.

21:33 somnium: hmm, was thinking of opening/closing sockets on a server

21:33 chouser: yeah, I don't know how to handle that. I've done it, but I'm not sure I did it right.

21:34 the statefulness of that socket tended to leak out into the rest of my program -- hard to keep it contained.

21:34 somnium: perhaps cinc will lead to a functional server

21:35 chouser: you could put it in an agent instead, and only operate it on it by sending functions to the agent

21:35 this would serialize access to the socket

21:36 danlei: chouser: well, my state is, that (loop for (k v) on '(:a (1 2) :b (3 4)) by #'cddr append (list k (apply #'+ v))) is not "worse" than (apply merge (for [[x [y z]] {:a [1 2] :b [3 4]}] {x (+ y z)})) (not 100% equivalent), but different. I kinda like both, both have pros & cons. about java: I like the well tested libs and that there are so many of them and I like the ease of clojure interop, but I would welcome a few more wrappers, and

21:36 end up wrapping relatively often. again, that's just taste.

21:36 somnium: when to use send vs. send-off?

21:41 chouser: somnium: if your function is CPU bound, use send. If it blocks on anything else, IO for example, use send-off.

21:42 danlei: I did learn CL, but it never "stuck" for me. libraries were a big issue, but so was the difficulty I had reading CL code.

21:44 I was surprised at how much easier Clojure seemed for me to read, but I think not that it may be mostly because if you see (foo a) in Clojure, an overwhelming majority of the time it's calling something named foo with arg a.

21:44 In CL, it might be that, or it might be a variable binding of some sort, or an expression in a cond form, or who knows what.

21:45 and if you're reading inside-out as is often required, that means you have to read further "ahead" to an outer form to even know vaguely what's going on.

21:46 In Clojure, the [foo a] clearly says it's not a function call. It leads to fewer dead-ends while trying to read a block of code.

21:46 slashus2: oo I just learned about transients.

21:46 chouser: All that said, though, of course it's a matter of taste, as you said.

21:49 danlei: chouser: I follow you, and as far as the libraries are concerned: pretty hard to beat java, there we agree. about the visual thing: I just don't have that problem in "traditional" lisps, so clojure here doesn't solve a problem for me. (but still I value the more general seq abstraction, compared to CLs "sequences", and it sure is convenient)

21:49 * chouser nods

21:54 slashus2: chouser: I have read a little bit about newnew. Is the clojure in clojure effort and newnew coming along pretty well?

22:06 sproingie: i think my problem with CL is mostly IDENTIFIERS-THAT-LOOK-LIKE-COBOL-TO-DO-BASIC-THINGS

22:07 danlei: well, I prefer it to id/l->cob :)

22:08 sproingie: there's a happy medium

22:08 danlei: and since you use java in clojure more or less daily, you often have a similar effect, lest you wrap

22:08 s/lest/unless

22:09 but yes, there are a few long identifiers, sure

22:09 sproingie: macros help

22:09 * danlei nods

22:09 danlei: on the other hand, I prefer list to l for list variables

22:10 sproingie: i special-case that one and use L

22:10 danlei: which starts another flame: lisp-1 vs lisp-2 ;9

22:10 sproingie: i like lisp-1

22:10 <3 scheme

22:10 danlei: I like both, I always miss something, no matter which one I am using

22:10 sproingie: my other lisp is elisp which is also a lisp-1

22:11 * arbscht shrugs... when in Rome, etc

22:11 danlei: here the freedom of identifier choice, there the ease of dealing with 1st class funs

22:11 arbscht: none of these things bother me in either CL or Clojure

22:11 danlei: elisp?

22:11 sproingie: emacs lisp

22:11 danlei: (setq foo (lambda () 'hallo))

22:11 (foo)

22:11 try it

22:12 sproingie: hm. except i'm always throwing around functions without #'

22:12 oh nevermind those aren't functions

22:12 been a while since i last hacked elisp :p

22:12 danlei: np

22:13 arbscht: well, I miss the freedom in variable naming more than lisp-1 ness. I guess I tend towards lisp-2

22:14 sproingie: static scope tends to make accidental shadowing less an issoe

22:14 clojurebot: scope is at http://paste.lisp.org/display/73838

22:14 sproingie: issue

22:14 macros have hygeine problems either way

22:16 danlei: I don't even see why it should be impossible to allow (setq foo (lambda () 'blah)) (foo) -> blah

22:16 (in a lisp-2)

22:21 sproingie: because you're setting the value slot

22:21 danlei: doesn't work because it doesn't work? :)

22:22 sproingie: because the spec only looks at the function slot when it sees (foo)

22:22 danlei: sure, but why can't the first symbol in a list be evaluated and if it evaluates to a function, call it. like ((lambda () ...) ...) works too

22:22 yes, I know the way it is

22:22 sproingie: falling back to the value slot might be interesting but probably infeasable

22:22 danlei: I just don't understand the reason

22:23 probably

22:23 but I'm not sure why it would be

22:24 sproingie: consistency i guess. don't have to introspect values for callables

22:24 danlei: of corse it would just be for convenience ...

22:24 maybe performance issues ... dunno

22:24 sproingie: if you look into values you pretty much have a lisp-1

22:24 danlei: well, yes

22:24 sproingie: lisp-1 with some dual nature to be sure

22:25 danlei: the "default" for funs would be the symbol-function, but symbol-value would work for convenience

22:26 probably there is an obvious reason why it is like it is and I just don't know enough about the subject

22:26 sproingie: traditiooooooon ... tradition!

22:27 danlei: :)

22:31 but I remember some people arguing that they actually liked funcall, for similar reasons chouser likes [] for data vs () for code. they like to "see" that something "different" happens

22:32 so maybe yes, tradition, culture, taste. like often.

22:44 somnium: what is the preferred way to set *config* vars when using libraries? presumably not (do (in-ns foo) (def *config* bar))

23:06 hiredman: " About this time, the Scheme community

23:07 starts denying that Scheme is a dialect of Lisp, claiming closer bonds to Algol.

23:07 "

23:07 brilliant, pure gold

23:07 chouser: somnium: wouldn't work anyway.

23:07 you can use 'binding' for thread-local setting, or perhaps alter-var-root

23:14 hiredman: what's that from?

23:15 hiredman: the evolution of lisp

23:16 somnium: chouser: it seemed to work (do (in-ns 'foo) (def *bar* baz) (in-ns 'old-namespace))

23:26 chouser: somnium: hm, indeed.

23:57 rongenre: Hi .. looking for a decent example a defn with optional keyword arguments

23:57 arbscht: defn doesn't take keyword arguments

23:58 rongenre: I meant creating a function with optional keyword args

23:58 arbscht: functions don't, either :)

23:59 you can pretend they do by applying hash-map to the args, I guess

23:59 rongenre: Really. So I need to do the &rest thing and do a hash-map yeah

23:59 Ok, just trying to be idiomatic

23:59 arbscht: ,((fn [& args] (apply hash-map args)) :a 1 :b 2)

23:59 clojurebot: {:a 1, :b 2}

23:59 rongenre: awesome. Thanks!

Logging service provided by n01se.net