#clojure logs

2009-04-23

00:48lisppaste8cark annotated #79053 "this one is working" at http://paste.lisp.org/display/79053#4
00:50replacayou're parsing binary data into maps?
00:50Carkyes
00:51Carkthat's gnuvince's project
01:03replacacool
01:03replacathat's a useful idea
01:03Carki'm not sure clojrue is the best tool for that, but yes
01:04Carkand performance isn't too bad
01:04Cark43 seconds to parse 150Mb of data
01:04replacawell, yeah, but finding very flexible ways to manage serialized data is interesting
01:05replacaI have nothing to compare that to, so it seems good to me :-)
01:05Carki don't know, i always use sexprs for that =P
01:05replacagreat if you've got lisp at the other end
01:05Carkwell it's easy to parse anyways !
01:06replacaless great if you have, say, images or video streams in the mix
01:06Carksure
01:06replacain my day job, we have distributed systems that often run over severely bandwidth restricted networks
01:06replacaso every bit counts
01:07Carkwell then you can compress your stream
01:07replacaif you get it compressed better, you can send more and deliver a better user eexperience
01:07replacayeah, we do that too
01:07Cark(not talking about video of course)
01:07Carkdo you get better results by compressing binary data ?
01:08replacayeah, cause even binary data isn't fully compressed
01:08replacai'm sorry-> evenly distrubyted
01:08replaca*distributed
01:08replacacause a bunch of it ends up being text
01:09Carkah i see
01:09replaca(not the video, but other stuff
01:09replacaand when it's not text, it's biased low (1s and 2s far outweigh 254s and 255s) even after we do minimum byte int compression
01:10replacaso basically, we do every trick in the book :-)
01:10Carkheh must be interesting
01:10replacaand we're adding more (adaptive video encoding, etc.)
01:11replacayeah, it's fun. I mostly do architecture and management at work, so I don't get to code too much
01:11replacathough I have done most of the compression and bandwidth management/allocation stuff
01:12replaca(but Clojure ends up being my coding outlet :-))
01:13Carkit's a nice lisp
01:13Carkbut the java stuff is sometimes killing me
01:13hiredman~clojure
01:13clojurebotclojure is the best way to learn java
01:13hiredman~botsnack
01:13clojurebotthanks; that was delicious. (nom nom nom)
01:14Carkclojuebot is very wise
01:14replacajava is both a blessing and a curse, no doubt
01:14hiredmanone out of eleven shot that factiod would come up
01:14hiredman~literal [?] clojure
01:14clojurebot11
01:20Cark~def sort
01:28Carki wonder why there's not a version of reduce with more than one calletionc, is the same fashion as map
01:28Carkis/in
01:50replacathe idea behind reduce is that you're "squishing" down a collection, whereas map is coollecting function results. That said, I don't why it wouldn't work.
01:52Carkthere are many cases where i need to do ugly destructuring because of this
01:52hiredmanmap+reduce+apply
01:53hiredman(reduce (partial apply somefunction) (map list some collections here))
01:53clojurebotmap is *LAZY*
01:53hiredmanclojurebot: I KNOW
01:53clojurebotHuh?
01:53Carkmhh
01:55Carkthere still is structuring/destructuring under the hood
01:55hiredmanfor where?
01:55Carkthe map form strutures into a list
01:56Carkand the apply destructures the list
01:56Carkbut you're right it's not as ugly
01:56Carki wonder about performances though
01:57hiredmanI doubt it would perform worse then clojure's built in destructuring
01:58hiredman,(doc destructure)
01:58clojurebot"([bindings]); "
01:58hiredman...
01:58Cark~def destructure
01:58hiredman,(destructure '[[a b] [c d]])
01:58clojurebot[vec__2292 [c d] a (clojure.core/nth vec__2292 0 nil) b (clojure.core/nth vec__2292 1 nil)]
02:00Carkuses nth with lists too =/
02:01Carkanyways ...good night !
02:02replacagoodnight!
04:04liwphow do I get the length of a sequence? I can't seem to find a length function in the core API...
04:09cgrandliwp: count
04:09liwpahh, didn't think of that name. I tried to look for length and size. Thanks
04:10liwpHow does one create a Java byte array in clojure?
04:10liwpI tried (into-array Byte/TYPE ...) but that didn't work
04:12liwpI'm trying to use the Java 2d API from clojure and dealing with primitive type arrays is turning out to be painful
04:15liwpFor example, the pixels in this case are represented by signed bytes, but the values are really between 0 and 255. Java code deals with this by using ints to manipulate the pixels and then getting the byte value with byte b = i & 0xFF.
04:40hoeckliwp: try (into-array Byte/TYPE (map byte [1 2 3 4]))
05:10liwphoeck: excellent, that works!
05:12liwpit seems that using (byte) I'm also able to force a 128-255 value into a signed byte, which is exactly what I wanted: (byte 255) -> -1
05:12liwpthansk
06:32jdzcount
06:32jdz(make-array Byte/TYPE 4096)
06:32jdz,(make-array Byte/TYPE 4096)
06:32jdzclojurebot: are you there?
06:32clojurebot#<byte[] [B@bed64>
06:32jdzsilence...
06:32clojurebotexcusez-moi
07:04cemerickThis comment by GvR on side effects really shocked me: http://neopythonic.blogspot.com/2009/04/tail-recursion-elimination.html?showComment=1240451280000#c1726520516547497765
07:07cemerickSure, he's the python guy, so avoiding side effects isn't going to be a priority for him. But I expected at least an acknowledgement that doing so is really, really good (necessary?) in a *lot* of domains (if not all of them in a pervasively multicore world).
07:14eevar2+1 to gvr for correcting the lisp-worlds use of "persistent"
07:16cemerickI'll take Okasaki over GvR w.r.t. data structure terminology.
07:17cemerickand I presume it was originally an ML term, given his usage of it....
07:20eevar2okies, "fp-world" then
08:23gnuvinceGood morning
08:35cgrandgnuvince: hello
08:37gnuvinceQuiet today
08:58cgrand~seen dnolen
08:58clojurebotdnolen was last seen quiting IRC, 376 minutes ago
10:27cgranddnolen: I think it's better to rename the conflicting CSS predicates
10:27cgrand(CSS not is enlive/but)
10:28dnolencool! I wasn't sure if that was a compromise you were willing to make
10:29cgrandare you tracking the master branch now?
10:29dnolenyes
10:29cgrandfine. I already renamed empty to void and put complement into another ns
10:30dnolengreat
10:31dnolencgrand: enlive is moving along at light speed, a tutorial and everything ;)
10:32Chousukeit's really neat though.
10:33cgrandthanks again to Adrian (are you here?) for the tutorial
13:15noidiis there a way to import all the statics from a java class?
13:16noidiI'm trying to get rid of the extra gl's in the moronic JOGL API :P
13:16noidi(let [gl (.getGL drawable)] (.glHint gl GL/GL_PERSPECTIVE_CORRECTION_HINT GL/GL_NICEST))
13:16noidiseriously, who comes up with an API like that >
13:16noidi:D
13:16leafwnoidi: clojure discourages namespace pollution with imports you don't need. That said, there may be a way :)
13:17kotarakthere was a contrib.import-static...
13:18noidikotarak, yeah, I thought I remembered something like that mentioned here
13:18noidithanks :)
13:19noidihmm, it still requires all the statics to be named explicitly
13:20noidiI guess I'll just write a few macros, so I can do (gl Hint (GL PERSPECTIVE_CORRECTION_HINT) (GL NICEST)) instead of the monstrosity above
13:20noidiit's possible to rewrite symbols in a macro, right?
13:21leafwnoidi: still reads quite verbose, and you lose the ability of any java programmer to understand the code
13:22noidibut it's closer to the original API, in which the command would be glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
13:24technomancymaybe it was written by a python programmer who was used to self.repeating self.self all the self.time. =)
13:26rsynnotta lot of C libraries do that sort of thing, as an attempt to be vaguely OO
13:27noidiopengl's not really OO, that's just making up for the lack of namespaces in C
13:34danlarkinyeah it has nothing to do with OO
13:44pjstadig~def keys
14:18durka42auto-documentation?
14:19hiredmanreplaca write something to auto generate docs in the google code wiki
14:19hiredmanwrote
14:20hiredmanhttp://code.google.com/p/clojure-contrib/wiki/OverviewOfContrib
14:21durka42oh, that's cool
14:21durka42makes contrib a lot more discoverable
14:21jwinter_that is cool, e.g. http://code.google.com/p/clojure-contrib/wiki/ZipFilterApiDoc
14:22cadsclojure clojure clo jure bannana fanna fo fojure.... I've got a clojure environment using rlwrap to provide tab completion on symbols, but is there a function that gives me the symbols that are mapped in a namespace, allong with their doc strings, perhaps formatted the same way (doc aSymbol) does it?
14:23durka42there is ns-publics
14:23hiredmancads: clojure.org/namespaces
14:23durka42also perhaps find-doc
14:23kotarakcads: the repl of vimclojure does that, but it's only interesting if you are a vim user...
14:23replacaglad to help! please ignore spurious checkin messages - developing with the google wiki isn't so great
14:23replacabut it's almost all there
14:24cads(doc 'clojure.org/namespace) doesn't work? why not?
14:24clojurebotExcuse me?
14:25hiredmancads: website
14:25hiredmanhttp://clojure.org/namespaces
14:36tetechnomancy: i just saw your bludgeon repo
14:36tebrilliant, sir
14:37tetechnomancy: i have another idea for bludgeon -- could you crush a human skull with the total weight of floppy disks the library occupies
14:38teor perhaps -- could a sock full of floppy disks representative of the library size, be used to beat someone to death?
14:39cemerickwhat's the deal with twibes? Way offtopic, but I just saw cgrand join up, so...
14:39technomancyte: floppy disks... interesting
14:40tetechnomancy: im not sure how big rspec's library is, but i mean, i think a good 10 or so floppies in a sock could effectively be used to kill someone
14:40te20, certainly
14:40te10 could at least provide a serious beating
14:43technomancyte: the main problem I had with that library was integration testing. let's just say there were some serious side-effects that I wanted to avoid at test-time. =)
14:44cadsdoes clojure have a standard that defines it, in terms of a formal grammar definition?
14:45cadsone thing I'll be willing to wager on, if such a thing does not exist yet, it should be easier to produce that in a language such as ruby
14:45hiredmanwell, it's a lisp
14:46cadstrue, we can find personal axioms to understand it by :D
14:46hiredmanlisp grammars are easy
14:46cadsthey are, I've made my own notes :)
14:48cadswho would make a standards document, if it came to that?
15:10Chouserit's likely the clojure reader will eventually be re-written in clojure.
15:11Chouserat that point, if done carefully, the code could act as a spec
15:12hiredmanor you could use fnparse
15:27replacaI've been thinking about a modified reader myself, so that we could pretty print files of coode
15:27replaca*code
15:27replacabut it hasn't gotten past the idea stage
15:27replacacause the regular reader loses comments and metadata annotations
15:40Lau_of_DKJava guys - I have questions!
15:40Lau_of_DK1) Which classes will best solve this: I need to download a website, just get the raw bytes, and the reponse code.
15:44Carki beleive the url class can give you a stream
15:44Lau_of_DKOk, I'll look into it
15:44kotarakaren't duck-streams also handling URL?
15:44Carkbut i don't know about the response code
15:44Lau_of_DKHmm
15:44leafwyes, it can: URL getStream
15:45Lau_of_DKActually - I remember seeing a http client in contrib way back when
15:47replacaLau_of_DK: doesn't seem to be there now
15:47Lau_of_DKThats true
15:50Lau_of_DKAnybody else here had some performance problems with jetty servlets ?
15:50rsynnotta http client, as opposed to a wrapper for the java one, is probably not something that you'd actually want to write
15:50rsynnottall the nasty stuff is already done for you, after all :)
15:51Lau_of_DKOr rather - My second question of the night - Is there a neat way to schedule a load test? Lets say I want 1000 hits per hour, and I want these even distributed - how would I most elegantly set that up ?
16:01replacarsynnott, Cark: yeah, I'd just use the java stuff for that and wrap it in a clj function that does just what you want.
16:09gnuvinceCark: I ran more tests in my VMWare machine with an "heated up" JVM, but the results are largely the same. Like I said, I figure that the speed of IO in VMWare is the cause of the bottleneck.
16:11Carkgnuvince : allright ... i managed to knock off another second off ...but that's meaningless
16:13gnuvinceI get home at around 7:30-8:00 (math homeworks :(, I'll check it out then.
16:14Carki'llo give you the latest code
16:14Carkjust let me know you're back
16:53eevar_Lau_of_DK: httperf?
16:53eevar_with --rate
16:59Lau_of_DKI tried http_load with -rate, but it doesnt support less than 1 second, which I need
16:59eevar_500 = 500 request per second -- or something like that
17:01eevar_or, well.. doesn't seem to be that, but higher number = more load
17:01eevar_--period gives more control
17:06danlarkinLau! I have a sortof-http client library if you want it
17:07danlarkinthat was an oddly placed "sortof"... it is not sortof-http, it is http
17:07rsynnottsort-of library, then? ;)
17:09danlarkincorrect :)
17:10danlarkinI will post it to the mailing list as a submission for contrib once I work out the api more fully
17:17Lau_of_DKdanlarkin: Send me an email on it? I'd really appreciate it
17:17Lau_of_DKI was fiddling with apache's, but since we done have import org.apache. * - it was just a mess
17:17danlarkinhttp://gist.github.com/98612
17:18Lau_of_DKSanks
17:25hiredmanclojurebot: what is the most terrible thing?
17:25clojurebotIn Ordnung
17:25hiredmanclojurebot: the most terrible thing?
17:25clojurebotexcusez-moi
17:25hiredmanclojurebot: the most horrible thing?
17:25clojurebotmost horrible thing is http://tinyurl.com/b65o8e
19:18DrakesonDo you know a powerful plot library that is not too hard to use from clojure?
19:20Drakesonsomething similar to matplotlib for python
19:23eeehello
19:23dliebkejfreechart is an excellent java library, I've wrapped parts of it for my Incanter project. Here's some samples: http://wiki.github.com/liebke/incanter/sample-plots-in-incanter
19:23eeeis there an easy way to get access to the whole contrib namespace?
19:24Drakesoneee: me too :)
19:25eeei'm using clojure-dev, and finding the namespace browser awesome
19:25Drakesondliebke: thanks a lot. that's what I was looking for
19:25eeebut it only shows what's in your namespace now
19:25dliebkegood luck
19:26eeebut specifically I'm looking for the fastest merge, meld, union type implementations
19:26eeemaybe seq-utils
19:30eeei also forgot how you use some new namespace
19:30eeerequire I guess
19:39eeenow i remember. it's (use)
19:51Drakesonhow can I build and use clojure using maven? Do I start by "mvn install" ?
19:53Drakesonman mvn is not informative
19:56DrakesonI did too, but it seems I miss a lot if I don't use mvn (on the java side)
19:57eeeare you forking clojure?
19:57Drakesongod! no!
19:58eeenice reaction :)
19:58Drakesonis using/trying to use mvn imply that?
19:59Drakesons/is/does
20:01DrakesonI said on the java side. downloading .jar files manually in no fun.
20:02eeenot the maven part. I'm just trying to learn what the usefulness is. Either you had to make a change to try something out, or you want to fork, or you want the latest snapshot that isn't built (and so why don't the distributors have a continuous build system upon checkin) or you want it on some little phone device . . . or I am just nosey :)
20:03Drakesonoh, I just don't know how maven works. I am still new to java.
20:04eeewhy do you need to build clojure?
20:04eeewhy does one
20:04clojurebotwhy not?
20:04eeeetc
20:04DrakesonI want the latest clojure.
20:05eeeand they don't have automated build
20:05Drakesoncan I get it without building?
20:05eeei wonder
20:05Carkbuildin is just type "ant <enter>"
20:06eeemaking me think about a git-hub or google repos-like thing that always builds whenever someone does a checkin
20:06DrakesonCarl: then you have to worry about where the .jar goes.
20:06eeeif they don't, that's an opportunity
20:06eeejava-only of course
20:08eeei have a question to ask anyone who is following the google groups discussions for clojure
20:09arohnereee: shoot
20:09eeeis that anyone here right now?
20:09eeecool
20:09arohnera lot of us here are also on the groups
20:09eeei'm posting results about this heap
20:09eeeis it annoying?
20:09eeeor passively interesting
20:09arohnerwhich post is that?
20:10arohneroh, priority queue: some results
20:10eeelatest is this: best way to compete against meld?
20:10eeeyes
20:10eeei just got another result
20:10eeebest of all
20:10eeeand thinking of posting
20:11eeeis it ok?
20:11felzixIs there a way to eval def's first argument?
20:11arohnereee: yeah, keep posting
20:11eeecool
20:11arohnerI know it's discouraging to not get any responses
20:11arohnerit's happened to me several times
20:11eeei just merges two sorted sets
20:12eeeand then two heaps
20:12eeecheck this out
20:12eeeperforming union of two sorted sets "Elapsed time: 18881.81 msecs" making another heap performing meld of two heaps "Elapsed time: 0.146 msecs"
20:12arohnernice
20:12eeeahhhhh
20:12eeefeedback
20:12eee:)
20:12arohnerone piece of advice is that it's slightly hard to follow the topic when you have several different threads
20:12eeeoh
20:12arohnerreply to yourself in one thread just to keep the context around
20:12eeeok
20:13eeei'll add to the last results email then
20:13felzixlike using set instead of setq in CL
20:13eeeno
20:13eeeset means a uniquified list like thing
20:13eeenoun
20:14eeenot verb
20:14arohnerfelzix: I don't know enough CL to know what you're asking
20:14eeesetq
20:14eeemeans def
20:14arohnerthe first argument to def is the symbol name you want to point at the new var
20:14eeeor something like that
20:14eeeyeah
20:14eeeso he thinks of "set" the verb
20:14eeeto set
20:15arohnerso I don't understand what you mean by eval'ing it
20:15eeewe mean the datastructure
20:15eeewho said eval?
20:15felzixsay, (let [a 'b] (def a 9)) resulting in b == 9
20:16eeeoh I missed it
20:16arohnerah, ok
20:16eeei see
20:16arohneryou could do that with a macro pretty easily
20:17arohneractually, you might not even need the defmacro, just the backticks
20:17arohnerthough, why do you want to def inside of a let? that creates a new global
20:17unlinkHow do I serialize my Clojure objects efficiently?
20:17Raynes``
20:18felzixarohner: Ah, you're right, extremely easy to make.
20:18unlinkLike protobuf, cPickle, or memcpying structs in C.
20:19arohnerfelzix: though be careful with that. It's generally frowned upon to change the value of a var using def in running code
20:19unlinkDid I just answer my own question? protobuf supports Java.
20:19arohnerreally the only reason you're allowed to re-def a var is for development purposes
20:20felzixarohner: I'm using it in a define-class macro to make boilerplate functions.
20:21arohnerfelzix: that sounds appropriate then
20:21felzixcool. Thanks for the help!
20:22eeek, made my new post
20:22eeethanks for the encouragement
20:23gnuvince_Doe all aset functions go through the reflection framework?
20:24eeei don't know what aset is
20:24eeeso I can't help
20:24rhickey_eee: I don't think sorted collections negate the value of heaps in any way, heaps serve some unique purposes
20:25eeethanks rich
20:25gnuvince_eee: setting values to an array
20:25eeedid you see the last result?
20:25eeeawesome
20:26eeei just need to figure out decreaseKey()
20:26eeein functional setting
20:26unlinkgnuvince_: http://code.google.com/p/clojure/source/browse/trunk/src/jvm/clojure/lang/RT.java
20:26eeewithout backpointers
20:27eeeoh yeah gnu
20:27eeeI forgot about aset
20:28rhickey_eee: I'm sorry I haven't had time to look at your stuff yet. One word of advice I'd have, is that you'll find papers on purely functional implementations, but you are not limited to that in making a functional persistent data structure for Clojure. Mutation of temporaries, or one-time setup during insertion is a critical component to the speed of Clojure's maps/set/vectors.
20:29eeeok
20:29eeeI was thinking about that
20:29rhickey_no backpointers though :)
20:29eeeyeah
20:29rhickey_and no mutation after init
20:29eeeok
20:30eeecan you explain that with one more sentence. the init meaning what happens at 'new' time, right?
20:30eeewhen the type is established
20:30rhickey_but if you look at PeristentHashMap et al you'll see that new arrays are created and mucked with on inserts/deletes
20:31rhickey_eee: creating any new version, you can create some *new* component of the data structure, mutate it, then weave it into the result, but once returned never to change again
20:31eeeyeah
20:31eeei do that a lot
20:31eeewell
20:31eeeminimum needed
20:32eeethat I can tell
20:32eeeso I think I'm following the rules
20:32eeewill look at PHashMap though
20:33eeethanks for the pointers
20:33eeeno pun intended
20:33eee:)
20:38eeethe PeristentHashMap looks somewhat like what I had one or two versions ago with all the static functions in the implementation file. But I shaved of a little time consolidating. maybe I should put it back since it was negligable, hmmmmm
20:38unlinkgnuvince_: here is the implementation of evens I was trying to accomplish yesterday: http://gist.github.com/100253
20:38unlinkevens2
20:40eeeunlink: intersting
20:40DrakesonI am getting: Could not find clojure.lang.Compile. is that gone?
20:41dnolennope, Drakeson are you trying to compile clojure-contrib?
20:41unlinkexercise for the reader: use recur
20:41Drakesonno, incanter
20:41eeeunlink: would look almost the same, right?
20:42dnolenperhaps you need to explicitly pass the path to clojure.jar to ant? you have to do this contrib.
20:43unlinkeee: well, evens2 is not in tail position
20:43Drakesonlike -Dclojure.jar=... ?
20:43eeedoes this help with compiling? http://www.lithinos.net/Compiling-Clojure-applications-using-Ant.html
20:44dnolenant -Dclojure.jar ../clojure/clojure.jar
20:44dnolenwith whatever your path is tho.
20:46gnuvince_unlink:
20:46gnuvince_user=> (take 3 (evens2 (iterate inc 1)))
20:46gnuvince_()
20:48unlinkoh looks like I wasn't actually testing the function.
20:49eeerhickey_: I actually wondered if there could be a drastic speedup as multi-core computers come on line. The way there's a separate thread for GC, maybe there should be a separate thread for object pools. so the *new's* could be predicted and created in advance in another thread.
20:49clojurebotfor is not a loop
20:49eeegnuvince_: I think it's even items in the list
20:50eeeoh
20:50eeeyou cakked his evens2
20:50eeei didn't see you define it
20:50eeei thought you used clojurebot
20:51cadsdo you guys think I could embed the semantics for simple PIC microcontroller C code (simple loops, even gotos (eww), very shallow recursion, lookup tables), into a clojure DSL, for a simple code generation framework using CLJ syntax?
20:52eeei wonder if that relates to something I saw, cads. I'll remember in a sec
20:52unlinkgnuvince_: you have to do (apply evens2 (take 3 (iterate inc 1)))
20:52eeenestedvm
20:53eeehttp://nestedvm.ibex.org/
20:53gnuvince_unlink: you got a stack overflow too
20:54unlinkgnuvince_: if you try to apply iterate you will
20:54arohnercads: why not?
20:55arohnerI was looking at the mini-VM from the ICFP from a previous year, and it didn't seem that bad to do it in clojure
20:56lisppaste8gnuvince pasted "Lazy evens" at http://paste.lisp.org/display/79106
20:58arohnerunlink: it's a neat trick, but what is the point?
21:01unlinkarohner: I find it to be the most natural way of expressing it
21:01unlinklike haskell/sml's pattern matching
21:01gnuvince_Except Clojure has no pattern matching, so it's kind of futile to try and replicate that style.
21:02unlinkIt has arity overloading, so no, it isn't.
21:02arohneroh that reminds me, why isn't there a function for the sequence of ints?
21:02arohnerdoing (iterate inc 0) all over the place bugs me
21:03dnolenwell not totally true, between multimethods, multiple arity, and destructuring bind you have quite a few good ideas from pattern matching.
21:03gnuvince_unlink: but you need to use apply to call the function instead of the normal form.
21:03gnuvince_arohner: not that I know of.
21:03arohnergnuvince_: I know there isn't a function for that. That's the problem :-)
21:04gnuvince_arohner: define a natural functioN?
21:05dreish,(map first (partition 2 [0 1 2 3 4 5 6 7 8]))
21:05clojurebot(0 2 4 6)
21:06gnuvince_,(take-nth 2 (rest [0 1 2 3 4 5 6 7 8]))
21:06clojurebot(1 3 5 7)
21:06eeewait, is this a function to find the even valued things? or even position things?
21:06dreishPositioned
21:07gnuvince_It's a function to extract the even-indexed elements in a 1-indexed collection.
21:08eee,(map first (partition 2 [1 0 3 4 2 5 6 7 9 11 13]))
21:08clojurebot(1 3 2 6 9)
21:08eeenice
21:08eeehow's it work
21:08dreishpartition 1 2 avoids dropping the last one if there are an odd number. Or you could just use take-nth
21:09dreish,(partition 2 (range 10))
21:09clojurebot((0 1) (2 3) (4 5) (6 7) (8 9))
21:10eeehandy function
21:11dreish,(partition 3 1 (range 10))
21:11clojurebot((0 1 2) (1 2 3) (2 3 4) (3 4 5) (4 5 6) (5 6 7) (6 7 8) (7 8 9))
21:12eeecool
21:13eee ,(partition 3 3 (range 10))
21:13eee,(partition 3 3 (range 10))
21:13clojurebot((0 1 2) (3 4 5) (6 7 8))
21:13eeethat's power
21:20eeei think I found the decreaseKey() answer!
21:20eeei'd forgotten about it
21:20eeeEurika
21:21Jedi_Stanniswhat was the question?
21:22eeemaking a heap/priority queue ... functional
21:22eeein java
21:23eeemeld, insert, findMin, deleteMin ... ok
21:23eeebut
21:23eeecan't do things like Branch and bound, A-Star, shortest path, Prim's alg . . .without decreaseKey
21:24eeeend of soliloquy
21:25Jedi_StannisI see
21:26Jedi_Stanniscode online anywhere?
21:26eeeyeah
21:26eeeone sec
21:26eeehttp://code.google.com/p/jc-pheap/
21:26eeehttp://code.google.com/p/jc-pheap/source/browse/#svn/trunk/jc-pheap/src
21:28eeewell now I see a problem with what I was just thinking. false Eurika
21:29Jedi_Stannisso is the idea to be able to use this data structure from within clojure?
21:29eeeyup
21:29eeethere;s a clojure test in there
21:29Jedi_Stannisany reason you wrote in java instead of directly in clojure?
21:29eeehaven't tried that yed
21:29eeeyet
21:29eeebut i have a paper somewhere on treaps
21:30eeethat maybe will work like that
21:30eeefigured it would be faster
21:30eeeand Rich suggested it, too
21:30eeebe back in a few
21:33eeeback
21:36eeei think the trick is
21:36eeethat somehow you leave the old value where it was
21:36eeeand clone the object inserting it anew
21:37eeewhen the deleteMin gets to the old one
21:37eeeit skips it
21:37eeebut . . .one problem is that that sounds amortized
21:37eeeand another problem is that the clone messes with "identity"
21:38eeeso at the very lease you gotta do a secret mutable swap
21:38eeebut no
21:38eeedepends on if two clients can have a handle to the same node
21:38eeebut they can't so maybe it will work.
21:38eeeend of soliloquiy 2
21:39eee:)
21:47Jedi_Stannisinteresting
21:47Jedi_StannisI don't think I know enough about priority queues to fully appreciate all of this
21:47eeethe brodal paper is in the code repos
21:48eeeWAY easier than his imperative version
21:48eeei had all that straight at one time
21:48eeei like data structures a lot
21:49Jedi_Stannisyeah, I haven't explored data structures too deeply
21:49eeeknow what a splay tree is? That's awesome. so is disjoint set
21:49Jedi_Stannisnope
21:50Jedi_Stannismain advantage of these is their running time for certain operations?
21:50eeein some shops, for what they are doing, machines are fast enough just to use vectors everywhere, sadly
21:50Jedi_Stannisyeah
21:50eeerun time and organization
21:51eeedisjoint set is an easy example to appreciate
21:51eeeif you are interested I could try
21:51Jedi_Stannisif you had functional versions of other collections that have different trade offs that could all be used in clojure, that would be pretty cool
21:51eeebe back in a sec
21:52eeeback
21:53eeeso with disjoint set. you may start with 300 sets each with one element
21:53eeeat some point, you may decide that two such elements should be in the same set
21:54eeebut only if they aren't already in the same set
21:54eeeor you just might want to ask if two elements are in the same set
21:55eeeor what set is an element in and have some sort of VALUE that distinguishes that set
21:55eeeif you try to do that with linked lists
21:55eeeyour done
21:55eeeyou'll spend so many cycles updating links
21:56eeeunder lots of join operations, the identities of two sets have to meld into one
21:56eeeTarjan solved it
21:56eeedisjoint sets
21:56eeegood stuff
21:56eeesmallest algorithm/data structure ever, too
21:56Jedi_Stannissounds interesting
21:57Drakesonis there a mechanism to unpack jars and "install" them in a local or system-wide (/usr/lib/...) place (plus updating some index) and have a classloader that uses the extracted jars and the index?
21:58eeeyou mean in java?
21:58eeejar -xvf some.jar
21:58gnuvince_~seen Cark
21:58clojurebotCark was last seen in #clojure, 113 minutes ago saying: buildin is just type "ant <enter>"
21:59eeebut it won't make stuff know about them like libs . . . unless you have a CLASSPATH environment variable set
21:59eeeand in that case, no need to unpack them
22:00DrakesonI don't understand why java unpacks jars everytime it wants to use them.
22:00Jedi_Stannisis there a list of all the clojurebot commands somewhere?
22:01durka42there is his source code :)
22:01Jedi_Stanniswhere's that at?
22:01DrakesonJedi_Stannis: look at http://github.com/hiredman/clojurebot
22:01eeeoh I didn't know the source was bundled, cool
22:02eeeoh
22:02eeei missunderstood again
22:02eee:)
22:04eeethe other reason to do data structures in java I just realized is to give them to non-clojure people, too
22:04eeelike scala, I guess
22:04durka42clojurebot: where do you live?
22:04clojurebotTitim gan �ir� ort.
22:05durka42clojurebot: where are you?
22:05clojurebothttp://github.com/hiredman/clojurebot/tree/master
22:05Jedi_Stannislol
22:05eeeclojurebot: hello
22:05clojurebotBUENOS DING DONG DIDDLY DIOS, fRaUline eee
22:05Jedi_Stanniswow
22:05eeelol
22:18eeei'm confusing myself
22:18eeein a purely functional world
22:19eeewhat would it mean to decrease the value of something, anyway?
22:19chessguyreturn the successor of it
22:19chessguyerr, predecessor
22:19chessguydecrease 2 == 1
22:19eeebut, like from java it would be a new object, right?
22:20eeesince Integers are immutable
22:20chessguyif you want immutability, yes
22:20eeeyou'd just get a new Integer
22:20eeethat you would think of as the old integer
22:20eeeso
22:20chessguywell no
22:20chessguyyou'd probably call it something else
22:20eeewell, in a priority queue
22:21eeeyou stick something in
22:21eeeand later
22:21eeeyou decide
22:21eeeno, I got the value wrong
22:21eeeI want to udate it
22:21eeelet it bubble up the queue
22:21eeebut "it"
22:21eeeis fuzzy
22:21chessguyyou would return a new queue then
22:21eeeyes
22:21Jedi_Stannis,(-> {} (assoc :a 10) (assoc :a 1))
22:21clojurebot{:a 1}
22:21eeebut the user needs a handle to their object
22:22eeeso they can mess with the value
22:22eeebesides a handle to te queue
22:22eeethe idea of a handle is fuzzy
22:22chessguywell if they can only mess with the value, and it changes in the queue, then you're breaking referential transparency
22:22eeein an immutable world
22:23eeeanyone else seing queue, I realize still needs the old queue
22:23eeebut the notion of a position where the value this guy is tracking needs to be there some how
22:23eeein his new view
22:23chessguyperhaps what you want is a zipper?
22:24eeehmmm
22:26eeewhen you stick something in the heap, you need the new heap and some sort of way to refer to your inserted item
22:26chessguya zipper would do that
22:27Jedi_Stannisis it possible to have the same value in the heap multiple times?
22:27eeeif you stick 5 2's in . . . only one of those 5's is yours, but I wonder if it even matters which one you decrease. I think it does matter if you have other data hanging off it that isn't part of the comparison
22:28eeeyes
22:28chessguyare you only ever going to be updating the one you last put in?
22:29eeeif I figure it out. by the way, this code is in java . . .for clojure use
22:29Jedi_Stanniscan you specify the old priority also?
22:30eeegood question
22:30eeei guess in an immutable world, you could have both handles
22:30eeewhich means that you should have the version of the queue that goes with it
22:30Jedi_Stannisthen even if there were multiple values, as long as you change the one with the right priorirty your good
22:30eeesounds reasonable
22:31eeethe "as long as you" part is the worrysome part tho
22:31eeeyou've got your item and you've got a snapshot of the queue
22:31eeeyou do decreaseKey and get a new item and a new queue?
22:32eeeso you need a unique handle/key to the item as a receipt
22:32eeeand maybe that key is only valid in one snapshot of the queue
22:33eeei shouldn't say key
22:33Jedi_StannisI don't think you need a unique key
22:33eeethat's the comparator . . i mean ID
22:33Jedi_Stannisthink of it in terms of the current clojure data items
22:33eeeyou need a unique ID only if you have objects
22:33eeethose objects could have many fields
22:34eeebesides your comparison field
22:34eeeyou don't want to decrease the wrong object
22:34eeejust because the comparison field matches right?
22:34Jedi_Stannishmm
22:34Jedi_Stannisway not just use clojures data type semantics
22:34Jedi_Stannisthe value is the identity
22:34eeei see
22:34Jedi_Stannisthe entire value is the "comparison field"
22:34Jedi_Stannisdon't use identity anywhere
22:34Jedi_Stannisonly use value
22:35Jedi_Stannisif the value is the same, they are equal
22:35eeeRich has an essay on that
22:35Jedi_Stanniscache hashes to make comparisons fast
22:35eeewell
22:35eeeequal and less than are two different things
22:35Jedi_Stannisdo priorities have to be intergers?
22:35eeeill-defined situation one thing could be not less than and not greater than . . . and STILL not equal either
22:36Jedi_Stannisor priorities can be any object?
22:36eeeno, anything with an order
22:36eeehas to have less than defined
22:36eeeit's not a priority . . .it's a heap . . or a priority queue
22:37Jedi_Stannisso the collection has values in it, which each have a priority associated with them
22:37eeeright
22:37Jedi_Stannisor the priority is inherit to the value itself?
22:37eeefirst thing
22:37Jedi_Stannisok
22:37eeethey implement java comparable
22:38eeecompareTo() is implemented
22:38Jedi_Stannison the value or on the priority?
22:38eeei think your questions are good tho . . .making me think
22:38Jedi_StannisI think you need to decouple the priority and the value
22:38Jedi_Stannislet me give an example
22:39Jedi_Stannissay your using this for a scheduler
22:39Jedi_Stannisand you have 3 processes
22:39eeea heap/priorityQueue has THINGS in it, that can be compared to each other in an order
22:39eeeok
22:39Jedi_Stannisprocess a,b,c
22:39rlbeee: wouldn't an immutable priorty queue just be like any other clojure data structure, i.e. it only makes sense to talk about the "state" that's currently bound to an identity?
22:40Jedi_Stannisand we stick them all in the priority queue with different priorities
22:40Jedi_Stannis<(a,1), (b,2), (c,3)>
22:40Jedi_Stannisnow we want to downgrade a's priority
22:40rlbs/wouldn't/couldn't/
22:41eeethe state of the queue is no problem to understand rlb
22:41Jedi_Stannis(decreaseKey 'a 1 4 *1) --> <(a,4),(b,2),(c,3)>
22:41eeethe queue is defined by what's in it
22:42Jedi_Stannisyou can't have the objects in the prioirty queue have the priority be part of their value
22:42Jedi_Stannisbecause they can't be mutable
22:42eeeok
22:42eeethat's fine
22:42eeebut that's all blowing my mind how hard that is
22:42eeeI almost need a map and a queue
22:43eee s/all/almost
22:43eeeJedi
22:43eeeso
22:44eeein java terms, I'd have an object with two fields
22:44eeein clojure I'd have two objects
22:44eeethe thing, and it's priority?
22:44Jedi_Stannisyeah
22:44eeebut
22:44eeewhat TYPE could that be?
22:45Jedi_Stannisthe thing can be anything
22:45Jedi_Stannisno restrictions
22:45Jedi_Stannisthe priority needs to be comparable
22:45eeeum
22:45eeethen it could be an object like in java
22:45eeewith two fields
22:45eeerecursive argument
22:45Jedi_Stanniswould you want that for a reason?
22:46eeeyou mean just define that the priority part is considered equal whenever it is not less and not greater
22:46eeehey, I've enjoyed this , . . . but I gotta go at least for a bit
22:47Jedi_Stannisok no problem
22:47eeei'm at eviertel@gmail.com for more cool ideas
22:47eeethanks
22:47Jedi_Stannishopefully that helps you at
22:47Jedi_Stannisout*
22:47eeeyup
22:47eeethanks
23:10eeeyo
23:22rlbeee: FWIW, I think Jedi_Stannis said something like what I was thinking...
23:24eeei think I get it
23:24eeestill an odd conflict to me
23:24eeebecause most structures
23:24eeeare for search
23:24eeelike a map
23:24eeeor set
23:25eeeso you can 'find' your element
23:25eeeby matching on value
23:25eeeand define identity that wat
23:25eeeway
23:25eeebut, classically
23:25eeein a heap
23:25eeeyou don't search
23:25eeeyou stick your element in
23:25eeeit's yours
23:25eeeyou still know where 'it' is
23:26eeeit's yours because it's yours . . .not because the value matches
23:26eeeyou never lose it. you always have your finger on it
23:26eeebut that's really suited for imperative environment
23:26rlbeee: you mean if you keep the pointer to it? Otherwise, you still have to find it again.
23:27eeeexactly
23:27eeeso the return from insert right now is a new heap
23:28eeebut it perhaps needs to be a new heap and a little box for your object
23:28eeenow's the tough part
23:28eeeno backpointers up the tree
23:28eeechange the value in the box
23:28eeemeans you need a new heap
23:28clojurebotnew Class(x) is (Class. x)
23:29eeethat has that value in the right place. so you need a new heap and a new box
23:29eeebut same value?
23:29eeeor new value
23:29rlbI suppose it depends on how often you really need to keep track of the pointer. You don't in cases where all you really want the queue for is to hand you the next item when you ask for it.
23:29eeewell, that alone is pretty cool
23:30eeelazy sort
23:30eeebut
23:30eeedecreaseKey is the real story
23:30eeeso many nice algorithms get fast with that
23:30eeelike Djikstra's shortest path
23:30eeedepends on updating the value
23:32eeei think java's priority queue as I'm seeing has notion of equality
23:32eeelike clojure
23:32eeeso
23:32eeei'll start with that idea
23:32rlbeee: does it have to, or rather, for clojure, I would think you might want a special queue (like the existing collections) that makes altered copies cheap.
23:32eeethat you can get any value that matches yours . . .decrese the first one that 'equals' yours
23:32rlbthough how hard that might be to do right for a priority queue, I don't know offhand -- haven't really thought about it.
23:33eeei have it working where altered copies are cheap
23:33eeefor everything but decreaseKey
23:33eeethinkingn out loud about that one
23:34eeethinking I need a map and a heap
23:34eeea persistentMap from clojure's java code
23:34rlbto make decreaseKey efficient?
23:34eeeto find an equal element
23:34eeewithout traversing
23:34eeea hashmap
23:35eeethat points to it
23:35eeehashmap that points to a linked list that points to all the equal elements
23:35eeethat solves the easy part :)
23:35eeeof having a handle
23:36eeenext, you insert a new element
23:36eeerepresenting the lesser value
23:36eeeand in that clients copy
23:36eeeyou remove the entry from the list
23:36eeenow, if that client ever bubbles up the dead node
23:37eeethat need to be able to tell that it's not in their version of the map
23:37eees/that/they
23:39eeemake sense?
23:42rlbeee: I'm not sure -- do you need handles (again haven't thought about it much)?
23:42eeelooks like someone did it in haskell withought, too
23:42eeewithout
23:43eeethey mess with values that match a predicate
23:43eeethat's kinda cool
23:43eeewonder if it's O(1) though
23:43eeethat's what I was going for
23:43eeedecreaseKey() in O(1)
23:48eeei think i found another paper
23:55eeethey did something just like I said. auxilliary data structure
23:55eeeruntime dominated by that structure and by cleanup of dead nodes
23:55eeeI think this may be an open problem in computer science
23:56eeefunctional decreaseKey in O(1) time