#clojure logs

2009-08-22

00:08JAS415ok
00:09JAS415so you call java with a -cp argument
00:09JAS415so if you are a unix like environment that means you make a shell script
00:09JAS415ah you left the room
00:09JAS415darn
00:17JAS415,(dorun 3 (range 0 100))
00:17clojurebotnil
00:18maxthimussuppose i have a list '('(1 2) '(3 4))
00:18JAS415(dorun 3 (map println (range 0 100)))
00:18maxthimushow will i invoke (map + list) so that i get (4 6)
00:18JAS415err
00:19maxthimusbasically i want the list to be expanded as list of arguments. i know apply can be used.
00:19maxthimusbut couldn't figure out how.
00:19JAS415,(let [x '('(1 2) '(3 4))] (map #(+ %1 %2) (first x ) (second x)))
00:19clojurebotjava.lang.ClassCastException: clojure.lang.Symbol cannot be cast to java.lang.Number
00:20maxthimusyup. but i want it for a variable length list
00:20Knekktry apply
00:20JAS415,(let [x (list '(1 2) '(3 4))] (map #(apply + %&) (first x ) (second x)))
00:20Knekk,(doc apply)
00:20clojurebot(4 6)
00:20clojurebot"([f args* argseq]); Applies fn f to the argument list formed by prepending args to argseq."
00:21JAS415liek that
00:21JAS415and you can apply the map too
00:22JAS415,(dorun 3 (map println (range 0 100)))
00:22clojurebot0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
00:22JAS415hmm
00:22JAS415is dorun broken?
00:22JAS415,(dorun 8 (map println (range 0 100)))
00:22clojurebot0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
00:23JAS415i would expect it to give me 3 or 8 and then quit
00:23Knekk,(doc dorun)
00:23clojurebot"([coll] [n coll]); When lazy sequences are produced via functions that have side effects, any effects other than those needed to produce the first element in the seq do not occur until the seq is consumed. dorun can be used to force any effects. Walks through the successive nexts of the seq, does not retain the head and returns nil."
00:24maxthimusi know i'm missing something simple. i couldn't extend this to work for var length list.
00:24JAS415oh
00:27maxthimusthanks guys. got it.
00:28maxthimussilly me. should have apply-ed +.
00:28JAS415yup
00:28JAS415apply +
00:28JAS415you can apply the map too I think
00:28JAS415i had a version like that somewhere
00:29maxthimusyup. thanks @JAS415.
00:36JAS415so is there any way to selectively consume a lazy sequence
00:37JAS415lets say i want to consume the first 4 and then leave the rest of the seq lazy?
00:40tomoj,(take 4 (iterate inc 1))
00:40clojurebot(1 2 3 4)
00:41tomoj"selectively consume" sounds like exactly what "laziness" means, to me
00:42_mstand to grab a hold of the rest: (let [[first-four lazy-bit] (split-at 4 (iterate inc 1))] ...)
00:42JAS415okay
00:43JAS415that is fine
00:43JAS415but lets say i do ,(dorun (take 4 (iterate inc 1)))
00:43JAS415,(dorun (take 4 (iterate inc 1)))
00:43clojurebotnil
00:43JAS415or actually
00:43tomoj(reduce + ...) appears to be consistently faster than
00:43JAS415i have the example above
00:43tomoj...(apply + ...)
00:44JAS415,(dorun 3 (take 3 (map println (range 0 100))))
00:44clojurebot0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
00:45JAS415see that is what I don't understand
00:47_mstyeah, I can't explain that either. That's not what it prints in my repl
00:47tomojperhaps it's chunked?
00:47tomoj32 can't be coincidental..
00:47tomojI get 32 as well here
00:47JAS415i get the feeling it is something weird about the latest version
00:47_mstah, I'm still on 1.0 so that might be it, yeah
00:47tomojI think that's a bad way of printing stuff from a seq anyway
00:48JAS415yeah that's just an example
00:48JAS415i was actually doing something with a GUI and generating frames
00:48tomoj(doseq [x (take 3 (range 0 100))] (println x))
00:48tomoj,(doseq [x (take 3 (range 0 100))] (println x))
00:48clojurebot0 1 2
00:48JAS415ah
00:48JAS415i'll try that version
00:48tomojyou don't want to map a side-effect function over the seq
00:52JAS415why is that?
00:52JAS415does it always evaluate side effect functions?
00:54tomojno, it doesn't know the difference
00:55tomojbut (as you've seen) it might apply the function more than necessary
00:56tomojit appears to go in increments of 32
00:56JAS415that's unfortunate
00:56tomojyou can get your original example to work if you change the order
00:57tomoj,(dorun (map println (take 3 (range 0 100))))
00:57clojurebot0 1 2
00:57JAS415hmm
00:57tomojbut I think doseq is better
00:57JAS415unfortunately the situation isn't analogous to either of those
00:58JAS415this all has to do with the chunking stuff?
00:58tomojI'm guessing
00:58tomojcheck this out
00:59JAS415too bad as i was going to have a 'more' button that just evaluates more of the sequence to add frames to the window
00:59JAS415would have made it fairly simple :-/
00:59tomojyou can still do that
00:59tomojI don't see how it's any less simple when you're not using (map println ...)
01:00JAS415ah i see what you are saying
01:00tomojhrmm
01:00JAS415yeah maybe that would work
01:01tomoj,(dorun (take 3 (map println (iterate inc 0))))
01:01clojurebot0 1 2
01:01tomojstrange
01:01JAS415i'll just pass the function and the list of frames then apply
01:01JAS415huh
01:01tomojyou can still use lazy seqs
01:01JAS4150 1 2?
01:02tomoje.g. with split-at like _mst showed
01:02tomojdraw the first however many and hold onto the rest with split-at, then when you want more repeat
01:03tomojI have this feeling that it's just a bad idea to have a lazy-seq consumption of which causes side-effects, not sure if that's really true
01:05JAS415yeah i mean
01:05JAS415generally it is because you can kill yourself with memory overhead
01:06JAS415but i would guess it would be okay if the whole point is to cause the side effect
01:06JAS415but i can change my thinking about it and get an answer that is what I want without doing the lazy sequence stuff I think
01:06JAS415just have to pass the function as well as the seq of information
01:23tomojit's obviously not ok if the whole point is to cause the side effect
01:23tomojas in your previous example which printed out way too much
01:23tomojdoseq is better
01:25clojuregiven (def d {:employees '(david richard)}), is this idomatic to add another employee: (assoc d :employees (conj (d :employees) 'william))
01:26kotarakclojure: (update-in d [:employees] conj 'william)
01:27kotarakAnd while we are about idiomatic: (def d {:employes [:david :richard])
01:28clojureah, thank you. so prefer vectors of things instead of lists if they change?
01:29kotarakclojure: prefer vectors instead of quoted lists and keywords instead of quoted symbols
01:29kotarakclojure: whether to use vectors or lists for changing things depends on the desired characteristics
01:30clojureaesthetically, i like quoted lists and symbols
01:33clojurethat worked nicely; whenever i see ugly clojure code, i know i've much to improve
01:35kotarakclojure: my code starts looking ugly like hell, after three refactorings and two re-writes it then suddenly shrinks in size by 80%, becomes more functional and easier extendable. This happens quite often for me. I came to the conclusion: "If your code looks ugly, it is wrong."
01:35kotarakYMMV of course.
01:37clojurejust started coding clojure today, but same observation. and, i have to rid myself of perl, python, and java habits
01:38kotarakclojure: ah, that's easier than you think. And then there are cool Java libraries also. I have good experiences with eg. mxGraph. It allows a very functional, cojurey (ie. immutable) style. Very nice actually.
01:49clojureall clojure noobs should take notes, collectively edit a "clojure do and don't" wiki
01:50tomojI'd hope the non-noobs would chime in once in a while too :)
01:50tomojin case a noobs "do" is really a "don't"
01:52clojurebet combing through the #clojure irc logs will be great starter material
01:53hiredman~logs
01:53clojurebotlogs is http://clojure-log.n01se.net/
01:53hiredman~delicous
01:53clojurebotExcuse me?
01:54hiredmanbah
01:54hiredman~delicious
01:54clojurebotdelicious is http://delicious.com/clojurebot
01:54hiredman~brain
01:54clojurebotbrain dump is http://clj.thelastcitadel.com/clojurebot
01:55tomojit posts every link it hears to delicious?
01:55hiredmanyep
01:55kotarakWell. I was told, that noobs don't read wikis anyway...
01:56tomojjees
01:56hiredmanpastebin links tagged with pastbin, all links tagged with the nick that pasted it
01:56tomojit has 18 bookmarks tagged as me
02:01tomojdoes clojurebot have a gender?
02:11JAS415~gender
02:11clojurebotHuh?
02:11JAS415~sex?
02:11clojurebotI don't understand.
02:19bitbcktclojurebot: gender is irrelevant
02:19clojurebotYou don't have to tell me twice.
02:23JAS415~gender
02:23clojurebotgender is irrelevant
02:23JAS415clojurebot: sex? is yes please!
02:24clojurebotIn Ordnung
02:24JAS415~sex?
02:24clojurebotsex? is yes please!
02:24JAS415~gender
02:24clojurebotgender is irrelevant
04:16lowlycoderhow do you deal without continutaions? or is this the wrong channel, since those that really love continuations aren't here
04:16tomojI've never used a language with real continuations :(
04:18lowlycoderscheme
04:20tomojdo you have some example code where you want to use continuations?
04:43ChousukeI suppose continuations are a feature you don't miss until you've used them.
04:58tomojyeah
04:58tomojI'm a blub programmer
04:59ChousukeWell, I did read about continuations when I looked a scheme, but I never quite figured them out.
04:59Chousukeat*
05:00tomojI remember seeing a port of cl-cont to clojure
05:00tomojfor faking continuations
08:08ChouserI think concat needs to chunk for a chunked 'for' to do any good.
08:13Chousukehmm.
08:13rhickeyChouser: quite likely
08:14Chousukewhat would chunk do if you concat a chunked seq with a non-chunked one?
08:14Chousukeer.
08:14Chousukes/chunk/concat/
08:15rhickeyChousuke: the chunk-rest of a chunked seq need not itself be chunked
08:15rhickeychunked-ness is tested at each step
08:16Chousukeokay.
08:19rhickeyChouser: you had asked about #() in into, it's there in order to prevent holding onto from during the loop, but won't quite work because it closes over from. This was a quickie attempt because the original, not having a branch, recurred to itself and thus was fine
08:20rhickeyneeds to be ((fn [ret items] ...
08:20rhickeyinterestingly I couldn't get any version to hang onto from when testing this
08:21rhickeyso sometimes I guess hotspots liveness analysis obviates the need for clear-on-tail-call
08:22rhickeyI wish I could rely on that, and it would be nice if it worked for non-tail calls - i.e. on stack, not used after this call is a dead reference during the call
08:24Chouserrhickey: avoiding holding something was my first thought but yead it didn't seem like it would work.
08:24ChouserI'd missed this somehow: http://www.brool.com/index.php/pattern-matching-in-clojure
08:36Chouserconcat is defined before chunk and the math stuff.
08:57grosoursplop
09:09lisppaste8raphinou_ pasted "adding jwt listener" at http://paste.lisp.org/display/85858
09:10raphinouI have a problem with the second listener I want to define in my jwt exploration (see paste)
09:10raphinouI have the same problem as yesterday for the first listener, when I proxied Signal1 rather than Signal1$Listener
09:11raphinoubut here I don't make the same mistake (I think!), though I get the same error
09:11raphinouif anyone has a suggestion, I'm a taker :-)
09:12kotarakI had once trouble with inner classes and had to fully qualify the classname. (But just guessing...)
09:12carklike yesterday it looks ok at first glance =/
09:14raphinoukotarak: yesterday we confirmed you have to import innerclasses with a Signal$Listener syntax
09:15kotarakraphinou: I can't remember what I did, the only thing worked for me was (proxy [foo.bar.baz.Frobnicator$FlogistonReactor] ...). Everything with import failed. But I can't remember exactly. (As I said: just guessing)
09:17carkenterListener takes a JSlot
09:17carki mean enterpressed.addListener
09:20carkthis framework is quite strange
09:21raphinoucark, I think I try to use this method: http://www.webtoolkit.eu/jwt/latest/doc/javadoc/eu/webtoolkit/jwt/EventSignal.html#addListener(eu.webtoolkit.jwt.WObject,%20eu.webtoolkit.jwt.AbstractEventSignal.LearningListener)
09:22raphinoucark: why do you feel it's strange?
09:23carkah sorry, i'm not used to the .. notation
09:23carkyou are correct
09:23raphinouyes, I had tried with -> but got an error and then copied the working listener :-)
09:27carkbut this abstracteventsignal.learninglistener thing ... iit doesn't look like it's implementing Signal.Listener
09:28kotarakraphinou: you have to .method notation for ->, instead of (.. a foo bar) do (-> a .foo .bar)
09:29kotarak-> is more general. it also allows clojure functions and macros
09:29carkif you want a trigger method, you might need to proxy AbstractEventSignal.JavaScriptListener
09:30carkah but there is an add-listener with the proper parameters too =/
09:31raphinoucark, I really don't see the error here either
09:31raphinoukotarak, thx for the tip
09:34carkyou have this error at run time ?
09:34raphinouyes
09:34carkwhat's the value of wapp ?
09:34carkits class mean
09:35cark+I
09:35raphinouWApplication
09:36carkwell i'm at a loss =P
09:36carki give up !
09:36raphinoucark: you're right :-)
09:36raphinouthx for the help. I'll contact the jwt author
09:37raphinouI'll post something about the solution
09:37carki wonder why you're not using one of our nice web frameworks
09:38carkthis thing looks like it is intended to shield you from the web
09:38raphinouwell, I'm also using compojure
09:39raphinouand I'm curious about jwt to see how it can help me develop some web apps
09:39carki've been doing a few gigs with web applications, and in the end i prefer being in control
09:41raphinoucark: I could very well come to the same conclusion, but I have an app where this widget approach could be very helpful.
09:41carkdid you have a look to extjs ?
09:41raphinouyes, the app I'm talking about is done with extjs :-)
09:42carkit also shield you from the web stuff, but i like the client-side only approach
09:42carkthough i didn't do anything worthy of mentioning yet with it =)
09:43raphinouwell, extjs is fine, but you also have to code the server side, and you have 2 different code bases in 2 languages
09:43raphinouI want to see how/if jwt can help me
09:43carka typical web application has you coding in 4 languages, so i can live with 2 =)
09:44carkit would be nice to have a clojure to javascript compiler tho !
09:44raphinouyes, but if you follow that logic you can code in cobol too :-D
09:44raphinouyes, that could be very nice
09:45carkwell you have means of abstraction on the client side and on the server side too
09:45raphinoutake a look at this: http://wiki.github.com/rdale/wtruby/tutorial
09:45raphinouI found it interesting to read
09:46raphinounot that I want to convince you, but I want to see how this can be used in real world apps (likethe one I wrote with extjs)
09:49carki can see how this is tempting
09:50raphinouI need to go now.... Bye!
09:50carkbyebye
12:08alrex021can someone explain to me what the benefits of destructuring? I've seen a few examples in Rich's but can't see practical use of it.
12:08alrex021worth noting I'm new to FP style programming
12:10alrex021**typos: .... can someone explain to me what the benefits of destructuring are? I've seen a few examples in Rich's screencasts but can't see practical use of it.
12:11Chousukealrex021: you can do things like (let [[x y z] coordinate] ...) instead of (let [x (coordinate 0) y (coordinate 1) z (coordinate 2)] ...)
12:12Chousukeor if you want to separate the head of a sequence from its tail: (let [[head & tail] aseq] ...)
12:12alrex021ohh so give it a vector of bindings and bind to seq which in this case is coordinates?
12:13Chousukemap destructuring is less common but still nice.
12:14Chousukeit's mostly a convenience thing. saves a lot of manual undoing of data structures.
12:15alrex021ok thanks Chousuke, now I understand it better
12:16Chousukefor example, if you have a map and you want to extract values from it, you'd just do (let [{:keys [the keys here]} {:the 3 :keys 5 :here 'bar}] ...) and within the let you'd have variables called the, keys and here corresponding to the values from the map.
12:17Chousuke,(let [{a :foo b :bar} {:foo 5 :extra 6}] [a b])
12:17clojurebot[5 nil]
12:18alrex021oh cool, thats pretty neat
12:18Chousuke:keys is a shortcut for the case when you have {key :key otherkey :otherkey morekeys :morekeys}
12:19Chousukeactuall I think map destructuring works with anything associative.
12:19Chousukelet's see...
12:19alrex021can destructuring be applied using binding macro function like using let?
12:20Chousukepretty much anything that uses bindings uses let so destructuring is everywhere.
12:20Chousukeand in function arglists
12:20Chousuke,(let [{a 3 b 0 c 5} [1 2 3 4 5 6]] [a b c])
12:20clojurebot[4 1 6]
12:22Chousuke,(let [swap (fn [[a b]] [b a])] (swap [1 2]))
12:22clojurebot[2 1]
12:23alrex021sweet
12:26alrex021now destructuring makes a lot more sense and I see its convenience and power
12:26alrex021now just to use it in some real code :)
12:27Chouseralso you can provide defaults for map destructuring using :or
12:27Chouserand you can nest structures
12:28alrex021yup, I've seen the nested struct examples
12:28alrex021however never new about :or
14:19cupertinochadI have a quick newbie question
14:19JAS415ok
14:19cupertinochadI am reading the book Programming Clojure and I pasted in the following example:
14:19cupertinochaduser> (def foo 10)
14:19cupertinochad#'user/foo
14:19cupertinochaduser> (.start (Thread. (fn [] (println foo))))
14:19cupertinochadnil
14:19cupertinochaduser>
14:20cupertinochadThe book says it should print out 10 after the nil, but my REPL doesn't print the 10, just the nil.
14:21JAS415hm
14:21woodzcupertinochad: are you running it from a terminal or within Emacs/SLIME?
14:22cupertinochadI am running in Emacs/SLIME
14:22woodzCheck the *inferior-lisp* buffer.
14:22cupertinochadAnd there it is!!!
14:22woodz:-)
14:22cupertinochadThank you. I will keep that bufffer visible, too.
14:23woodzThat's where all your printlns from the REPL go.
14:23rottcoddor add this to your .emacs (add-hook 'slime-connected-hook 'slime-redirect-inferior-output)
14:24woodzAwesome. Didn't know that particular tip, rottcodd
14:24cupertinochadCool. I will add the hook. It will be easier for me to track things
14:26cupertinochadI installed the hook; works great. Thanks rottcodd!
14:27woodzLikewise :-)
14:54hamzahey guys, today i recompiled clojure, i started getting java.io.NotSerializableException: clojure.lang.PersistentVector$Node when i try to write a vector to file?
15:11hamzahey guys, today i recompiled clojure, i started getting
15:11hamza java.io.NotSerializableException: clojure.lang.PersistentVector$Node
15:11hamza when i try to write a vector to file?
15:12ChouserI've not tried to use binary serialization at all
15:13ChouserI know a couple others have. Do you have a little snippet that would reproduce the problem?
15:13Licenser_hello everyone
15:15hamzafunction uses alot of extra jars for encryption but it used to work 5 mins ago until i rebuild my clojure and clojure-contrib jar.
15:16hamzaif i switch to old jars i get no errors.
15:16hamzai was wondering if anything got changed?
15:16rhickeyhamza: there is a new implementation of vector and the nodes might not be serializable
15:19hamzais there a work around for this? or should i create java vector before writing it?
15:20rhickeyhamza: is there a reason you are using the latest?
15:20Licenser_latest is always shiny!
15:21rhickeyserializability is not yet a 'feature', certainly there needs to be an audit and a set of tests written, then patches to make sure all the collections work
15:21hamzano particular reason, i just updated it because it has been a while since i build the jars should i switch back?
15:22rhickeyhttps://www.assembla.com/spaces/clojure/tickets/64
15:23rhickeyhamza: yes, you should switch back, then maybe make some small test cases so anyone trying to patch this for you has something to target
15:31hamzajust curious, clojure vectors are java vectors right? what makes them not serializable?
15:31wtetzner_i don't think they're java vectors
15:32kotarakhamza: I don't think so. They just implement the vector interface.
15:32carkthey are not java array
15:32wtetzner_they have all of the fancy immutable persistence stuff
15:32rhickeyhamza: no they're not java.util.Vectors. The is no vector interface either
15:36kotarakOh. I thought there was an interface. Isn't java.util.Map an interface?
15:36rhickeythe vector nodes just started using j.u.c.AtomicReference, but that's Serializable
15:37rhickeykotarak: the relevant interface is j.u.List
15:37kotarakah. Ok.
15:37rhickey,(instance? java.util.List [1 2 3])
15:37clojurebottrue
15:38rhickeyj.u.Vector is a concrete class
15:38rhickey,(instance? java.util.RandomAccess [1 2 3])
15:38clojurebottrue
15:39kotarakIndeed, and j.u.Vector implements j.u.List.
15:39cemerickwe've been binary-serializing clojure vectors for some time
15:39cemerickwe're still on v1.0, so maybe something's changed, though
15:40kotarakI have a hacky xml-o-matic translating everything to xml for use in one the required Java libs. Works quite well so far.
15:41cemerickkotarak: xstream is the best in that department, last I knew
15:41cemerickwe use it heavily in our ground-truthing test process
15:42cemerickor, in our "legacy" process, I should say
15:43kotarakcemerick: xstream looked promising but it has a serious flaw: I cannot name the containing xml element. So I can't say <vector> because xstream already does a <c.l.LazilyPersistentVector> or so.. But maybe I should just go with whatever xstream.
15:43kotarakcemerick: Now I use very hacky org.w3c.Element translation, but mxGraph leaves that alone and provides persistence for free. Works quite well.
15:43rhickeyI think the only problem is that pv.Node has no default ctor
15:47cemerickrhickey: Java Serialization doesn't depend upon having a default ctor.
15:48cemerickif a class has a non-Serializable superclass without a default ctor, that's is a problem
15:48cemerickbut I think that's the only ctor-related restriction on Serialization
15:48cemerickThe bean pattern, on the other hand, does require default ctors everywhere, which can get *very* annoying.
16:16hamzais it possible to use the java task in ant to run a clojure file? i am trying to set up a build file to allow non programmers to get my compujure app running without messing with class paths. Like clojure.lang.Compile but to run instead?
16:17carkmake an executable jar so your user only needs to click it
16:19hamzai'll pass it to the guy who edits the html&css stuff i would like to create a easy way to get him up and running so he does not have to maintain jars and classpath's..
16:20carkand make him install ant ?
16:21cemerickhamza: an executable jar is the simplest way for end-users. Short of that, clojure.main can be used as the main class in a java ant task.
16:22Licenser_Hmm I've a very general and likely stupid question. From what I got by now storing states is evil in Clojure (or any other Lisp derivate) So what is the 'good' way of handling like a board of chess figures? updating the board with a function call and chain them for every move?
16:23hamzacark: he is using osx ant is installed by default cemerick: it is not for end user's it is for the html guy to edit stuff if i use clojure.main how can i tell it to load .clj file?
16:23ChousukeLicenser_: You can use refs for state
16:24Licenser_*nods* I know it's more a style question. I am not that versed in functional programming yet and I'd not want to get into the habit writing my usual iterative (or object oriented) code just with a different syntax, I think that is bad karma
16:25Licenser_So I wonder how that would be handled in a functional manner
16:25ChousukeLicenser_: represent the board as an immutable data structure however you want, and every transition as a function. then, you can just put the initial position in a ref, write code to ask for the next move and update the ref accordingly, and repeat
16:26Licenser_okay so for things like that it wouldn't be frowed upon to use a changing reference to things, good to know :) thanks Chousuke
16:27Chousukethat way all your actual logic is going to be purely functional (just a transformation taking the current board and the move as a parameter and producing a new board)
16:27ChousukeLicenser_: real programs need state. it's just a question of how it's handled.
16:28Licenser_That is the feeling I got from reading more about clojure and functional programming, that I can do a lot niftly things with it but if things go over hello world or some pure data processing state is required
16:28Chousukethe ref is an "identity". it's the game board. the value of the game board can vary with time, but the values themselves never mutate.
16:29Licenser_I just change what 'board' the ref points to right=
16:29Chousukeyeah
16:29Licenser_^^
16:29Chousukeif you read the state of the game board at one point that value is not going to change suddenly.
16:29Chousukeunlike in languages where you'd have a mutable "Board" that could suddenly get changed.
16:30Licenser_Ah I see that is where the whole stuff remains sane for matters of paralelism
16:30Licenser_yes in every iterative language I had written some kind of variable that gets changed for every move
16:31Licenser_this starts to make more and more sense ^^ :D
16:31Chousukeyeah. in clojure you'll have a single "variable" that points to whatever value of the board is current
16:32Licenser_So it's like updating a pointer instead of changing the data behind it
16:32Chousukeyeah.
16:32Chousukewith well-defined concurrency semantics :)
16:33Licenser_Does clojure have a GC that handles the unrefferenced data properly, because I kind of remember that Java's GC was kind of a myst sometimes
16:33Licenser_then again perhaps they have cleaned that up as well as the + opperator since I lased was tortured with it
16:33duck1123clojure uses java's gc
16:34duck1123and it's pretty good now a days
16:34Licenser_Chousuke: the concurrency is what got me interested in clojure in the first place. I mostly write ruby and that is really horrible when it comes to doing two things at once.
16:34Chousukethe important point is that your code won't mess with this variable directly. instead you'll be writing pure functions of value to another value and then tell the "variable" to apply a function to its current value and change itself to point to the new value returned
16:34Licenser_*nods*
16:35Chousukethe nice thing is that until you can pretty much not worry about the ref until you're done writing the purely functional logic.
16:37Licenser_sounds good
16:37Licenser_well clojure has one thing that is worth gold, a helpful community =)
16:42Licenser_But I see what peopel like about Lisp, the structure of the code is surprisingly clear.
16:51ChousukeLicenser_: lisp code is very dense.
16:51Chousukethere's so little syntax.
16:51Licenser_clear in the sense of what actually happens
16:52Chousukewell, I guess.
16:53Chousuke. is one of Clojure's operators that always forces me to stop when reading code though :/
16:54Licenser_because people ask silly questions like mine and you feel obligated to answer?
16:54Chousukenah.
16:54ChousukeI don't like . because it steals the list head position from the actual operation
16:55Licenser_Ohhh okay, I thought . is a odd for for saying me :P
16:55Chousukeand it's even worse if you have (. (. (. ...)))
16:55Chousuke:P
16:55Licenser_And I thought you're a channel opperator which foces you to stop reading code o.o
16:55Licenser_narf okay my brain is fried I think
16:56ChousukeI always try to get people to use .foo and Foo/bar syntax instead of . directly.
16:56Chousukebecause I hate reading code that uses it :)
16:56Licenser_That only applies wen working with Java classes right?
16:56Chousukewell, . is the java interop operator, so yeah.
16:56Chousukebut I'm not discouraging the use of java interop. it's okay. just don't use . :P
16:57technomancyChousuke: glad I'm not the only one who thinks that
16:57Licenser_^^
16:57Licenser_but I see what you mean, it makes the code less clean, even if . happens you acutally want the function behind it
16:59Chousuke. may have a place in macros though. but that's acceptable.
16:59Chousukemacros should be read carefully anyway :P
17:00Licenser_^^
17:20lowlycoderare there any java gui kits not based on top of AWT?
17:23rsynnottis SWT?
17:23rsynnottsorry, I mean is Swing?
17:23rsynnottpretty sure SWT isn't
18:08lowlycoderI wnt to know what namespace/package SWT.NONE belongs in; is there an easy way to 'grep' through jar files?
18:10drewrperhaps, jar tvf foo.jar | fgrep 'SWT$NONE'
18:10drewrnot an inner class though is it
18:11drewrcould start looking for SWT alone
18:14lowlycodercrap, how do I convert these two lines into clojure?
18:14lowlycoderGLData data = new GLData (); data.doubleBuffer = true;
18:14lowlycoderdoubleBuffer is just a java var, NOT a ref
18:14clojurebot
18:17drewr(def data (doto (GLData.) doubleBuffer))
18:17drewrer, sorry
18:17lowlycoderyeah, that seems to read from it
18:18lowlycoderrather than write to it
18:18technomancylowlycoder: just extract the jar file into a directory, then rgrep it
18:19drewrwould this work? (def data (GLData.)) (set! (. data doubleBuffer) true)
18:23lowlycoderdrewr: that worked; thanks
18:24pschorfdoes anyone know of a non-messy way to xor chars? bit-xor throws a cast exception
18:32drewrpschorf: what does your call to it look like?
18:32drewr,(bit-xor 1 1)
18:32clojurebot0
18:32drewr,(bit-xor 0 1)
18:32clojurebot1
18:33pschorf,(bit-xor \a \b)
18:33clojurebotjava.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.Number
18:33drewr,(bit-xor (int \a) (int \b))
18:33clojurebot3
18:33drewr,(int \a)
18:33clojurebot97
18:33pschorfdrewr, thanks
18:34pschorfdidn't realize you could explicitly coerce
18:42lowlycoderhmm, I actually can't figure out how to conver tthis to clojure:
18:42lowlycoder while (!shell.isDisposed()) { if (!display.readAndDispatch())
18:42lowlycoder display.sleep();
18:43lowlycoder }
18:43lowlycoderthe best idea I have in mind involves using recur
18:44Chousukeclojure has a while loop
18:44Chousuke(doc while)
18:44clojurebot"([test & body]); Repeatedly executes body while test expression is true. Presumes some side-effect will cause test to become false/nil. Returns nil"
18:45Chousuke(while (not (.isDisposed shell)) (when-not (.readAndDispatch display) (.sleep display)))
18:46Licenser_Again the ugly question, is that functional programming wise Ok?
18:47Chousukewell, it relies on side-effects so it's not functional, but it's not like you need to avoid non-functional programming all the time.
18:47Chousukeusually, sticking to functional idioms just makes things easier for you.
18:47Chousukeand with java interop, you often can't avoid side-effects
18:48Licenser_*nods* True
18:48lowlycoderChousuke: worked; thanks!
18:53Licenser_well night everyone!
22:54lowlycoderhow do I convert the following to clojure? I get lost after: "(Listener. ..... " given java code of: Listener listener = new Listener() { public void handleEvent(Event event) {
22:57Chouserthat's a anonymous inner class (or whatever it's called). Currently Clojure's most similar construct is 'proxy'
22:57clojurebotproxy is <Chouser> proxy teases with its ease of use, then suddenly betrays.
22:58Chouser(let [listener (proxy [Listener] [] (handleEvent [event] ... ))] ...)
22:58Chouserin a future version 'new' will do this for you.
23:02lowlycodercool; thanks :-)
23:07Chouseryou can try it now in the 'new' branch
23:22Chouserthe amount of work done for each clause of a 'for' form is quite stunning, both at compile time by the macro, and then at runtime by the generated code...
23:23Chouser,(macroexpand-1 '(for [a [1 2] b [3 4] c [5 6]] (+ a b c)))
23:23clojurebot(clojure.core/let [iter__5244__auto__ (clojure.core/fn iter__2550 [s__2551] (clojure.core/lazy-seq (clojure.core/loop [s__2551 s__2551] (clojure.core/when-first [a s__2551] (clojure.core/let [iterys__5242__auto__ (clojure.core/fn iter__2552 [s__2553] (clojure.core/lazy-seq (clojure.core/loop [s__2553 s__2553] (clojure.core/when-first [b s__2553] (clojure.core/let [iterys__5242__auto__ (clojure.core/fn iter__2554 [s__2555]
23:24tomojhow do you generally make custom swing components (e.g. that draw graphs or whatever)?
23:24tomojseems the standard way of doing this in java is by subclassing and overriding paint
23:24tomojso, gen-class?
23:24Chousernah
23:25Chousernot unless you need it to look like "normal" widget class to Java code that uses it
23:25tomojI don't care about java code using it.. what's the alternative?
23:25Chouserthe normal proxy pattern
23:26Chousera clojure fn that uses proxy to create an object
23:26tomojhmm
23:27tomojproxy methods can't call super, though, right?
23:28Chouseractually, you might not even need proxy...
23:28ChouserI wrote this a while ago: http://gist.github.com/40012
23:28Chousertrying to figure out how it works
23:29Chouserah, that doesn't hook the paint method -- it just draws onto a Frame when it feels like it. maybe not a good example.
23:30tomojI tried that at first
23:30tomojbut on resize everything gets cleared
23:30Chouseryeah, you want a paint method. I thought I did that too, just have to find it...
23:31Chouseroh, the ants example does this
23:32tomojah, great
23:32tomojI'll take a look at it
23:32tomojthanks
23:32Chouseryou don't need to call the superclass' paint method.
23:32tomojoh, that looks a lot simpler than I expected
23:33Chouser"Subclasses of Component that override this method need not call super.paint(g)."
23:33Chouserstraight from the Java doc
23:33tomoj:)
23:33tomojbeen a long time since I did anything with java
23:34Chouser:-) np.
23:39elbenI'm trying to get vimclojure to work, but my syntax isn't looking right: http://yfrog.com/0ggvimp
23:39elbenFor ex, the keyword "def" isn't highlighted. But it seems that it's using my /.vim/syntax/clojure.vim file. any ideas?
23:40lowlycoderi want to have a varaible whose value lasts between a "(use :reload-all 'module-name)" session ... how do I do that?
23:41Chouserlowlycoder: maybe defonce
23:43lowlycoderthat looks useful thanks
23:48lowlycoderI don't get the point of 'transient' ... so it's a hint to the gc to say "this piece of data can be thrown away soon?" ?
23:48ChouserThe Java keyword, or the Clojure term?
23:49Chouserthey mean rather different things.
23:49lowlycoderhttp://clojure.org/transients
23:50lowlycoderNot persistent, so you can't hang onto interim values or alias
23:50lowlycoderso I can't capture intermediate calculations?
23:50lowlycoderthis is weird
23:50Chouserright, it's just a performance feature of Clojures persistent vectors and maps
23:50lowlycoderhmm, my clojure doesn't even support it
23:51Chouseryeah, it's pretty new
23:52Chouserif you're building a large vector inside a function which you will then return, it would be perfectly safe to build it using a mutable collection and then convert it to persistent before returning it.
23:52lowlycoderwhy would i want to use transients instead of a vector of refs ?
23:53Chousera mutable collection would be faster for that kind of building up, but then converting it to persistent would generally be too expensive to be worth while
23:53lowlycoderconverting is something like (map #(deref %) ...)
23:54lowlycoderi guess what I really should do, instead of debating
23:54lowlycoderis checkout latest clojure and time it :-D
23:54ChouserClojure triansients give you most of the speed benefit of a mutable collection, but then the 'persistent' call is O(1)
23:54lowlycoderah