#clojure logs

2009-07-03

00:46CoreyWhiteDoes anyone know of a syntax highlighter with Clojure support? Or with generic Lisp support that would be fairly easy to adapt to Clojure? (For the web, preferably javascript/jQuery, although I could live with something server-side in PHP.)
00:47CoreyWhiteI'm aware of the Clojure plugin for SyntaxHighlighter (here: http://travis-whitton.blogspot.com/2009/06/syntaxhighlighter-for-clojure.html), which is quite good . . . but unfortunately SyntaxHighlighter messes with my markup in very unpleasant ways.
00:53gstamphttp://kai.myownsiteonline.com/clojure/html.clj.html
00:55CoreyWhitethat seems pretty excellent! Is that your site?
01:04gstampNo not mine. There was a recent thread in the mailing list. I plucked the URL from that.
01:05gstampThread was titled "Displaying Clojure code on a Website" if you'd like to look it up
01:12Knekkanyone here use vimclojure?
01:28Chousergah. why can't I have a reader hook!?
03:00mrpikat
03:00mrpikaoops
03:06Knekkfor a large(ish) multi-dimensional array of mutable data should I use vectors of refs? or Java arrays?
03:08parthmKnekk: If you want java interop + performance you can use java arrays
03:09parthmare there multiple threads in your program operating on the data?
03:09KnekkWould only need performance for the array. I can define the data itself without java interop
03:09Knekkyeah, multiple threads will manipulate the data
03:10parthmrefs of vectors can be a start. if you feel performance is bad you can switch to arrays
03:10parthmvectors have a lot of functions to work on them
03:11Knekkthat's what I am seeing, yeah
03:11parthmfor most cases vector performance is fine
03:11KnekkI am blowing the heap space trying to create the vectors. Need to get my head around the implications here
03:12parthmhmm ... do you need all the initialization up front or maybe it can be lazy
03:14Knekkeven if it's lazy I'll be iterating across all the array elements a number of times to do transformation on the data pretty fast, so all elements will be accessed
03:19parthmI probably don't get the use case but even the computation should be delayed and only the relevant values should be generated/computed.
03:19parthmuser=> (time (def y (map (partial + 1) (range 10000000))))
03:19parthm"Elapsed time: 0.904514 msecs"
03:19parthm#'user/y
03:19parthmuser=> (take 5 y)
03:19parthm(1 2 3 4 5)
03:19parthmuser=> (take 5 (drop 1000000 y))
03:19parthm(1000001 1000002 1000003 1000004 1000005)
03:19parthmuser=>
03:20parthmsometime I have seen the stack blow when we hold on to the head somewhere.
03:21KnekkI am probably not using the proper methods then. I am a n00b. Using (apply vector (map (fn [_] (ref (struct my-struct))) (range large-number))
03:21Knekk))
03:22Knekkto create one dimension of the array
03:23Lau_of_DKapply forces evaluation, thats not the same as parthm's example above
03:24KnekkI was basing mine on a different example, and that'd explain why I am blowing the heap
04:46Knekkok, so now I have a better lazy approach to creating a multi-dimensional array of refs
04:52Knekknight
05:22Knekklaggy tonight
06:46ChousukeChouser: are you handling the clojure-1.0 compatible contrib branch?
08:01AWizzArdIs there an efficient built-in function that removes an element from a vector at position n?
08:20rhickeyAWizzArd: can't be
08:26AWizzArdrhickey: is it planned to add new immutable data structures to Clojure, such as doubly linked lists or skiplists?
08:27rhickeyAWizzArd: finger trees would be welcome
08:27rhickeyhttp://en.wikipedia.org/wiki/Finger_tree
08:30AWizzArdFinger trees or skiplists ( http://en.wikipedia.org/wiki/Skiplist ) would have to be implemented in Java for performance reasons yes?
08:32rhickeyno
08:34rhickeyany data structures need to be persistent
08:34AWizzArdyes
08:34rhickeyso, doubly linked lists not possible
08:34qrahi clojure group, this is first time I entered this channel.
08:35rhickeyqra: hi
08:36AWizzArdI see, didn't think about that yet. Anyway, what would you do if you wish to conj up a vector V of structs over which (V) you then run a unification and pattern matching algorithm that wants to remove at (possibly random) positions elements and add new ones?
08:37rhickeyAWizzArd: what's the significance of the positions?
08:37qrahow to force 'for' to run through all items in a lazy list?
08:38durka421qra: doall
08:38durka421or you may be looking for doseq instead of for
08:38qraok
08:38rhickeyqra: if your 'for' is only for side effects, use doseq instead, otherwise you can call doall on the result of for
08:39rhickeyor vec
08:41AWizzArdrhickey: if the positions won't be important then maybe a set would be right. But if the order must stay the same it is not so easy anymore.
08:43rhickeyAWizzArd: for splicing we need finger trees
08:43AWizzArdI see
08:49qra(for [i last-list] (doall (println i)) wont work?
08:50durka42for produces a lazy seq, so you want to wrap doall around the entire thing
08:50durka42(doall (for ...))
08:51qraok, but i cant understand what's going on
08:51rhickeyqra: for is designed to return a sequence of values
08:51rhickeybut yoiu just want to perform a sequence of side effects, so use doseq
08:52rhickey(doseq [i last-list] (println i))
08:52qradoseq throws some error it expects vector, but I have only lazy-list
08:53rhickeyfor produces the values lazily, so if you never use them, it never produces them
08:54rhickeyqra: try: (doseq [i (range 3)] (println i))
08:54rhickeyat the repl
08:55qrathank u, it works.
09:02tashafahello all
09:02danlarkin__salut!
09:02tashafawhats up danlarkin
09:02danlarkin__it's finally sunny!
09:03tashafanot in mass :(
09:03danlarkin__maybe... just maybe it can last all day
09:03tashafamassachusetts
09:03tashafai dont think ive seen the sun in a month
09:04danlarkin__I was in Boston last weekend, and driving home was hilarious. I left boston in a hazy cloud cover and like 30 minutes west it turned into a beauuuutiful day
09:05tashafathats new england weather for you
09:06sgtarr_england weather is worse.
09:06tashafaclojure ques.
09:06sgtarr_ques?
09:07tashafait escapes me but how do you extend a java class again and override a method
09:07tashafa?
09:07tashafain clojure ofcourse
09:07tashafa:)
09:08sgtarr_i can tell you how to do it in java.. :)
09:08danlarkin__proxy
09:09danlarkin__unless proxy is gone now
09:09danlarkin__it's been a few weeks since I've used clojure :(
09:09tashafasame here
09:09sgtarr_haha
09:09sgtarr_clojure changes that quickly?
09:09tashafai've been in python world
09:09sgtarr_the cutting edge!
09:09sgtarr_tashafa: welcome back to civilization...
09:10sgtarr_naw, I shouldn't talk like that about Python. I use it often and i've used it for many projects since approx 2002
09:10sgtarr_But there are some things that bug me...
09:10sgtarr_and java is just much better for Enterprise
09:10tashafayup... procedural programming is just mind numbing
09:12tashafaafter messing with clojure that is
09:13sgtarr_yea
09:13sgtarr_tashafa: how did you get involved with clojure?
09:14sgtarr_interest in lisp from before?
09:14tashafaby way of paul graham
09:14tashafabut common lisp was just hard to get started with
09:16sgtarr_yea
09:16sgtarr_I was always fascinated by Lisp
09:16sgtarr_and there is a finance company that I was familiar with that used Lisp exclusively, still do, but they used LispWorks afaik
09:17tashafacool
09:21sgtarr_I remember that asteroid probe Deep Space 1 also ran Lisp
09:21durka42really?
09:22sgtarr_It still does actually, even though its ion thrusters have been off since 2001
09:22sgtarr_Lisp up there in space, still running silently :)
09:22durka42the first google result for "deep space 1 lisp" is that rant about how JPL lost faith in lisp
09:23sgtarr_really? weird
09:23sgtarr_check out http://en.wikipedia.org/wiki/Deep_Space_1#Remote_Agent
09:23sgtarr_the RAX software was lisp
09:23sgtarr_and the mission was a huge success
09:24sgtarr_from your article:
09:24sgtarr_"Based on this experience I think it's safe to say that if not for Lisp the Remote Agent would have failed."
09:25sgtarr_"Debugging a program running on a $100M piece of hardware that is 100 million miles away is an interesting experience. Having a read-eval-print loop running on the spacecraft proved invaluable in finding and fixing the problem."
09:25sgtarr_Nice. REPL 100 million miles away
09:38tashafahmm
09:39tashafahow do you call methods on the parnet class (super) in proxy?
09:43tashafaproxy-super
09:45Chousukehm, is that even possible?
09:51AWizzArdIs there (maybe in contrib) a foo for doing (foo [1 2 3 4 :x 5 6 7 8 :x 9 10 :x 11]) ==> ((1 2 3 4) (:x) (5 6 7 8) (:x) (9 10) (:x) (11)) ?
09:52AWizzArdsplit-at, split-with, take-while, partition-by, group-by and others don't work
09:55AWizzArdmy foo call was not complete, it misses something like #(= % :x) or #(not= % :x)
10:02tashafaChousuke: I have no idea
10:02tashafabut shouldnt it be?
10:29tashafaChousuke: http://dishevelled.net/Tricky-uses-of-Clojure-gen-class-and-AOT-compilation.html
10:32Chousukeinteresting
11:31lisppaste8AWizzArd pasted "How to group/split contents of a collection into groups?" at http://paste.lisp.org/display/82957
11:32rzoomis there a github issue?
11:33rzoomrob@eniac:~$ git clone http://github.com/richhickey/clojure
11:33rzoomInitialized empty Git repository in /home/rob/clojure/.git/
11:33rzoomfatal: http://github.com/richhickey/clojure/info/refs not found: did you run git update-server-info on the server?
11:42rzoomnevermind
11:43rzoomin the future, use the github specified Clone URL, for .... you know ... cloning
11:43rzoome.g. git clone git://github.com/richhickey/clojure.git
11:52cgrandAWizzArd: (s/partition-by #{:x} [1 2 3 4 :x 5 6 7 8 :x 9 10 :x 11])
11:52cgrandwhere s is seq-utils
11:53AWizzArdcgrand: ah good, that is much better
12:23jackdempseyrzoom: yea, .git on the end :)
12:49lisppaste8codyK pasted "already in zip libraries?" at http://paste.lisp.org/display/82962
13:38Lau_of_DKGood evening gents
13:39dysingersup
13:50jackdempseyevenin
15:31jackdempseyanyone familiar with compojure round these parts?
15:39jackdempseyis there an idiomatic approach for getting the current time in clojure?
15:39jackdempseyreading a variety of ways to ask java, and prety much all end with
15:39jackdempsey"i hate the Calendar class" :-)
15:42Lau_of_DKI use Joda time for that stuff
15:42Lau_of_DKAnd yea, Compojure is hot
15:42Lau_of_DK*sizzle*
15:43jackdempseyk, saw Joda mentioned before as well, gotta check it out it seems
15:44jackdempseysigh
15:44jackdempseyThis page is unavailable at the moment. Please try again shortly. Sorry for the inconvenience.
15:44jackdempseyoh the yak shaving :-)
15:46technomancythe JDK calendar is horrible, but if all you want is the current time, it's not bad
15:46technomancy(java.util.Date.)
15:48jackdempseyhey technomancy , yeah, thanks man, i'm ultimately looking for just the current time in a unix style timestamp
15:48jackdempseyi thought it'd be fun to rewrite this in clojure/compojure: http://github.com/jcapote/watercoolr/blob/125707e211b0a3cb6462ea405bb77aefb1618f8b/watercoolr.rb
15:48jackdempseygood exercise to learn more, etc
15:48lisppaste8Lau_of_DK pasted "Macro this!" at http://paste.lisp.org/display/82973
15:48Lau_of_DKBoys - Can somebody shed some macrobiotic light on the question I asked in that lisp-paste ?
15:50Chousermacfoo always uses a function named 'foo' exactly twice?
15:52Lau_of_DKYep
15:52Lau_of_DKOn the first assumption
15:52Lau_of_DKBut it will use it x number of times, depending on the length of your list, ie "mister" "#clojure" "bar" "baz" etc
15:53Lau_of_DK@ Chouser
15:54ChouserLau_of_DK: did you want to pass in the initial string too?
15:54Lau_of_DKThat would be ideal
15:55technomancyjackdempsey: my first project was porting a web app to compojure too, but I found I learned more from writing Mire; I kind of fizzled out on the web app.
15:55jackdempseyheh gotcha
15:56jackdempseyyeah its kinda painful so far
15:56technomancyweb apps just have too much incidental stuff to worry about
15:56jackdempseyespecially coming from rails
15:56technomancymight be better to tackle that domain once you've got a grasp on the core language
15:56jackdempseyah
15:56jackdempseyi see what you mean
15:56jackdempseynot a bad point
15:56Chouser(defmacro macfoo [string & subs] `(-> ~string ~@(for [sub subs] `(foo ~sub))))
15:56jackdempseymy eyes are starting to glaze over
15:57jackdempseyhmm
15:57jackdempseythis isn't too bad tho
15:57jackdempsey(/ (. System currentTimeMillis) 1000.0)
15:57Lau_of_DKChouser: Man thats nasty :)
15:58Lau_of_DKIt was the ~@(for...) I couldnt work out, but it makes perfect sense
15:58Chouser:-)
16:00krumholt_why is it every? but some without "?"
16:01Lau_of_DKChouser, mind if I annote it so that others can benefit?
16:01ChouserLau_of_DK: by all means.
16:01lisppaste8Chouser annotated #82973 "Macroed" at http://paste.lisp.org/display/82973#1
16:02Chouserkrumholt_: the "?" suggests it'll return true or false
16:02achimLau_of_DK: umm, why a macro? that's "reduce" ...
16:02achim(reduce #(foo %1 %2) "hi!" ["mister" "#clojure"])
16:02krumholt_Chouser, ok thanks
16:02Chouserkrumholt_: 'some' returns the value returned by the predicate -- could be something other than boolean
16:03Chouserachim is absolutely right.
16:03jackdempseyheh
16:04ChouserI violated the first rule of writing macros.
16:04Lau_of_DKAchim... ehm.... I was just setting Chouser up of course, I had it figured out hours ago :)
16:04jackdempseylol
16:05Lau_of_DKChouser you should paste your user.clj .... (defmacro println) etc... :)
16:18achimdid anybody here have a look at Qi?
16:22technomancycan you start nailgun from an already-launched clojure instance?
16:22technomancyi'm using (com.martiansoftware.nailgun.NGServer/main (make-array String 0)) to no effect
16:23rhickeyachim: Qi is definitely interesting
16:29jackdempseyah cool
16:29jackdempseyhadn't heard of Qi
16:29fooxi have three sub-expr in a 'let'. the third gets evaluated before the second; how can i prevent this
16:30fooxthe second sub-expr is a doseq
16:32drewrtechnomancy: I haven't tried nailgun yet. Like it?
16:32technomancydrewr: works like a charm
16:32krumholt_how can i remove an item from a map?
16:32technomancyexcept for starting the server in an already-running instance; I can't figure that out
16:32technomancykrumholt_: dissoc
16:33krumholt_thanks
16:33technomancydrewr: on the whole it's very simple and obvious
16:33drewrkrumholt_: Also look at select-keys if you have a bunch to remove.
16:34drewrtechnomancy: Looked like it. I'll give it a shot.
16:34krumholt_thanks
16:44technomancyif the nailgun server is runnable, can I pass it to a new thread and have the thread run it for me?
16:44technomancyhow does that interface work?
16:45technomancyoh, looks like that works.
17:51dysinger_thank goodness for #clojure's active irc channel
17:53Chouserhm. a joke?
17:53Chousuke:P
17:55technomancyI think he means relative to Java IRC channels
17:55technomancy#hadoop is like a tomb
17:55Chouserah
17:55technomancyand dysinger_ is dancing among the gravestones
17:56dysinger_y Chouser - seems like often Java dudes ( I am on ex-10-yr one myself ) just hang out on IRC and don't actually participate in discussion.
17:56Chouserah.
17:56dysinger_I've tried to ask a question on #hadoop 4 times - every time there's like 60 people in there but all I get is crickets
17:56ChousukeCan you do the moonwalk? Maybe it'd activate the channel.
17:57dysinger_I ran naked through the channel
17:57technomancyas long as it's not the Thriller zombies...
17:57dysinger_but nobody said anything :)
17:57Chousernormally I would have assumed you were making a straight statement, but since your comment was the first in over an hour I just wasn't sure.
17:57dysinger_seriously :) "dysinger_ runs by naked and nobody notices [2:52pm] •"
17:57Chouserheh
18:03jackdempseyman
18:03jackdempseythis is really interesting, but i feel like i'm starting to walk again
18:03jackdempseyexcept i have arthritis from OO land
18:03jackdempseyi'm staring at (let [id gen-id]....) for a while and wondering why i get the function back
18:04jackdempseymaybe because thats exactly what i asked it to set id to
18:04jackdempsey[id gen-id] will just st id to be the function referred to by gen-id, correct? if i actually want it to be the result i have to do (let [id (gen-id).....) right?
18:04Chousukeyes.
18:05jackdempseycool
18:05Chousukefirst-class functions are fun little things :)
18:05jackdempseytechnomancy: that little web port is coming along ok....so far the hardest part has been trying to figure out what i can borrow from java......and of course some basic clojure stuff.
18:05jackdempseyhaha, yep
18:05jackdempseygoing to take a while to unlearn some bad habits
18:06jackdempseyi can't wait to see what this does to my ruby....
18:06Chousukejackdempsey: you'll be using code blocks a lot more I guess.
18:07jackdempseyyeah, blocks are already kinda ubiquitous, but i think the way i use them and approach certain problems will certainly be different
18:07Chousukeor then you do an assignment and go "wtf, why is the old reference changing too?"
18:07jackdempseyi saw somethhing in couchdb earlier and thoguth" but but but, thats a side effect, oh god no!.......oh wait........ahem"
18:07jackdempseylol
18:08jackdempseyuser=> (def foo #{})
18:08jackdempsey#'user/foo
18:08jackdempseyuser=> (conj foo 1)
18:08jackdempsey#{1}
18:08jackdempseyuser=> (conj foo 2)
18:08jackdempsey#{2}
18:08jackdempseythat still cracks me up....not used to it at all :-)
18:08Chousukeyeah.
18:08jackdempsey"where'd the 1 go.........oh......ha"
18:09jackdempseyits definitely easier to think about things in the more pure functional sense...appeals to my math side for sure
18:09ChousukeI find it easier because functions become true black boxes.
18:09Chousukeonce they work, you *only* need to know what they do, not how
18:09jackdempseyyep
18:09jackdempseyexactly
18:10jackdempsey"does that still set that random thing or not......have to go look"
18:10jackdempseyman, i really really want to reply with something about refs and STM: http://stackoverflow.com/questions/1080993/pure-ruby-concurrent-hash :-)
18:11arohnerClojure makes me more irritated by ruby
18:11arohnerI get annoyed by things like not being able to pass multiple blocks to a function
18:11technomancyyes.
18:12arohnerand blocks are not a replacement for first class functions
18:12technomancyI find myself writing classes for pure IO and keeping them totally separate from the bulk of the logic.
18:12technomancybut I've only written like two pages of Ruby since learning Clojure. =)
18:13Chousukearohner: what, you can only pass one? :/
18:13slashus2technomancy: Was it your main language before?
18:13jackdempseyheh
18:13arohnerChousuke: yes, one "normal" block. After that, you have to start passing procs around, which use a different syntax
18:13jackdempseyyeah, if you do def (foo, &bar)
18:13arohnerthat, and there are 6 or 7 different kinds of blocks
18:14jackdempseycan pass that one normal block, otherwise as arohner says you have to use lambdas
18:14jackdempseyhehe
18:14Chouserthough in a mutable language, first class functions are not a replacement for blocks
18:14arohnerChouser: how so?
18:16arohnerhttp://innig.net/software/ruby/closures-in-ruby.rb
18:16arohnerthat is a great example of how Ruby is insane
18:16jackdempseyoh man
18:16jackdempseylol
18:16jackdempseyreally exposing the skeletons in the closet now :-D
18:16Chouserruby blocks can use 'break' and such to control the loop they're in
18:16arohnerewww
18:16jackdempseylambas can return as well....but procs return differently......and well......yea
18:17jackdempseyruby's an excellent language for some things.....but for others, not so much, and like anything, has its warts
18:17jackdempseyk, workout time, later gents
18:28codyKis there an existing pretty-printer for xml-zip ?
18:31ChousercodyK: you can zip back up to the root and use 'emit' to print it as xml again.
18:35codyKgood enough, thanks
19:11_hrrldIs there a function to tell me if a Var is "bound"?
19:16Chousuke_hrrld: (when-let [v (resolve sym)] (.isBound v)) perhaps
19:21_hrrldComically, I can't seem to call resolve on an unbound symbol.
19:22_hrrld(declare x)(resolve x) ; Var user/x is unbound.
19:24achim_hrrld: (.isBound #'x) seems to do the trick
19:25achimresolve is a function, it doesn't even see the x, the compiler tries to substitute it before calling resolve
19:28_hrrldThat makes sense, and the hash quote does work. Thanks.
19:28ChouserThat assumes the var exists
19:29Chouserwhich is why Chousuke use 'resolve' first to see if there's even a var named by that symbol
19:37unlinkhi
20:47somethingif I know the name of the function, is there a way to get the fn definition back during runtime?
20:59Chousersomething: have you tried clojure.contrib.repl-utils/source ?
21:00somethingChouser: no I didn't yet. let me take a look at that.
21:01Chouserit actually uses the var name not the fn, and it needs to be able to find the original .clj file in the classpath
21:01somethingChouser: I want to figure out # of arguments a particular fn takes before I invoke it. Is there an easy way to do that?
21:02Chousersomething: not perfectly, but you could get an 80%-type solution if you have access to the var
21:02Chouserif the var has been resolved to an actual fn, or if the fn was never in a var, you're pretty much out of luck.
21:03Chouserthe var has :arglists metadata you can try to use
21:03somethingChouser: awesome! let me check that out.
21:05Chouserthe thing is even if you have the var, it's possible for the var's arglists to have been left out or changed
21:07somethingin what scenario can the arglists be left out?
21:08Chouser(def foo (fn [a b c] ...))
21:09somethingChouser: right,
21:10somethingChouser: I'm going after the defn case, so I should be ok, but I understand what you are saying.
21:23somethingChouser: I guess the question is how to get a hold of the var when I only know the string representation of it
21:36Chousersomething: (resolve sym)
21:46somethingChouser: ah, thanks
21:49RaynesJoining #Concatenative after making less-than-nice remarks on reddit - Awkward.
23:33Knekkdoes clojure provide data/object serialization functionality (for writing to a stream, for instance) or does one need Java interop?
23:34ChouserMost Clojure collections can be printed as ascii that can then be read again.
23:35ChouserThere's also a *print-dup* var that can be set to make sure you get identical object types when read as when printed.
23:37Knekkthank you. I have too much data to keep in memory and need to find an efficient way to offline to disk