#clojure logs

2009-09-02

00:05technomancywow, I just got bit by lisp-1-ness for the first time ever.
00:08lisppaste8technomancy pasted "crazy proxy macro" at http://paste.lisp.org/display/86410
00:08technomancyso my methods map isn't working with init-proxy; not sure why
00:08technomancyguess I should try it with a map that doesn't need tweaking first
00:18lisppaste8technomancy annotated #86410 "almost works" at http://paste.lisp.org/display/86410#1
00:19technomancyso this works if I remove IMeta from the proxy definition
00:21technomancythe meta method just needs to return a map and take zero args, right?
00:21technomancywhy would it be raising an UnsupportedOperationException?
00:22hiredmansomeing is trying to mutate something
00:22hiredmanthe clojure collections all throw that exception if you call a mutable part of the collections interface
00:23hiredmanpossibly something else of course
00:25technomancyhttp://p.hagelb.org/meta-exception.html <= it looks like the repl is actually raising the exception by trying to look up the type in the meta map
00:26technomancyoh... init-proxy _replaces_ a proxy's methods.
00:26technomancyI want update-proxy
00:26hiredmanoh
00:27hiredmando you have a fn implementing that method in the map?
00:27hiredmanproxy throws that for unimplemented interface methods too
00:27technomancynope, just in the original proxy
00:27clojurebotproxy is <Chouser> proxy teases with its ease of use, then suddenly betrays.
00:27technomancyso true!
00:27technomancy,botsnack
00:27clojurebotjava.lang.Exception: Unable to resolve symbol: botsnack in this context
00:27hiredmanpashaw
00:27technomancy~botsnack
00:27clojurebotthanks; that was delicious. (nom nom nom)
00:33technomancywell that's enough Macro Madness for tonight.
00:33technomancythanks.
02:07LauJensenDoesnt 'if' abort evaluation if the first item or can 'or' body evalutes to false?
02:08hiredman
02:09broolLauJensen: not sure I understand the question
02:09brool"or" short circuits if any item is true
02:09hiredmannot the most readable thing
02:09LauJensen,(if (or (= 2 1) (= 3 (+ 1 2))) (prn "foo") (prn "bar"))
02:10clojurebot"foo"
02:10LauJensenIs (+1 2) ever evaluated?
02:10LauJensenAnswer then is no, thanks :)
02:10hiredmanuh
02:10brool( + 1 2 ) is evaluated there
02:10broolbecause first condition is false
02:10hiredman
02:11hiredman(= 2 1) is false so (= 3 (+ 1 2)) is evaluated
02:11hiredmanand is true, so the if expression evaluates to the result of evaluating (prn "foo")
02:12hiredmanwhich prints out "foo" as a side effect
02:12brool,(or (do (println "did first clause... ") (= 2 1)) (do (println "did second clause... ") (= 3 (+ 1 2))))
02:12clojurebottrue
02:12clojurebotdid first clause... did second clause...
02:14LauJensenYes yes I got it, thanks :) I wrongfully put in a false first clause
04:06alinphi
04:06alinpI have a function like this:
04:06alinp(defn my-f [fn] (fn))
04:06alinp(def x (fn [a b] (+ a b)))
04:07alinp(my-f (x 2 3))
04:07alinphow can I make this work ?
04:07alinpI mean .. calling fn inside my-f
04:07hiredman
04:07hiredmanyou need to pass my-f a function
04:08hiredman(x 2 3) is not a function
04:08rathorehiredman: just curious... what timezone are u in?
04:08hiredmanwest coast of america
04:09rathorehiredman: ok... just wondering, cause you're always here helping folks... very grateful to you :)
04:09hiredman:P
04:12alinphiredman: but I need also to pass the argumens
04:12alinparguments
04:12alinpI need to call apply inside my-f ?
04:13hiredmanno
04:13alinp(defn my-f [fn & args] (apply fn args))
04:13alinp(my-f x 1 2)
04:13alinpthis works
04:13hiredmansure that'll work too
04:14alinpcan you please tell me how can I do that beside of apply ?
04:14hiredmanpass in a functio to my-f
04:14hiredmanmy-f takes one arg fn
04:14alinpyeah
04:14hiredmanthe body of my-f is (fn) which is a function call
04:14alinp(def x (fn [a b] (+ a b)))
04:15alinpx is a function
04:15hiredmansure
04:15alinpso
04:15hiredmanbut (x 2 3) is not
04:15alinpok ...
04:15hiredman(x 2 3) is function application
04:15alinpok ...
04:15hiredmanso what happens is (x 2 3) evaluates to 5
04:15alinpso, 5 is sent instead of fn
04:15alinptrue
04:16hiredmanso my-f attempts to call 5 as a function
04:16hiredmanwhich, well, doesn't work
04:16alinp(my-f (fn [] (x 1 2)))
04:17alinpshould do the trick
04:17alinpright ?
04:17hiredmanyes
04:17hiredmanthere is also a handy bit of syntactic sugar for this
04:17hiredman#(x 1 2)
04:17alinpoh, yeah :)
04:17alinpI knew that
04:17alinpI like to be more verbose when comes to lambda functions ;)
04:18alinpbut, thanks for reminding me
04:18hiredmansure
04:20nselwhen clicking on stack trace frames in swank-clojure, I get "Synchronous Lisp Evaluation aborted." just want to check before filing a bug report, does anyone here get something different when they click on a stacktrace frame?
04:20nselI've been seeing this behavior for months, and have latest git version
04:21nselwouldn't be surprised if that's just how it's supposed to be, not yet implemented, as well
04:22nsel(test case: trigger any error which brings up a slime backtrace and click on a frame).
04:26nselincase this wasn't clear, normally you'd expect it to jump to a source location.
05:03AWizzArdwhen I included a .txt file into my .jar, how can I then slurp the contents of that .txt file?
05:04Chousukehmm
05:04ChousukeI think you can use @ in a path to mean "classpath-relative"
05:05AWizzArdI would like to include it in the .jar instead of putting it outside
05:05AWizzArdI already tried (slurp "@/com/company/file.txt")
05:05hiredman(.getResourceAsStream (clojure.lang.RT/baseLoader) "version") where version is the name of a textfile
05:06hiredmanthat gets you an inputstream
05:08AWizzArdmaybe I can use duck-streams reader function with that
05:10hiredman,(doc reader)
05:10clojurebot"clojure.contrib.duck-streams/reader;[[x]]; Attempts to coerce its argument into an open java.io.BufferedReader. Argument may be an instance of Reader, BufferedReader, InputStream, File, URI, URL, or String. If argument is a String, it tries to resolve it first as a URI, then as a local file name. URIs with a 'file' protocol are converted to local file names. Uses *default-encoding* as the text encoding. Should be used in
05:10hiredmansays it takes an input stream
08:48lisppaste8raphinou pasted "help for translating from OO to clojure" at http://paste.lisp.org/display/86427
08:48raphinou_if someone has the time to look at this paste, I can use some help
08:49raphinou_trying to translate OO code in clojure, and I don't see how to keep funtionality without the instance variables that are used in the OO example
08:54noidiraphinou_, you could create check-credentials inside make-login-widget
08:54noidithen it could access all the variables in a closure
08:55raphinou_yes, seems obvious now you say it :-)
08:55ChouserI keep losing the link to that blog post that walks through a few different ways to do "objects" in Clojure.
08:56Chouserbut generally, closing over the "instance" data is one way. Another is to put that data in a vector or map and pass it around.
08:56raphinou_ok
08:57raphinou_I was afraid my function would grow horribly, but in a sense it's fine to have it defined in there, as it only makes sense to use it there
08:58noidii thought about this myself a few days ago, and here's the toy code i worked with: http://pastebin.com/d44188f91
08:58AWizzArdraphinou_: you can use defstruct to define the fields of your "class" and define multimethods on it. One example, pretty much what Chouser said.
08:59Chouserno point in multimethods unless you expect to override them.
08:59noidithis macro even gets rid of the duplication in the clojure version http://groups.google.com/group/clojure/msg/5ef807214247472d
09:01rhickeyraphinou_: just pass the data in a map
09:01rhickeythen you get a nice function you can test without a gui
09:01triyoAnyone know of any native HTML parser for clojure?
09:02Chousertriyo: what do you mean by "native"? tagsoup has worked well for me.
09:02raphinou_thx all for your answers!
09:03triyoChouser: by native I mean non-java introp way
09:04Chousertriyo: nope, don't know of such a thing. What would be the benefit of avoiding interop?
09:05noidiChouser, is this the blog post you mentioned? http://blog.thinkrelevance.com/2009/8/12/rifle-oriented-programming-with-clojure-2
09:05Chousernoidi: no, though that's good too.
09:06triyoChouser: no real benefit I guess except that it will perhaps be more lispy. I'll give tagsoup a try.
09:06noidiI love the analogy :) "Its a little like saying that a rifle is not arrow-oriented."
09:20ole3test
09:29ambienthmm, to me OO is mainly about hiding the complexity that arises from mutability. clojure doesnt really have a lot of that so therefore clojure doesn't need OO that much
09:29ambientalso, OO is more about messages than it is about objects imo
10:23LauJensenGents, what would be the most elegant way to scramble a sequence randomly? ie (scramble [1 2 3 4 5]) => [4 1 5 3 2], (scramble [1 2 3 4 5]) => [1 3 4 2 5] ?
10:25ChousukeLauJensen: probably best to use java for that.
10:25Chousukeconvert to array, scramble, convert back to vector.
10:28raphinou___is it normal that drop-fruit is displayed at http://richhickey.github.com/clojure-contrib/sql-api.html ?
10:29raphinou___and in general the functions from the sql.test ns ?
10:35Chouserhm.. does seem likely that's a mistake.
11:15LauJensenChousuke: When I said 'the most elegant way', what on earth got you thinking Java?
11:16FossiLauJensen: i think there's a function for that in some util in contrib
11:16Fossiseq-util prolly
11:20liwp,(let [l (java.util.ArrayList. [1 2 3])] (do (java.util.Collections/shuffle l) l))
11:20clojurebot#<ArrayList [1, 3, 2]>
11:20liwpso how do you make a vector / list out of the ArrayList again?
11:20ChousukeLauJensen: because java probably has a method for scrambling arrays :P
11:21liwpand no, that's not particularly elegant, especially with the inplace shuffle, but it's quite short
11:21ChousukeLauJensen: and it's going to be faster than anything you can do with immutable vectors :)
11:21liwpChousuke: yep, java.util.Collections/shuffle which takes a List
11:22stuartsierrac.c.seq-utils/shuffle just calls ArrayList/shuffle.
11:22Chousuke,(vec (ArrayList. [1 2 3]))
11:22clojurebot[1 2 3]
11:22liwpstuartsierra: heh, I didn't look that far :)
11:23liwp,(let [l (java.util.ArrayList. [1 2 3])] (do (java.util.Collections/shuffle l) (vec l)))
11:23clojurebot[2 1 3]
11:23Chousukethat's going to be as elegant as you can get I suppose.
11:23stuartsierraOthers have written shuffle fns using, e.g., Knuth's algorithm for arrays of unknown length, but ArrayList/shuffle is much efficient.
11:23stuartsierra*more efficient.
11:24liwpstuartsierra: I'm not seeing a shuffle in ArrayList
11:24Chousukehm
11:24stuartsierraIt's part of the Collections interface, I think.
11:24Chousuke,(instance? List [])
11:24clojurebotjava.lang.Exception: Unable to resolve symbol: List in this context
11:24Chousuke,(instance? java.util.List [])
11:24clojurebottrue
11:25stuartsierra,(java.util.Collection/shuffle [1 2 3 4 5])
11:25clojurebotjava.lang.IllegalArgumentException: No matching method: shuffle
11:25stuartsierra,(.shuffle [1 2 3 4 5])
11:25clojurebotjava.lang.IllegalArgumentException: No matching field found: shuffle for class clojure.lang.LazilyPersistentVector
11:25Chousuke,(java.util.Collections/shuffle [1 2 3 4 5])
11:25clojurebotjava.lang.UnsupportedOperationException
11:25Chousuke,(java.util.Collections/shuffle (transient [1 2 3 4 5]))
11:25clojurebotjava.lang.Exception: Unable to resolve symbol: transient in this context
11:25Chousukedamn :P
11:26ChousukeI guess there is no getting around the mutability.
11:26ambientback to netbeans from emacs, enclojure seems to have developed nicely last time i tried it. with emacs it's a bit hard to add external libraries
11:26Chousukebut if it's only an implementation detail it doesn't exist :)
11:26stuartsierraNope. seq-utils/shuffle copies to an ArrayList and calls shuffle on that.
11:26clojurebotshuffle is http://groups.google.com/group/clojure/msg/a2816f1b51d99b79
11:27stuartsierrathere you go
11:27liwpthank you clojurebot!
11:28Chousukefor once the autocomment feature triggered at the right time :)
11:39LauJensenSweet :)
11:40LauJensenThanks for taking up the discussions guys :)
11:46ChouserI've got a question about the finger-tree paper. I don't suppose anyone here has read it enough to help me come up with an answer?
11:47Licenser42!
11:47rhickeynot necessarily an impediment :)
11:47rhickeyshoot
11:47Licenserrhickey: you're the clojure guy right?
11:47Chouserit looks to me like the measure function is applied at all levels of the tree
11:48rhickeyLicenser: yes
11:48Licenserthen good work! Keep it going :D
11:49Chouserthat is, if the measure function is the domain of all measure functions has to include type a (the basic element type), type Node a, type Node Node a, etc.
11:49slyrus_hmm.. wasn't sure if there was going to be a #clojure, much less one with 142 users. :)
11:49Chousers/if the/the/
11:49Chousukeheh
11:50Chousukethis channel is often better for getting in touch with the right people than the group is :P
11:50slyrus_group?
11:50Chousukethe google group
11:50slyrus_ah, ok
11:51Chouserbleh, I messed that up too much. I'll try again.
11:51Chouserthe domain of all measure functions has to include type a (the basic element type), type Node a, type Node Node a, etc.
11:53Chouserbut that doesn't seem very nice to me. surely the measure fn ought to only have to understand type a
11:55rhickeydoesn't || pluck out the v?
11:56Chouser|| on a node simply returns the cached v, yes.
11:56rhickeydoesn't that happen always before the measure is applied?
11:57ChouserBut when constructing the node with the "smart constructors" at the top of section 4.2, they just do ||a|| (+) ||b||, where a and b could be of any nested Node depth
11:57djpowellHmm, whilst the 'recur' examples on the transients page work well, I'm finding that doing something like: (reduce (fn [m [k v]] (assoc! m k v)) (transient m1) mymap) - doesn't perform much differently than the persistent version - is that to be expected?
11:57Chouseroh
11:58Chouserright. ok, if a is a Node, || on it will return the cached.
11:58Chouseronly if a is a Digit will it try to apply the user-supplied measure fn
11:59Chousersomehow I lost this in the conversion from vectors-with-metadata to reify'd objects, and then got too muddled to put it back together.
12:00rhickeyChouser: I know you've been planning on exposing the measure system generically, just want to point out the utility of a version with it hardwired: http://hackage.haskell.org/packages/archive/containers/0.2.0.1/doc/html/Data-Sequence.html
12:01Chouserrhickey: yes, I have vague plans to do both.
12:01rhickeyIt all starts with vague plans :)
12:02Chouserthat is, a generic underlying thing with no built-in measure (perfect for simple queues)
12:02Chouserthen something built on top that implements Indexed by measuring size
12:03Chouserperhaps some nicely packaged priority queue. etc.
12:26djpowellI think my problem is probably that even the persistent collections perform so well that the calculations I am doing dominate the time taken to build the collection
12:26djpowellwhich is good
12:39ole3hello, is there a way to stop and resume processes in clojure?
12:44leafwole3: process are java Threads. So yes.
12:46ole3leafw: really? I thought a process lives in its own address space.
12:48leafwer, a virtual machine is just that, virtual.
12:49ole3leafw: ok, can you tell me how?
12:50ole3leafw: something like SIGSTOP?
12:51leafwole3: are you talking about OS process, which are just the JVM ?
12:54ole3leafw: I'm talking about an OS process started via (.exec (Runtime/getRuntime) ...)
12:54leafwole3: ah! Then, catch the returned object
12:54ole3leafw: ok got it, stored in *process* :)
12:55leafwyes
12:55ole3leafw: Here it is: #<UNIXProcess java.lang.UNIXProcess@16917ee>
12:55leafwunfortunately, the http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Process.html seems not to have anything else to do other than destroy(), so you have to cast blindly
12:56leafwto the subclass.
12:56leafwi.e. inspect its methods, it may have what you want :)
12:56ole3hm, to what subclass?
12:57ole3It has exitValue, destroy, waitFor, but not stop
12:57leafwjava.lang.UNIXProcess is likely a subclass of java.lang.Process
12:58dave[csc]Is there an issue with defining an empty vector? a la (def myvec vec)
12:58ole3yes, it is one
12:58leafwole3: then the UNIXProcess maybe has other methods. If not, then ... you are stuck.
12:59ole3leafw: oh my god
13:01ole3leafw: does this mean i have to use jni or jna for stopping processes
13:01Chousukecan't you send a suspend signal to the process?
13:02ole3i don't know the pid
13:13Chouserdave[csc]: vec is not an empty vector, it's a function to create vectors. [] is an empty vector
13:22ole3ok, i will use jna, thanks for your help
13:28ambientim wondering if i can just use arrays & stuff for mutable data structures and not really care
13:28ambienti really love the lispiness but the immutability is seriously giving me a headache
13:30Chouserambient: sure you can, but it'll be better for you in the long run if you push through on the immutability front.
13:31ambientwell i find it really hard to vision games done mostly with immutable data
13:33Chouserperformance issues are one thing. headaches another.
13:41ericthorsenI see there is a logging namespace in clojure.contrib but it does not appear that anyone is using it (in the contrib lib I mean)
13:42ericthorsenIs there a preferred way to handle this in the contrib code? or is logging frowned upon?
13:42technomancyericthorsen: I just started using it
13:42technomancyplanning on backporting it to the 1.0-compat branch, actually
13:43Chouseroh, I see -- if a contrib lib needs to log something?
13:43ankouhi, is it possible (and advised) to split one namespace over several files?
13:43ericthorsenChouser: exactly
13:44Chouserankou: certainly possible. proxy and genclass are in clojure.core namespace but live in their own .clj files.
13:44Chouserericthorsen: dunno, haven't needed it. For me it's seemed best so far to leave error handling up to the app -- it can log or abort or whatever as needed.
13:45ericthorsentechnomancy: it is omitted from the build and does not appear to load unless it can see all the libs (log4j, apache.commons.logging, etc.) which I assume defeats the purpose. Perhaps I do not know how to use it?
13:45technomancyericthorsen: it works with java.util.logging if the others are not found
13:45ankouChouser: is it recommended to split it in several files and load these?
13:46ankouChouser: better question: is this errorprone or something like that?
13:46Chouserankou: Not sure when it's recommended but it's definitely supported.
13:47ericthorsenChouser: You do not see utility in library code providing any logging?
13:47Chouserankou: note how the top of core_proxy.clj differs from most .clj lib files. It's a "secondary" file, so it doesn't define the namespace with an 'ns' macro call. instead it uses in-ns and import.
13:48Chouserericthorsen: I haven't written a libarary where it felt like the right choice. I'm making no claims about the general case. :-)
13:49ericthorsenChouser: ok
13:49technomancyericthorsen: the logging library is quite new.
13:49ericthorsentechnomancy: I see.
13:51ericthorsenChouser: I find having the ability to enable logging in APIs I am not the author of useful in troubleshooting problems. It has been a life saver working in the behemoth Netbeans framework for example.
13:52ericthorsenChouser: I can do what I need to in contrib without it for sure...just curious as to what the current thinking was there
13:52ankouChouser: so it is convention to use a namespace for each file even in normal non-library programs?
13:52ankouChouser: or do they normally use the User namespace ?
13:53Chouserankou: Most namespaces are defined by a single file.
13:54Chouserankou: I'd not recommend using the 'user' namespace except for repl, work-in-progress, toy code, etc. It won't AOT compile, might clash with others code, etc.
13:55Chouserany lib or releasable app ought to use its own namespace
13:55ankouChouser: with several minor namespaces? because I think it would somewhat confusing to have several thousand lines in one file
13:56opqdonutsure
13:56opqdonuti use subnamespaces all the time
13:57Chousersure, if your code gets to be more than you want for a file, you can add more files, either in the same namespace or in new namespaces.
13:57ChouserI guess I would generally add a new namespace when I add a new file, unless I had a specific reason to extend an existing namespace.
13:58hiredmancalling them subnamespaces is some what confusing
13:59ankoubut you know what I mean
13:59ankouor opqdonut xD
13:59ankouokay thanks
13:59hiredmanas far as I can tell there is no hierarchy of namespaces just like there is no hierarchy of java packages
13:59opqdonutyeh
13:59Chouserright, just a hierarchy of names. :-/
14:17mibuI have a peculiar bug with for. The first binding form is always binding to the first element of a sequence. Can someone shed some light on this behavior? http://codepad.org/8BY0KlQi
14:17mibuI'm using 1.1
14:20stuartsierrafor iterates over all bindings, last-fastest
14:20stuartsierraif the last binding is to an infinite sequence, the first binding will never advance
14:21mibuwhat do you mean?
14:21Chouserit's like a nested loop.
14:21stuartsierra,(for [i (range 5) j (range 5)] [i j])
14:21clojurebot([0 0] [0 1] [0 2] [0 3] [0 4] [1 0] [1 1] [1 2] [1 3] [1 4] [2 0] [2 1] [2 2] [2 3] [2 4] [3 0] [3 1] [3 2] [3 3] [3 4] [4 0] [4 1] [4 2] [4 3] [4 4])
14:21mibuoh, I see.
14:21mibuso, you can't bind to infinite sequences in for?
14:22stuartsierraNot if they're nested.
14:22Chousukeyou can, but it makes no sense :)
14:22mibuwhat's a better elegant way to create pairs from a single sequence?
14:22Chousukeat least, not without :while
14:22Chousersure you can, but if any level is infinite and not terminated by a :while, then you'll just never get to the next iteration of the outer level
14:22Chousukepartition?
14:23mibuchousuke: yes! thank you.
14:23mibuI hate it when I forget simple useful functions.
14:24Chousukenote that partition may require padding if you have an uneven sequence
14:24mibuI have an infinite sequence.
14:24Chousukeoh, okay :)
14:26mibuThere ought to be a place with all those little gotchas for every function. I haven't coded in clojure for two months and I already forgot plenty of those gotchas.
14:27Chousukestart a blog series.
14:27Chousuke:)
14:28ambientreverse of partition seems to be for
14:28mibuI was thinking maybe an add-on to the internal documentation (doc). you know, with examples, gotchas, guidelines, and other cookbook stuff.
14:28Chousukeheh
14:28ambient[[2 4] [3 5]] (for [x coll] (first x)) seems to be shortest way ot generating seq from the first items
14:29Chouser(map first coll)
14:29ambient:( *dohh*
14:29Chousukeand the reverse of partition is concat
14:29Chousuke,(apply concat (partition 2 [1 2 3 4])
14:29clojurebotEOF while reading
14:29Chousukewhoops
14:29Chousuke,(apply concat (partition 2 [1 2 3 4]))
14:29clojurebot(1 2 3 4)
14:34ambient(map #(play-note chan %1 %2) (map first phr) (map second phr)) im sure there's more elegant way to put this
14:37Chousukehm
14:38Chousukeplay-note looks like it should have a side-effect :P
14:38ambientit has
14:38Chousuke(doseq [[x y] phr] (play-note chan x y)) then
14:40Chousukeyou should avoid mapping functions with side-effects
14:41Chousuke,(do (map println ["foo" "bar"]) "foiled")
14:41clojurebot"foiled"
14:41ambientbecause map doesn't guarantee sequential access?
14:41Chousuke,(do (doall (map println ["foo" "bar"])) "not foiled")
14:41clojurebot"not foiled"
14:41clojurebotfoo bar
14:41Chousukebecause map is lazy :)
14:41Chousukedoall forces eagerness
14:42Chousukeor dorun, if you don't care about the results.
14:43ambientthis is going to be absolutely horrible..
14:43ambientim generating a thread for each channel and each pattern
14:43Chousukehm.
14:43Chousukeyou might have problems keeping them in sync :P
14:46ambientor alternatively i could convert these: (def phr-melod-1 [[60 250] [64 250] [60 250] [65 250]]) into event model
14:47ambientso i need to convert from note duration to its position in time
14:57ambientdamn.. its surprisingly complex to build accumulating value over seq and make a new seq out of it
14:58Chouser:-)
14:58ambientor perhaps i could use reduce
14:58Chouser,(reduce (fn [[acc time] [dur freq]] [(conj acc [time freq]) (+ time dur)]) [[] 0] [[1 :a] [4 :b] [3 :c] [1 :d]])
14:58clojurebot[[[0 :a] [1 :b] [5 :c] [8 :d]] 9]
14:58rhickey,(reductions + (range 5))
14:58clojurebotjava.lang.Exception: Unable to resolve symbol: reductions in this context
14:58rhickey(clojure.controb.seq-utils/reductions + (range 5))
14:58rhickey,(clojure.controb.seq-utils/reductions + (range 5))
14:58clojurebotjava.lang.ClassNotFoundException: clojure.controb.seq-utils
14:59rhickey,(clojure.contrib.seq-utils/reductions + (range 5))
14:59clojurebotjava.lang.ClassNotFoundException: clojure.contrib.seq-utils
14:59Chouser,(use 'clojure.contrib.seq-utils)
14:59clojurebotnil
14:59rhickey,(reductions + (range 5))
14:59clojurebot(0 1 3 6 10)
14:59ambientnifty :)
15:00Chouserthe problem in this case is you're off by one
15:00Chouser,(reductions (fn [[p v] [d v]] [(+ p d) v]) [[1 :a] [4 :b] [3 :c] [1 :d]])
15:00clojurebot([1 :a] [5 :b] [8 :c] [9 :d])
15:01Chouser:b should start at time 1, not 5. 5 is when :b should end and :c should start.
15:05Chouser,(map (fn [[[t] [_ v]]] [t v]) (partition-all 2 1 (concat [[0]] (reductions (fn [[p] [d v]] [(+ p d) v]) [[1 :a] [4 :b] [3 :c] [1 :d]]))))
15:05clojurebot([0 :a] [1 :b] [5 :c] [8 :d] [9 nil])
15:05Chouserdestructuring ftw!
15:07LauJensenftw?
15:08ChouserFor The Win!
15:08LauJensenah okay
15:09ambient(map #(- % (second (first phr))) (reductions + (map second phr))) seems to work ok :)
15:10Chouserambient: heh. well, that's better.
15:10ambientbut thats not the best way to do it i think
15:14ambient(all-but-the-last (reductions + (map second (cons [0 0] phr-melod-1))
15:15ambientno.. (all-but-the-last (cons 0 (reductions + (map second phr))))
15:16Chousukeall-but-the-last is called butlast :P
15:16ambientok, good to know
15:16Chouseror drop-last
15:17Chouserdrop-last is lazy, butlast is not.
15:23ankouhi again, is there a possibility to use string manipulation with symbols or how are the .javaShortFunctionCalls created?
15:24hiredmanhuh?
15:25Chouser,(str 'foo) ; like this?
15:25clojurebot"foo"
15:25hiredman,(name 'foo)
15:25clojurebot"foo"
15:25Chouser,(symbol (str "." "foo" "Bar")) ; or like that?
15:25clojurebot.fooBar
15:26ankouoh great :D
15:28Chousukeankou: if you need it in a macro you can just use . directly
15:34ambient (partition 2 (interleave (map first phr)
15:34ambient (drop-last (cons 0 (reductions + (map second phr)))))))
15:34ambientisnt very pretty :/
15:34ambientbut gets the job done
15:35LauJensenambient: thats kinda funny because I've heard Chouser described that exact way by his employer
15:35ambienthehe
15:38ambientin an imaginary language the problem would be about: new second element = accumulate old from 0
15:39ambienthow that could be expressed in sexps is beyond me
15:40hiredman(-> phr ((partial map second)) ((partial reductions +)) ((partial cons 0)) drop-last)
15:41Chousuke:P
15:42Chousukethat's just ugly.
15:42hiredman(comp drop-last (partial cons 0) (partial reductions +) (partial map second))
15:42hiredmanChousuke: hardly
15:42Chousukethe latter is much better.
15:43Chousukethe first one is just abuse of ->
15:43Chousukeit happens :)
15:44ambientcomp/partial, seems useful
15:44Chousukemostly the weird double parentheses offend me.
15:44hiredmanwhenever I play around try to work out a function in a repl it always turns into a big long -> expression
15:44hiredmanyou get used to the double parens
15:45ChousukeI don't use partial that much either
15:45LauJensenChousuke: Did you catch this anonymous contribution?
15:45LauJensen,(reduce #(let [i (rand-int %2) j (dec %2)] (-> %1 (assoc i (%1 j)) (assoc j (%1 i)))) [1 2 3 4 5] (range 5 1 -1))
15:45clojurebot[2 1 3 5 4]
15:46hiredmangnarly
15:46Chousukeit's better in haskell because of autocurrying
15:46Chousukebut I like being explicit.
16:16angermanhow would I nuke all lines from a string that start with %.... ?
16:17angermane.g. I have a file that uses % as comment indicator
16:18tomojangerman: you read the entire file into a string? or a seq of lines?
16:18ankouis there a function to expand inner lists? something which makes ((1 2) (3 4)) to (1 2 3 4)?
16:18angermantomoj: I read the whole file it's not that large
16:19angermantomoj: but I guess it's like (split on \n resp \r\n)
16:19angermanfilter the lines and glue it back together.
16:19hiredman,(doc line-seq)
16:19clojurebot"([rdr]); Returns the lines of text from rdr as a lazy sequence of strings. rdr must implement java.io.BufferedReader."
16:20hiredman,(remove #(re-find #"^%.*$" %) ["foo bar baz" "%foo" "bar"])
16:20clojurebot("foo bar baz" "bar")
16:21angermanhiredman: thanks. that looks not too bad :)
16:21tomojeh
16:22angermanwell I guess I screwed up :...
16:22tomojwhy use a regular expression to do .startsWith?
16:23angermanhm line-seq really wants a BufferedReader... slurp's so nice
16:23tomojI guess if whitespace is allowed before the % then a regular expression becomes more useful
16:23hiredmantomoj: *shurg*
16:23tomoj#"^\s*%" ?
16:26angermanhmm.
16:26angermanmaybe I should tackle the problem from a differnt side
16:26angermanmy file consists of blocks separated by two new lines.
16:26angermanand there may be lines in there that start with %. so all I need at first is just the blocks as a sequence.
16:27angermanmy first thought was: break file into lines, remove all those that startwith %, glue back together and split on \n\n
16:31hiredman,(doc partition)
16:31clojurebot"([n coll] [n step coll] [n step pad coll]); Returns a lazy sequence of lists of n items each, at offsets step apart. If step is not supplied, defaults to n, i.e. the partitions do not overlap. If a pad collection is supplied, use its elements as necessary to complete last partition upto n items. In case there are not enough padding elements, return a partition with less than n items."
16:31hiredman(comp (partial partition 2) line-seq)
16:31hiredmanor something
16:49angermanwhat would be a lisp way to scan a list and when one finds a symbol takes all that has been scanned a turns it into a list, from there on starts with a second list and so on
16:50angermane.g. (... "a" ... ... "a" ... ... "a" ... ...) -> (( ... ) (... ...) (... ...))
16:51ambientsplit?
16:51angermanwould still have to scan the last (... ...)
16:51ambientthat oddly reminds me of cartman
16:51hiredmanreduce
16:51angermanambient: well the symbol is actually two in a row. so I though about using peek
16:52hiredmanif you are parsing stuff, you could just, you know, using a parsing library like fnparse
16:52hiredmanof course fnparse apears to be under "heavy developement" at the moment
16:52hiredman:/
16:53hiredman~fnparse
16:53clojurebotPardon?
16:53hiredman~parse
16:53clojurebotparser is http://github.com/joshua-choi/fnparse/tree/master
16:59angermanso basically I can use fnparse to construct me a tree like structure?
17:01ambientanyone know how i can easily manage additional java libraries in emacs?
17:01ambientor must i always change .emacs by hand
17:01hiredmanangerman: you can use it to parse things
17:03angermanhiredman: ok. I guess I'll look a lot deeper into that.
17:06powr-tocambient: if you use a script to start clojure, you can have that script consult a .clojurerc file which contains a classpath decleration
17:08nsinghal(let [{:keys [a b & ss]} {:a 1 :b 2 :c 3 :d 4}] ss)
17:08nsinghalI am trying to capture rest of map in "ss" (other than a & b). How can i do that?
17:09Chousukehm, you can't do that, but you can have access to the whole map.
17:09hiredman,(dissoc {:a 1 :b 2 :c 3 :d 4} :a :b)
17:09clojurebot{:c 3, :d 4}
17:09ambienti got (0 250 500 750 1000), how do i get (250 250 250 250)?
17:10Chousuke,(let [{:keys [a b c] :as m} {:a 1 :b 2 :c 3 :d 4}] [a b c m])
17:10clojurebot[1 2 3 {:a 1, :b 2, :c 3, :d 4}]
17:10hiredman,(repeat 4 (second '(0 250 500 750 1000)))
17:10clojurebot(250 250 250 250)
17:11ambient:p yeah.. im actually looking for the differences
17:11ambientbut i think it will come to me after a while, i shall save my "points" for asking actually difficult questions
17:12nsinghali thought it wont work - but still was worth a try to ask
17:13tomoj,(map (fn [[a b]] (- b a)) (partition 2 1 '(0 250 500 750 1000)))
17:13clojurebot(250 250 250 250)
17:13nsinghalit will be nice to have that - validating map input might become easy. (defn [{:keys [a b & ss]}] (when-not ss ...)
17:14hiredman,(map #(- %1 (* %2 250)) '(0 250 500 750 1000) (iterate inc -1))
17:14clojurebot(250 250 250 250 250)
17:17bostwickHi
17:18bostwickDoes anyone have experience with the clojure plugin for eclipse?
17:19bostwickI'm writing a program to do some xml processing, and when I attempt to print a hash representation of my xml from the repl, eclipse freezes
17:24tomojseems like a "mapply" might be useful sometimes
17:25tomojlike, map, but instead of calling the function on each element, apply the function to each element (where each element is a seq itself)
17:26replacayou mean like (map (partial apply f) ...)?
17:27tomojguess so
17:27replacaI agree with whoever said earlier (Chosuke?) that they missed "auto-currying from Haskell
17:27tomoj,(map (partial apply #(- b a)) (partition 2 1 '(0 250 500 750 1000)))
17:27clojurebotjava.lang.Exception: Unable to resolve symbol: b in this context
17:27replacait would be nice to have comp and partial be a little more natural
17:27tomojerr
17:28tomoj,(map (partial apply #(- %2 %1)) (partition 2 1 '(0 250 500 750 1000)))
17:28clojurebot(250 250 250 250)
17:28tomojyup
17:28Chousukepartial apply?
17:28broolreplaca: yah, i would like that as well
17:29replaca(defn mapply [f & rest] (map (partial apply f) rest))
17:29replacaI think
17:30tomojbut then all the seqs are in a seq
17:32Chousukesome reader syntax for comp or partial might be nice... but is there anything left? :P
17:35ambienti need to separate items in a list like [4 4 4 3 3 1 1 1 1] -> [ [4 4 4] [3 3] [1 1 1 1] ] any easy way to do this?
17:35ambientive been browsing the API but my eyes start to water
17:37Chousuke(doc group-by)
17:37clojurebot"([f coll]); Returns a sorted map of the elements of coll keyed by the result of f on each element. The value at each key will be a vector of the corresponding elements, in the order they appeared in coll."
17:38Chousukehm not that.
17:43tomojambient: my attempt: http://paste.lisp.org/display/86466
17:44ambienttomoj, well that was my backup plan if there weren't any short combination of existing functions :)
17:46tomojseems like a weird thing to do
17:46ambientnot so weird when its part of a larger thingie
17:46ambient((9 35 0) (4 60 0) (4 0 250) (4 64 250) (9 0 500) (9 38 500) (4 0 500) (4 60 500) (4 0 750) (4 65 750) (9 0 1000) (4 0 1000)) i need to group this by the last items
17:47tomojoh
17:47tomojthat's different
17:47tomoj:)
17:47tomojI was thinking it was weird because having [1 1 1 1] seems silly if you know that they're all the same anyway
17:48ambientbut i can just (map #(weird-thingie (last %)) myseq)
17:48ambienthmm wait
17:49tomojyou can just use my split-groups except pass a function in to use instead of just doing plain =
17:49ambientim still trying to come up with a higher level solution
17:50tomojgroup by works but it gives you something different
17:50ambientbut i got your version saved for future reference
17:50tomojdepends on if order matters
17:50ambientorder matters
17:50tomojwithin a group only? or you need the groups in the right order too?
17:50hiredman,x
17:50clojurebot((9 35 0) (4 60 0) (4 0 250) (4 64 250) (9 0 500) (9 38 500) (4 0 500) (4 60 500) (4 0 750) (4 65 750) (9 0 1000) (4 0 1000))
17:50hiredmanvals (reduce (fn [map group] (update-in map [(last group)] conj group)) {} x))
17:50hiredmaner
17:51hiredman,(vals (reduce (fn [map group] (update-in map [(last group)] conj group)) {} x))
17:51clojurebot(((4 0 1000) (9 0 1000)) ((4 65 750) (4 0 750)) ((4 60 500) (4 0 500) (9 38 500) (9 0 500)) ((4 64 250) (4 0 250)) ((4 60 0) (9 35 0)))
17:51tomojwat
17:51tomojoh, that's just like group by though, right?
17:51ambientwell those are instrument events (channel note time-location)
17:51ambientwhen note = 0 its note off
17:51tomojI mean, wrong order
17:52hiredmanby grouping you are changing the order
17:52hiredmanI don't see how you can expect to keep an order
17:52ambientmain thing is that note-offs dont come after the note-ons in the same time-slot
17:52tomojuhh
17:53hiredman,(vals (reduce (fn [map group] (update-in map [(last group)] conj group)) (sorted-map) x))
17:53clojurebot(((4 60 0) (9 35 0)) ((4 64 250) (4 0 250)) ((4 60 500) (4 0 500) (9 38 500) (9 0 500)) ((4 65 750) (4 0 750)) ((4 0 1000) (9 0 1000)))
17:53ambientit can be explicitly defined though
17:53tomoj[4 4 4 4 3 3 3 1 1 1] -> [[4 4 4 4] [3 3 3] [1 1 1]] ?
17:53tomojah, that works
17:53hiredmantomoj: his sample is not ordered that way though
17:53hiredman,x
17:53clojurebot((9 35 0) (4 60 0) (4 0 250) (4 64 250) (9 0 500) (9 38 500) (4 0 500) (4 60 500) (4 0 750) (4 65 750) (9 0 1000) (4 0 1000))
17:54hiredmanoh, it is, anyway
17:54ambientnote-on note-off only matters in the same channel, which is the first val
17:54hiredmanyou would map a sort function over each group
18:14lisppaste8ambient pasted "split-groups" at http://paste.lisp.org/display/86467
18:14ambienti did scheme-y version of it that maintains order
18:14ambientit's pretty simple, but i dont know what patterns can be extracted from that
18:21ambientnvm.. i need to sleep
18:21slyrus_I get a bunch of errors like this: [java] java.io.FileNotFoundException: Could not locate clojure/stacktrace__init.class or clojure/stacktrace.clj on classpath: (jmx.clj:10)
18:21slyrus_when trying to build clojure-contrib
18:21slyrus_should I worry?
18:22ambienti usually have to tell clojure.jar path manually to ant: ant -Dclojure.jar=../clojure/clojure.jar
18:37slyrus_ambient: yeah, I did that... it fails earlier if I don't do that
19:35rhickeyput Clojure data directly into RDF triple store: (store-root #^{:woo :hoo} {:a 1 :b 2 :c #{3 4 5} :d {:e 6 :f [7 8 9]} :g [1 2 3] :h "ten" :i 10.42})
19:37rhickeyreload and recover full structure in a single call
19:37rhickeyorg.clojure.rdfm=> (reload (::id ^*1))
19:37rhickey{:i 10.42, :h "ten", :g [1 2 3], :d {:f [7 8 9], :e 6}, :c #{3 4 5}, :b 2, :a 1}
19:38rhickeyorg.clojure.rdfm=> ^*1
19:38rhickey{:org.clojure.rdfm/id #<URI urn:uuid:13e52fec-ce9b-4060-bc64-5d02792495fa>, :woo :hoo}
22:10tomojwhat's the "triple" there?
22:15hiredmanhttp://www.thelastcitadel.com/images/prolog.jpg <-- $2 at goodwill
22:25tomojis there a "clojure monads for dummies" out there?
22:26tomojI am tremendously confused by both of the intros I've tried to read
22:26hiredmanmonads are confusing
22:38tomojmaybe I should just finally learn haskell
23:33technomancyso I'm trying to use update-proxy to provide a proxy with a map of methods.
23:33technomancyI'm using zipmap to turn the keyword keys into strings, and that works fine
23:34technomancyI also want to wrap the fn values in the map in another map, but I get a strange ClassNotFoundException when I try it.
23:34technomancyhttp://p.hagelb.org/applet.clj.html
23:34technomancy^ if I replace the bind-applet with identity in the zipmap, it works fine
23:39technomancyit looks like if bind-applet returns a named function it works, but returning an anonymous function breaks
23:41technomancyeven stranger: returning a named function from clojure.core or clojure.xml works, but returning a named function from my own namespace or from contrib breaks.
23:44hiredmansounds like a classloader issue