#clojure logs

2009-10-04

00:15lisppaste8steiger pasted "Can someone explain to me this behavior?" at http://paste.lisp.org/display/88140
00:23steigerseems like a bug to me
00:26hiredmanwhat does dist-map say now?
00:28steigertest> dist-map
00:28steiger#<Ref@7673a2: {}>
00:28steigerif I remove the last exp, (prn @dist-map), the function works as expected
00:29hiredmananyway
00:30hiredmanit works here on 1.0 and a snap shot of git master
00:31hiredmanI'd restart your repl and try again
00:31steigeri'm running clojure-box and it doesn't work here. (clojure-version) shows "1.0.0-"
00:31steigeri guess i'll update
00:32hiredmanI tried it on 1.0.0- (the download from clojure.org) it worked like expected
00:33hiredmanif you haven't yet, restart the repl and try from scratch
00:34konrWhere can I find clojure examples of java interoperability, particularly, uses of the proxy macro?
00:36steigerhiredman did it. still not working. this is very weird
00:36hiredmanhttp://delicious.com/clojurebot/pastbin
00:37hiredmanI'm tempted to just blame emacs (being a vim guy)
00:40briancarpersteiger: map is lazy, so I think the guts of initialize-dist-map are never evaluated in your second version of init.
00:41briancarperTry using dorun or doseq.
00:42steigerbriancarper hmm.. makes sence
00:42steiger*sense
00:43steigerbriancarper worked :) thanks
00:43steigerhiredman thankyou also
00:45hiredmanah
00:45hiredmanI wasn't reseting dist-map between runs
00:45hiredmanno wonder
01:38mikemThe 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.
01:39mikemhas anyone encountered this before?
03:00adityo(import '(java.math sqrt))
03:00adityowhat am i doing wrong?
03:00slashus2adityo: You can do just (Math/sqrt 5)
03:01adityoslashus2: okie so i dont need to import it?
03:01slashus2no
03:01slashus2That is correct.
03:02adityookie thanks
03:03slashus2You are very welcome.
03:07hiredmanthere is no java.math, iirc
03:07hiredmanit is java.lang.Math
03:07hiredmanand Math is not a namespace, it is a utility class
03:08hiredmanwhich means it is a class with a lot of static methods
03:08adityoallright..much clearer now
03:12hoeck1hiredman: there is a java.math package, it houses the BigDecimal and BigInteger classes
03:15hiredmanhoeck1: pardon me
03:47konrHow can I turn `e.getActionCommand( ).equals("Metal")` into clojure? (.. e getActionCommand equals "Metal")?
03:53hoeck1konr: or (-> e .getActionCommand (.equals "Metal))
03:54hoeck1konr: or (= "Metal" (.getActionCommand e))
03:57konrhoeck1: thanks!
04:01hoeck1konr: the dotted-methodname syntax is preferred these days, and (. ) is only used in macros expanding to method calls
04:10milepcan I assign multiple variables like in Ruby x, y = [1, 2]?
04:11slashus2,(let [[a b] [1 2]] [b a])
04:11clojurebot[2 1]
04:12milepok, thanks
05:03konrShould a (println "foo") print "foo" on the repl everytime it is evaluated, or the output can be redirected somewhere?
05:11LauJensenkonr the output can be redirected, and in slime/emacs this sometimes happends without you asking for it, ie when using threads :)
05:11LauJensen,(with-out-str (println "hi there"))
05:11clojurebot"hi there\n"
05:18konrLauJensen: haha, I knew! Thanks!
05:53namorHmm, I found this fibonacci example from wikibooks, but I get the error message: Unable to resolve symbol: lazy-cons in this context
05:53namorWhere did lazy-cons go?
05:56hoeck1namor: it has been replaced by lazy-seq some time ago
05:57hoeck1namor: lazy-cons was too eager, it always computed the first value of the lazy seq
05:59namorI see. But I don't understand lazy-seq from just reading the api docs.. Lazy-cons was somewhat obvious if you come from lisp.
06:00namorHow would you recursively build a list with lazy-seq?
06:03lisppaste8hoeck pasted "lazy-seq fib" at http://paste.lisp.org/display/88148
06:03hoeck1namor: like ^
06:04namorThanks!
06:04hoeck1namor: so you basically wrap your list building code with lazy-seq
06:21angermancan I ask clojure for a list of all files in ./**/*.wav?
06:28yasonangerman: use file-seq and filter what you need from there
06:39konrI'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?
06:47konrIs Java's System.exit(0) the same as ((. System exit) "0"))?
06:49Chousukeno
06:49Chousukeit's (. System (exit 0))
06:49Chousukeor, better: (System/exit 0)
06:50Chousuke. is a "low-level" operator and it's usually better to instead use the sugary forms provided. :)
06:52Chousukeie. (.method obj args...) for methods and instance fields and (Class/staticMethod args...) for static methods or fields
06:52Chousuke,Math/PI ; no parens needed for static fields, either
06:52clojurebot3.141592653589793
07:00konrChousuke: hmm, so in the case of System.err.println("foo"), I can use (System/err/println "foo")?
07:00Chousukekonr: no, that's different.
07:00Chousukeerr is an object
07:01Chousukeso (.println System/err "foo")
07:03Chousukeor (binding [*out* *err*] (println "foo")) :P
07:08konrinteresting! Can I bind *out* to a file?
07:09konr(handle)
07:10Chousukeany Writer object
07:10Chousuke(doc with-out-str)
07:10clojurebot"([& body]); Evaluates exprs in a context in which *out* is bound to a fresh StringWriter. Returns the string created by any nested printing calls."
07:11Chousukeyou could make a similar macro, but for a file :)
07:47cypher23hello all, I put my clojure startup script online, maybe someone will find this useful: http://blog.nuclearsquid.com/writings/clj-startup-script
08:57angermandid anyone write a sould play wrapper for clojrue?
09:22LauJensenIn 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) ?
09:24hoeck1LauJensen: by accident?
09:25LauJensenIts a bug?
09:25angermanhow would I do something like reading from one stream and writing to another with clojure?
09:25angermanwith java one would usually take some byte buffer, and loop until all is thogh
09:25hoeck1LauJensen: no, you just shouldn't do it this way, its not expected to work
09:26LauJensenso now that we can see that it does - that must constitute a bug, or a least unintended behaviour
09:27hoeck1LauJensen: of course, we could ad numerous modifiers to the language to forbid certain uses of things
09:29hoeck1LauJensen: 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
09:29LauJensenOk - I don't see it that way
09:30yasonangerman: check out clojure.contrib.duck-streams, there's (copy ...) for that
09:38danleiI see that swank-clojure's build.xml is gone. how would I just build swank-clojure.jar without using that clojure-install stuff now?
09:54angermanyason: thanks :)
09:54angermanhow do i instantiate a static class?
09:54angermanthis one: http://java.sun.com/j2se/1.4.2/docs/api/javax/sound/sampled/DataLine.Info.html
10:01dliebkeangerman: (javax.sound.sampled.DataLine$Info. lineClass format)
10:06angermandliebke: ohh thanks.
10:06angermanforgot about the $ notation
10:07angermanhmm, how can I call a multimethod straight?
10:07angermanI want to use copy.
10:07angermanbut copy is a multimethod that switches on the types of the classes
10:08angermanbut I know I want to call (defmethod copy [InputStream OutputStream] ...
10:09dliebkehmm, that's a good question. I don't know if you can call a multimethod directly (like you can in R)
10:10angermanhmm. well. looks like I'm gonna copy'n'paste :)
10:10angermanit'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:11blitz_how do I use clojure-contrib from within slime? it seems I have to add it to the classpath. but how?
10:12angermanblitz_: doing that post-init is not really possible i think.
10:12angermanyou have to tweak your init paths
10:12danleiblitz_: add-classpath from the repl ("post-init") or swank-clojure-extra-classpaths in your .emacs
10:12angermandanlei: does that add-classpath really work?
10:12blitz_thx
10:12danleiyes, it works
10:13angermandanlei: hmm... i must have made something wrong then
10:13danleiit's considered bad style for anything but playing around though
10:13blitz_danlei: it is already in my classpath... strange
10:13danleiuse it like this (add-classpath "file:///c:/.../my.jar")
10:15danleiit's in your classpath and doesn't work?
10:15blitz_danlei: sorry. it works. don't know what I did wrong
10:15danleiok
10:16angermanhttp://gist.github.com/201412
10:16angermanwhee :)
10:17angermanfinally
10:17angermannow I just need to figure out how to work with unicode filenames :(
10:17angermanuser> (.getName file-obj);; => "?.wav"
11:02angermanhow can I make clojure handle japanese characters in the repl?
11:05raek_angerman: where are you using the REPL? in a terminal? emacs?
11:06angermanemacs
11:06angermani though it should support unicode
11:06angermanso the int value of the charater is 12354
11:06angermanbeing the unicode codepoint for あ
11:07raek_I have no problem using UTF-8 encoded unicode characters in the REPL in my UTF-8 configured terminal
11:07raek_,"åäö"
11:07clojurebot"åäö"
11:07raek_,"あ"
11:07clojurebot"あ"
11:07angermanbut for some reason when I do (prn my-str) it fails.
11:07angermanraek_: well, I'm not entering it that way. it's the filename
11:08raek_,(prn "あ")
11:08clojurebot"あ"
11:08raek_ok
11:09raek_maybe java doesn't know which coding your filenames are in
11:09danleihow I love it ... an innocent "git pull" in swank-clojure, and nothing works anymore :)
11:09raek_to me, this looks like a java issue
11:10raek_angerman: what happens when you run (seq (.getName file-obj)) ?
11:11raek_does it treat the character boundaries right?
11:11angerman,(prn "\u3042")
11:11clojurebot"あ"
11:11angermanhmm ok.
11:11angermanso it must be something with my repl-emacs bridge
11:12angermanraek_: no, it seems the file is read correctly
11:14angermanbasically when I enter (prn "\u3042") at the repl in emacs I get a "?"
11:20angermanwow
11:20angermanhere we go
11:20angerman(set-language-environment "UTF-8")
11:20angerman(setq slime-net-coding-system 'utf-8-unix)
11:20angermanwhy that wasn't default ... puzzledme
12:24crioshello. I don't understand this.
12:24crios:
12:24crios,(cons '2' (seq 4))
12:24clojurebot(2 seq 4)
12:24criosbut:
12:24crios,(seq 4)
12:24clojurebotjava.lang.IllegalArgumentException: Don't know how to create ISeq from: Integer
12:25criosHow is 'cons' working there?
12:28ambientcons isn't probably trying to evaluate seq as a functino
12:29ambientit just directly takes the list as input
12:30ambientwhich is weird because (cons 2 (df ij gh)) doesnt really work
12:31crios,(cons '2' ((seq 4)))
12:31clojurebot(2 (seq 4))
12:31criosyes, I understand your point ambient, but it is weird
12:33crios(doc cons)
12:33clojurebot"([x seq]); Returns a new seq where x is the first element and seq is the rest."
12:35criosso, if the second parameter would be evaluated, the doc would say "and seq is an expression which after evaluation become the rest"?
12:45hiredmancrios: clojure doesn't single quote strings
12:45hiredman(cons '2' (seq 4)) => (cons '2 '(seq 4))
12:46hiredman,('seq 4)
12:46clojurebotnil
12:46hiredmaner
12:46hiredman,'(seq 4)
12:46clojurebot(seq 4)
12:46criosso the second parameter (seq 4) is read as a string?
12:47hiredmanno
12:47hiredmanit is quoted
12:47criosah ok, the second '
12:47hiredman,(cons "2" (seq 4))
12:47clojurebotjava.lang.IllegalArgumentException: Don't know how to create ISeq from: Integer
12:47hiredman,(cons 2 (seq 4))
12:47clojurebotjava.lang.IllegalArgumentException: Don't know how to create ISeq from: Integer
12:47hiredman,(cons 2 '(seq 4))
12:47clojurebot(2 seq 4)
12:48criosmy first argument should be a character
12:48crios'2'
12:48hiredmanno
12:48criosat least, my intention
12:48hiredmancharacters are preceded by \
12:48hiredman\2
12:48hiredman,(class \2)
12:48clojurebotjava.lang.Character
12:49crios,'2'
12:49clojurebot2
12:49hiredmanno
12:49hiredmantry calling class on that
12:49hiredman(you cannot do it)
12:50hiredman'a' is not a character literal
12:50criosyes, you are right
12:50hiredmanit is a quoted symbol followed by another quote, so the following form will also be quoted
12:51criosI have to refresh that basic topic! (too much different languages lately!)
12:51criosthanks
12:52Kototamahi, 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:52hiredman(cons '2' (seq 4)) is kind of trippy, it took me a beat or two to realize what was going on
12:52hiredmanKototama: that's an aweful lot of qouting
12:53hiredman,(sort-by count '((a b c) (xx) (aa bb cc dd) (oo)))
12:53clojurebot((xx) (oo) (a b c) (aa bb cc dd))
12:53hiredman,''(aa)
12:53clojurebot(quote (aa))
12:56Kototamaoh ok
12:56Kototamathx you :)
13:49ambienthow do i autocomplete stuff that is in clojure.contrib in emacs?
13:50dmiles_afkrhickey 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:51dmiles_afkClojureCLR > DotLisp > Clojure
13:51dmiles_afk">" greater than
13:51hiredmaneh?
13:51dmiles_afkright now i am up in the air about: DotLisp "what is here?" Clojure
13:52dmiles_afkDotLisp was in my interpretation the prototype of clojure
13:52hiredmanare you actually writing any code?
13:52dmiles_afkmostly interpreting users code
13:52ambienti heard .NET supports TCO
13:52dmiles_afkbut written a bit of DotLisp
13:53dmiles_afkwhich is clojure basically
13:53hiredmaneh?
13:54dmiles_afkwell i am trying to decide.. if i should replace the DotLisp.dll with Clojure
13:54hiredmanthere are surface syntax similarities
13:55dmiles_afkthen trying to decide between ClojureCLR vs CLojure.IKVM.Compile
13:55dmiles_afkthen trying to decide between ClojureCLR vs CLojure.IKVM.Compiled
13:55hiredmanare you sure you want to go with the clr over the jvm?
13:55dmiles_afkClojure.IKVM.Compiled (i tested this one and it basically works)
13:56dmiles_afkwell the rest of the project is CLR.. but really i love the JVM more
13:56dmiles_afkand the only reason .NET/CLR sucks is the perfomarnce.. deep down is a little better
13:56hiredmanI would go with the actaully port of clojure to clr over ikvm
13:57dmiles_afkso i live with performance degrdation for the ValueType feature
13:57hiredmana minivan has more cup holders than a ferrari
13:57dmiles_afkyeah i probly a mini van guy
13:58dmiles_afkok i shall really give ClojureCLR a chance
13:59dmiles_afkjust was scared its going to (eventualy if not now) get neglected
14:00dmiles_afk(when something neat happens the the Clojure JVM world - not propogate)
14:01notallamai think the plan is to rewrite clojure in itself. so in the long run at least, the ports shouldn't get hurt.
14:02dmiles_afkyet ClojureCLR has chances at features regular Clojure wishes the JVM could provide
14:02cypher23anyone 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:03cypher23I get this while trying to use Penumbra (http://github.com/ztellman/penumbra), and typing "(use 'examples.gears)" in the REPL
14:03dmiles_afk"rewrite clojure" - less progress in the shortterm but stll a good thing
14:03cypher23I'm on Snow Leopard, Clojure is the latest version from GitHub
14:05notallamais mono any good? my plan is to avoid clr like the plague anyway, but i'm curious.
14:07Guest92834why avoid it? it kicks ass
14:07Makoryunotallama: The big issue looming over Mono right now is the conservative garbage collector
14:16notallamait'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:18dmiles_afkmono is only 1/2 th speed of the jvm usually
14:19dmiles_afkwell sometimes 1/4 .. but other than that it uses less memory for the same tasks
14:19hiredmanhow are you measuring that?
14:20dmiles_afki large Lisp app framework (like larkc)
14:20dmiles_afka large Lisp app framework (like larkc) .. originaly written in java.. it compiles lisp code to .java files... but also targeting .cs
14:21notallamacould it be that it's more aggressive when compiling to .java?
14:22dmiles_afkso the comarison is slightly skewed.. but when we rewrite parts (not translatated) we end up feeling this way
14:22dmiles_afkit is.
14:22dmiles_afkthe unbaiser is that more of the .cs was hand written
14:23dmiles_afkso even though the the .java is more mature.. the .cs is sometimes better done
14:23notallamathat doesn't sound terribly scientific
14:24dmiles_afkso 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:24hiredmanhow are you measuring that?
14:24hiredmanby that I mean the memory use
14:24raek_cypher23: I got a similar problem when I tried to use compojure
14:24cypher23raek_, did you solve it? how?
14:25hiredmanmono tends to be more dynamic about memory use
14:25raek_in my case the problem was that I had multiple versions of jetty
14:25dmiles_afkfor instance the FIXNUM cache in java is 500mb .. in csharp 0mb
14:25raek_so java loaded som classes from one place and other from another place
14:25hiredmandmiles_afk: how are you measuring that?
14:25raek_so the signatures didn't match package-internally
14:26dmiles_afkhiredman: that 500 vs 0 mb.. just in profilers.. the speed is more some benchmarks
14:26dmiles_afkthe profiling though for mono was more ran .NET (not really mono)
14:26dmiles_afkbut the memory consumption ti start the app framework in jjava is 6GB and in Mono onlly 1.5 mb
14:27raek_I had installed jetty with apt-get, and the other version was included with compojure
14:27dmiles_afkbut thats of course our fault the java is that big.. the methoogy can be changed slightly
14:27hiredmanI 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:27raek_but when I removed jetty from my system and used the jar supplied by compojure, everytihng worked
14:28dmiles_afkhiredman: difference is ValueTypes vs Objects representing Data
14:28raekso I guess that you have duplicate jars somewhere, cypher23
14:28cypher23raek, k. I'll search for that
14:28raekif your problem is the same as mine, that is
14:29dmiles_afkin mono we get to not have to use objects.. unstead .. byvalue structs
14:29dmiles_afkinstead .. byvalue structs
14:29hiredmanmakes sense I guess
14:29hiredmanif only ram were dirt cheap...
14:29dmiles_afkin java every float/integer has to be an object
14:30dmiles_afkin clr.. they are just a byvalue thing
14:30hiredmanstill an object, just an object on the stack instead of the heap?
14:31dmiles_afkyeah.. they are not on heap.. but ctually they are TAGGED type
14:31dmiles_afklike a Union
14:31dmiles_afksome union values denote objects
14:31dmiles_afksome numbers
14:32notallamathe jvm decides it it should allocate on the stack or heap, right? or does it always go for heap?
14:32dmiles_afkright JVM has locally stacked up objects
14:32dmiles_afkthey might end up on heap if the program make them
14:33dmiles_afkour app startup makes a in memory table of 4 million rows times 10 columns.. bwe foree you even get a REPLK
14:33hiredmanI could wrong but I am pretty sure the jvm allocates on the heap
14:34dmiles_afkour app startup makes a in memory table of 4 million rows times 10 columns.. beforee you even get a REPL
14:34hiredmanat least hotspot
14:34hiredmanI think jrockit does some kind of escape analysis to allocate on the stack
14:35dmiles_afkyeah jrocket find places to keep them off the heap
14:35hiredmanthe same place I heard that jrockit does that I also heard it doesn't make a big difference
14:35dmiles_afkwhere the sun thing might make them pass thru gen0
14:36dmiles_afkyeah surprisingly just the standard sun jvm still kicks their butts
14:36dmiles_afkor less than 0.1% differnce
14:36hiredman♥ hotspot
14:37dmiles_afki cant say for sure.. i think java is finalyl doing it right.. where .. mono/.NET has huge room for imporvemnt
14:37dmiles_afkbut once they catch up (4 more years?) jvM will be wishing for ValueTypes
14:37hiredmanthe jvm has been around a lot longer
14:38dmiles_afkjvm has built in ValueTypes int,int[],float,float[],Object, etc
14:39dmiles_afkbut .NET lets users define more
14:39notallamai'm cooking up a toy vm/language of my own right now. i somehow doubt it will be as nice as hotspot, though
14:40jmorkhello, 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:42dmiles_afknotallama: include stucts and ValueTypes and unions ;)
14:43dmiles_afk*structs
14:45chouserunions? really?
14:46dmiles_afkwell so people can use {int mytype, ...somepadding...}
14:46dmiles_afkor whatnot
14:46hiredman:(
14:46hiredmanpadding? really?
14:47dmiles_afkyeah not the best design.. but at least the user has the rope
14:47hiredmanunless you calling out to C all the time...
14:47milephow can I have a sorted map by values? (keys are structs and values integers and all integer are not unique)?
14:47hiredmandefining interfaces based on the size of structures in memory :(
14:48dmiles_afki know bad actually that is why the java version of the app framework runs 40% faster than the C version
14:48dmiles_afkthe C versio is always tearing down its local allocations
14:49notallamamy vm will be pretty crude in that sense. structs and pointers. no unions.
14:49dmiles_afk(the app framework i refered to earlier)
14:49hiredmanI cannot see why you would to "pad" a datastructure in java
14:49dmiles_afkright the C version does.. not the java verion
14:49dmiles_afkthe java version cant :)
14:49hiredmanI know, but even if you could, what would be the point?
14:50hiredmanmy brain hurts just trying to reason out how that would work and why you would want it
14:50dmiles_afkin C, evryone hoped the C compiler could do really smart things .. so they "just got used"
14:51dmiles_afkthe C version was written by john mccarthy 30 years ago
14:51notallamac is fun stuff.
14:51notallamaexcept the infix.
14:51dmiles_afki think when he worked for Cycorp.. that was all that was available
14:51hiredmanC will eat your children
14:52Chousukehiredman: you need to have the binary interface at some level. :P
14:52hiredmansure
14:52notallamathat's what i want. a non-garbage collected lisp that has 3 data types: chars, ints, and pointers
14:53hiredmanChousuke: cinc paired with llvm
14:53Chousukeare chars going to be 8 bits? if so, call them bytes ;P
14:53hiredmannotallama: that is crazy
14:53dmiles_afkin 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:53hiredmanlisp has always had gc
14:54hiredmangc was one of the reasons some people (in antiquity) called java an acceptable list
14:54hiredmanlisp
14:55hiredmanalthough something as direct as C with a nicer syntax might be nice
14:55notallamayeah, but gc doesn't play nice with pointers. given the choice, gc is probably the sane one, but i like pointers.
14:55pixelmanis there work on getting better error messages in clojure?
14:57hiredmannotallama: I have an idea
14:57notallamaoh?
14:58hiredmando it as a concatenative language
14:58hiredmaninstead of a lisp
15:00notallamaprobably a good idea. it doesn't need parens around everything if functions have fixed arity.
15:00ambientfunctional lisp is kinda concatenative
15:00ambientbecause it can be transformed into postfix notation :p
15:01hiredmanconcatenative 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:05cypher23raek, 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:05cypher23thanks for your help
15:14milepis there any helper functions to sort map by values?
15:16johnmn31maybe sort-by. I'll have to look.
15:19johnmn31if you're using keywords, no
15:19johnmn31(sort-by #(< 1 (key %)) {:a 1 :b 2})
15:19johnmn31java.lang.RuntimeException: java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to java.lang.Number
15:20johnmn31but if you're using comparable items as keys:
15:20johnmn31(sort-by #(< 1 (key %)) {2 :a 1 :b})
15:20johnmn31([1 :b] [2 :a])
15:20hiredmanjohnmn31: that is not a sorted map
15:20milepok, thanks, sort-by might do it, I have structs as keys and integer values
15:21johnmn31or you you could do:
15:21johnmn31(sort-by #(< 1 (val %)) {:a 1 :b 2})
15:21johnmn31([:a 1] [:b 2])
15:21hiredman
15:21johnmn31hiredman: what do you mean?
15:21hiredmanjohnmn31: that is not a sorted map
15:22hiredmanyou are taking a map and returning a sequence
15:22johnmn31oh, of course.
15:22johnmn31maps have no order
15:22johnmn31is there a sorted-map in clojure?
15:23hiredmanyes
15:23hiredman,(doc sorted-map)
15:23clojurebot"([& keyvals]); keyval => key val Returns a new sorted map with supplied mappings."
15:23johnmn31indeed there is
15:24johnmn31and as long as the object implements comparable?
15:25johnmn31is there a way to do something like a seq on an array?
15:25Chousukejust call seq on it
15:26Chousuke,(seq (int-array 1 2 3))
15:26clojurebotjava.lang.IllegalArgumentException: Wrong number of args passed to: core$int-array
15:26Chousukehm
15:26Chousukewell, anyway
15:28johnmn31,(int-array 1 2 3)
15:28clojurebotjava.lang.IllegalArgumentException: Wrong number of args passed to: core$int-array
15:28johnmn31,(int-array [1 2 3)
15:28clojurebotUnmatched delimiter: )
15:28johnmn31,(int-array [1 2 3)
15:28clojurebotUnmatched delimiter: )
15:28johnmn31,(int-array [1 2 3])
15:28clojurebot#<int[] [I@10cdec1>
15:28johnmn31butter fingers
15:28johnmn31,(seq (int-array [1 2 3]))
15:28clojurebot(1 2 3)
15:28johnmn31hmm
15:29danleianyone else having problems with completion in latest slime (using swank.swank/start-server, installed without clojure-install)?
15:31milephmm, is there somewhere example how to use sorted-map-by?
15:32danleiI 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:34johnmn31,(sorted-map-by #(< %1 %2) 1 2 3 4 5 6 7 8)
15:34clojurebot{1 2, 3 4, 5 6, 7 8}
15:34johnmn31,(sorted-map-by #(> %1 %2) 1 2 3 4 5 6 7 8)
15:34clojurebot{7 8, 5 6, 3 4, 1 2}
15:35danlei,(sorted-map-by > 1 2 3 4 5 6 7 8)
15:35clojurebot{7 8, 5 6, 3 4, 1 2}
15:36johnmn31,true
15:36clojurebottrue
15:36milepso the sorted-map-by comparator gets keys as arguments?
15:38johnmn31milep: I think it sends both the key and the val to the function
15:39johnmn31sends both the key and val to the comparator, that is.. I'm not sure though
15:39milep,(sorted-map-by #(compare %1 %2) :c 1 :a 3 :b 2 :d 2)
15:39clojurebot{:a 3, :b 2, :c 1, :d 2}
15:40milepthat got only keys?
15:40danlei(sorted-map-by compare :c 1 :a 3 :b 2 :d 2), no need for wrapping
15:41johnmn31I guess so
15:41milepbut if I want to compare values?
15:46johnmn31hmm. 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:47milepjohnmn31: that doesn't help, because I lose values if they are equal
15:47johnmn31true
15:47mileptried that allready :)
15:48johnmn31(well, if you didn't mind ending up with vectors...
15:48johnmn31,(sort-by #(< 1 (val %)) {:a 1 :b 2})
15:48clojurebot([:a 1] [:b 2])
15:49milepcan I make a map from that?
15:50milepI don't mind if it is temporaly list of vectors
15:51johnmn31should be able to
15:52milepI think so also, but haven't found the syntax yet
15:54danlei(into {} (sort-by #(< 1 (val %)) {:a 1 :b 2}))
15:55danleibut that would loose order again :)
15:56milepdanlei: thanks, it doesn't matter I need the order only temporaly
15:58milepbut the sorted-map would be better...
16:00Chousukethere's a sorted-map-by
16:01milepChousuke: yes, but I didn't figure out how to use it to sort by values
16:02johnmn31should be a way to feed a vector of [:a 1] into hash-map
16:02johnmn31I was thinking desctructuring, but I don't really know how to use it
16:02Chousukethere is :p
16:02Chousuke(into {} [[:a 1] [:b 2]])
16:02danleiugliest in town: (apply sorted-map (mapcat identity (sort-by #(< 1 (val %)) {:a 2 :b 1}))) :)
16:02Chousuke,(into {} [[:a 1] [:b 2]])
16:02clojurebot{:a 1, :b 2}
16:03raek,(conj {} [:a 1])
16:03clojurebot{:a 1}
16:03Chousuke,(into (sorted-map) [[:r 1] [:b 2]])
16:03clojurebot{:b 2, :r 1}
16:03danleiChousuke: :)
16:08johnmn31oh. so:
16:08johnmn31,(into {} (sort-by #(< 1 (val %)) {:a 1 :b 2}))
16:08clojurebot{:a 1, :b 2}
16:09danlei(into {} (sort-by #(> 1 (val %)) {:a 1 :b 2})) ≡ (into {} (sort-by #(< 1 (val %)) {:a 1 :b 2}))
16:11johnmn31,(let [a (sort-by #(< 1 (val %)) {:a 1 :b 2 :c 5 :d 0})] (pr a) (into {} a))
16:11clojurebot{:a 1, :d 0, :b 2, :c 5}
16:11clojurebot([:a 1] [:d 0] [:b 2] [:c 5])
16:12johnmn31hmm, 1 is not less than zero, though
16:13johnmn31,(sort-by #(< 1 (val %)) {:a 1 :b 2 :c 5 :d 0})
16:13clojurebot([:a 1] [:d 0] [:b 2] [:c 5])
16:13johnmn31?
16:13johnmn31oh, I'm sorting by 1
16:14danleioh :)
16:14milep,(sort-by #(val %) {:c 1 :a 3 :b 2 :d 2})
16:14clojurebot([:c 1] [:b 2] [:d 2] [:a 3])
16:14Chousuke#(val %) = val :P
16:15johnmn31Chousuke keeps trying to tell us
16:16johnmn31,(let [a (sort-by val {:a 1 :b 9 :d 0})] (pr a) (into {} a))
16:16clojurebot{:d 0, :a 1, :b 9}
16:16clojurebot([:d 0] [:a 1] [:b 9])
16:16johnmn31there we go
16:18Chousukejohnmn31: do not trust that result
16:18Chousukejohnmn31: maps do not maintain order except by accident :)
16:18johnmn31oh I know, that's why I spit out a
16:19johnmn31the ordered data, for use
16:20johnmn31that map being ordered wasn't my intention
16:22milepIs there a way to access values in sorted-map-by comparator?
16:23milep,(sorted-map-by #(compare (val %1) (val %2)) :c 1 :a 3 :b 2 :d 2)
16:23clojurebotjava.lang.RuntimeException: java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to java.util.Map$Entry
16:25Guest92834forgot the {}
16:25Guest92834?
16:25Chousukeit only has access to the key, for obvious reasons :P
16:26milepso, it's not going to be easy to have sorted map by values
16:26danlei(sort '((a 1) (b 2) (c 3) (f 0)) #'< :key #'cadr) :P
16:27Chousukethat's not a map :P
16:27johnmn31true, you might want to use a different datastructure
16:27hiredmankeep two maps
16:28hiredmanone the inverse of the other
16:28danleiwell, i'd call it the poor-cl-mans map :p
16:28milephiredman: won't I lose some values if they are identical?
16:29hiredmanyes
16:29johnmn31you could use a set of key-val pairs
16:30Chousukeand you wouldn't be able to look up by key then /:
16:30danleijust use a good old alist
16:33hiredmanhttp://www.dreamsongs.com/Files/HOPL2-Uncut.pdf "The Evolution of Lisp" is pretty neat, if anyone hasn't seen it
16:35danleialso of (not only) historical interest: http://tinyurl.com/ye3tlko
17:00MarkVolkmannTechnically speaking, is a Var considered to be one of the "reference types"?
17:01ChousukeMarkVolkmann: yes.
17:14raekwow. prxml is really neat.
17:15raeki've always wanted to generate xml and html in a lispy way
17:16raek(prxml [:element {:attribute "value"} "content" [:subelement "sub"] "more text"])
17:17raekprints: <element attribute="value">content<subelement>sub</subelement>more text</element>
17:19raekbtw, has anyone made a version of clojure.contrib.xml/parse that handles xml namespaces?
17:20raeki've seen some ideas in the mail archive, but have anyone implemented this?
17:20hiredman,(doc clojure.xml/parse)
17:20clojurebot"([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:20raekcause I'm thinking about doing it myself
17:21hiredmanseems like that is something to be taken care of with the startparse bit
17:21hiredmanhuh
17:21hiredmanmaybe not
17:22raeki was thinking about a funktion that just takes the output from xml/parse, looks for xmlns attributes, and "updates" tag and attribute names
17:23raekthat is, returning a new xml tree
17:24hiredmantree map
17:25hiredmanI wonder why clojure.zip doesn't define a map
17:25hiredmanclojurebot: transform?
17:25clojurebottransform is http://github.com/hiredman/odds-and-ends/blob/8a84e6ddbad9d71f714ba16c3e1239633228a7eb/functional.clj
17:26hiredmantransform is basically a map over a zipper
17:26raek{:tag :html :attribs {:xmlns "http://www.w3.org/1999/xhtml&quot;}} => {:tag #^{:namespace "http://www.w3.org/1999/xhtml&quot;} :html}
17:26raekor something similar
17:26hiredmanheck
17:27raekto have maps that share structure is really awesome
17:28raekespecially if you have to keep track of an environment with some sort of bindings when traversing data structures
17:28raeklike xml namespace prefixes
18:04ztellmanwhat's the proper way to reference an internal class?
18:04ztellmanA$B ?
18:09danleiztellman: yes
18:09zaphar_psout of curiosity are there any clojure http-server libraries?
18:10danleiah, finally I got my completion back
18:10ztellmandanlei: it looks like you have to give the full classpath to have the inner class notation work
18:10ztellmanis that true, or am I just doing it wrong
18:12danleiztellman: no, you don't have to. for example: (DefaultEditorKit$CopyAction.)
18:12ztellmandanlei: well, this is for an enum rather than a class
18:12ztellmanmaybe that makes a difference, I dunno
18:12danleihm
18:12danleiI'm not sure
18:12ztellmanit's not a big deal
18:12danleibut I don't think that makes a difference
18:14danleiI had to import them like this though: (javax.swing.text DefaultEditorKit$CopyAction DefaultEditorKit$PasteAction DefaultEditorKit$CutAction), maybe that helps
18:15ztellmandanlei: I'll try that, thanks
18:53poetwhat's the usual turn around time for a new post on the clojure mailing list being approved ?
19:09somniumis there a standard java/clojure way to get all subdirs of a dir?
20:10ajaWhat 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:11somnium,(for [x (range 20)] (* x x))
20:11clojurebot(0 1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361)
20:11ajasomnium: Heh. Thanks. Once again, I bounce off the bloody square brackets.
20:12somniumyoull get used to 'em
20:12ajasomnium: I used to be annoyed by lisp newbs who complained about all the brackets -- I now have new empathy./
20:13somniumthey make binding expressions more readable than common-lisp, imo
20:14ajasomnium: Yeah -- I seee the point. I just have to re-train the part of my brain that was devoted to parsing that stuff.
20:16ajasomnium: Seems to work a charm. Thanks.
20:16aja(Note to self: When in doubt, consider that the things that might be lets should be inside [])
20:53danleishomehow 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:54somniumyou really prefer (hash-map :a :b :c :d) to {:a :b :c :d} ?
20:54danleiI didn't say it wasn't convenient
20:54danleiI still dont like the look
20:54danleiso, optically, yes i prefere the latter
20:54somniumor (let (a (hash-map :a :b :c :d)) ...
20:54danleibut still use the former
20:55danlei*prefer
20:55danleii don't even mind the additional parens in the other lisp
20:55somniumI'm trying to think of an example using destructuring without brackets, but there's no way Ill get the parens right
20:55danleithat was never something I minded
20:55danleiwell, in CL there's destructuring bind, but it's less general
20:56somniumfor me its not the parens, its the lack of visual cues to distinguish types of expressions
20:56danleianyway, I wasn't complaining about the language, it's just a more or less aesthetic thing. taste, if you will.
20:57somnium,(for [{x [_ y]} {:a [1 2] :b [3 4]}] [x y])
20:57clojurebotjava.lang.Exception: Unable to resolve symbol: _ in this context
20:58danleiI hate those visual cues somehow
20:58somnium:)
20:58danleii like the ... hm
20:58danleithe "harmony" of just symbols and round parens
20:58somniumok, but I don't know how I could write that and understand it without the reader macros
20:58danleiwell, in the other lisps that is not much of a problem
20:59danleisince the usual destructuring (as in CL) just operates on lists
20:59somnium,(for [{x [z y]} {:a [1 2] :b [3 4]}] [x y])
20:59clojurebotjava.lang.Exception: Unable to resolve symbol: z in this context
20:59danleithere are libs though which manage that without reader macros
20:59danleiI just don't use them
20:59danleifor example cl-unification
21:00danleiit's actually more ...
21:00danleibut again: no complaints, it's purely subjective, I know
21:00somniumwell, I never did anything substantial with a lisp before clojure, so I guess I don't haven anything to compare it to
21:01somniumbut it has most of the literal sugar I'm used to from languages like python or ruby
21:01danleiand it really is convenient (and a very nice language in general)
21:02danleiI always felt that the sequence abstraction in CL should be more general
21:02danleialong came clojure ... :)
21:09somnium,(apply merge (for [[x [y z]] {:a [1 2] :b [3 4]}] {x (+ y z)}))
21:09clojurebot{:b 7, :a 3}
21:09somniumI guess it is kind of noisy, what is equivalent with destructuring bind?
21:11danleias I said, there is no real equivalent, since dest-bind operates on lists
21:11danleiyou'd have to use something like metabang-bind or cl-unification, which I don't do usually. You'd just bind with lets.
21:12somniummetabang-bind is a nice name for a function
21:12danlei:)
21:15danleialso, 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:18danleithen again ... I still find let-binding easier to read sometimes. depends ...
21:21somniumI 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:22danleime to :)
21:23chousersomnium: how long have you been using Clojure?
21:23somniumnot long :)
21:23somniummaybe 5 months since I discovered it?
21:23chouseryou're in a well known stage.
21:23chouser:-)
21:24chouser1. "oh! Java!?" 2. "Eww! Java!" 3. "Ah... Java..."
21:25chouserdanlei: is apparently in a stage all his own. :-)
21:25somniumI used jruby before, but that is really grafted onto java, contorts java into its own syntax
21:26somniummaybe I'm just wanting to recreate that experience :)
21:27somnium,(doc atom)
21:27clojurebot"([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:28somniumif 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:32chouserbleh. probably not much point in putting it in an atom if it mutates on its own.
21:32chouserIf you're willing to make a full copy each time you change it, you could do that -- pretend it's an immutable value.
21:33somniumhmm, was thinking of opening/closing sockets on a server
21:33chouseryeah, I don't know how to handle that. I've done it, but I'm not sure I did it right.
21:34chouserthe statefulness of that socket tended to leak out into the rest of my program -- hard to keep it contained.
21:34somniumperhaps cinc will lead to a functional server
21:35chouseryou could put it in an agent instead, and only operate it on it by sending functions to the agent
21:35chouserthis would serialize access to the socket
21:36danleichouser: 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:36danleiend up wrapping relatively often. again, that's just taste.
21:36somniumwhen to use send vs. send-off?
21:41chousersomnium: if your function is CPU bound, use send. If it blocks on anything else, IO for example, use send-off.
21:42chouserdanlei: 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:44chouserI 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:44chouserIn 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:45chouserand 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:46chouserIn 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:46slashus2oo I just learned about transients.
21:46chouserAll that said, though, of course it's a matter of taste, as you said.
21:49danleichouser: 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:54slashus2chouser: I have read a little bit about newnew. Is the clojure in clojure effort and newnew coming along pretty well?
22:06sproingiei think my problem with CL is mostly IDENTIFIERS-THAT-LOOK-LIKE-COBOL-TO-DO-BASIC-THINGS
22:07danleiwell, I prefer it to id/l->cob :)
22:08sproingiethere's a happy medium
22:08danleiand since you use java in clojure more or less daily, you often have a similar effect, lest you wrap
22:08danleis/lest/unless
22:09danleibut yes, there are a few long identifiers, sure
22:09sproingiemacros help
22:09danleion the other hand, I prefer list to l for list variables
22:10sproingiei special-case that one and use L
22:10danleiwhich starts another flame: lisp-1 vs lisp-2 ;9
22:10sproingiei like lisp-1
22:10sproingie<3 scheme
22:10danleiI like both, I always miss something, no matter which one I am using
22:10sproingiemy other lisp is elisp which is also a lisp-1
22:11danleihere the freedom of identifier choice, there the ease of dealing with 1st class funs
22:11arbschtnone of these things bother me in either CL or Clojure
22:11danleielisp?
22:11sproingieemacs lisp
22:11danlei(setq foo (lambda () 'hallo))
22:11danlei(foo)
22:11danleitry it
22:12sproingiehm. except i'm always throwing around functions without #'
22:12sproingieoh nevermind those aren't functions
22:12sproingiebeen a while since i last hacked elisp :p
22:12danleinp
22:13danleiarbscht: well, I miss the freedom in variable naming more than lisp-1 ness. I guess I tend towards lisp-2
22:14sproingiestatic scope tends to make accidental shadowing less an issoe
22:14clojurebotscope is at http://paste.lisp.org/display/73838
22:14sproingieissue
22:14sproingiemacros have hygeine problems either way
22:16danleiI don't even see why it should be impossible to allow (setq foo (lambda () 'blah)) (foo) -> blah
22:16danlei(in a lisp-2)
22:21sproingiebecause you're setting the value slot
22:21danleidoesn't work because it doesn't work? :)
22:22sproingiebecause the spec only looks at the function slot when it sees (foo)
22:22danleisure, 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:22danleiyes, I know the way it is
22:22sproingiefalling back to the value slot might be interesting but probably infeasable
22:22danleiI just don't understand the reason
22:23danleiprobably
22:23danleibut I'm not sure why it would be
22:24sproingieconsistency i guess. don't have to introspect values for callables
22:24danleiof corse it would just be for convenience ...
22:24danleimaybe performance issues ... dunno
22:24sproingieif you look into values you pretty much have a lisp-1
22:24danleiwell, yes
22:24sproingielisp-1 with some dual nature to be sure
22:25danleithe "default" for funs would be the symbol-function, but symbol-value would work for convenience
22:26danleiprobably there is an obvious reason why it is like it is and I just don't know enough about the subject
22:26sproingietraditiooooooon ... tradition!
22:27danlei:)
22:31danleibut 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:32danleiso maybe yes, tradition, culture, taste. like often.
22:44somniumwhat is the preferred way to set *config* vars when using libraries? presumably not (do (in-ns foo) (def *config* bar))
23:06hiredman" About this time, the Scheme community
23:07hiredmanstarts denying that Scheme is a dialect of Lisp, claiming closer bonds to Algol.
23:07hiredman"
23:07hiredmanbrilliant, pure gold
23:07chousersomnium: wouldn't work anyway.
23:07chouseryou can use 'binding' for thread-local setting, or perhaps alter-var-root
23:14chouserhiredman: what's that from?
23:15hiredmanthe evolution of lisp
23:16somniumchouser: it seemed to work (do (in-ns 'foo) (def *bar* baz) (in-ns 'old-namespace))
23:26chousersomnium: hm, indeed.
23:57rongenreHi .. looking for a decent example a defn with optional keyword arguments
23:57arbschtdefn doesn't take keyword arguments
23:58rongenreI meant creating a function with optional keyword args
23:58arbschtfunctions don't, either :)
23:59arbschtyou can pretend they do by applying hash-map to the args, I guess
23:59rongenreReally. So I need to do the &rest thing and do a hash-map yeah
23:59rongenreOk, just trying to be idiomatic
23:59arbscht,((fn [& args] (apply hash-map args)) :a 1 :b 2)
23:59clojurebot{:a 1, :b 2}
23:59rongenreawesome. Thanks!