#clojure logs

2009-02-22

00:25digash`attribute filtering is broken in xml.clj
00:25digash`not sure what the problem is
00:25digash`just broke with the new lazy patches
00:25digash`; attribute filtering
00:25digash`(assert (= (xml-> atom1 :link [(attr= :rel "alternate")] (attr :type))
00:25digash` '("text/html")))
00:26digash`throws exception with NullPointer.
00:32lisppaste8digash` pasted "assert error in zip-filter" at http://paste.lisp.org/display/75949
00:32blbrownis there a formal way to report bugs. I am assuming emails the google groups is not always the best
02:55te'lo
03:36Lau_of_DKTop of the morning gents
04:44Lau_of_DKWhen I fire up gen-class with this arg :constructors {[String com.jme.scene.Node] []}) Doesnt that mean, that my class will require a String. and a Node. when constructed?
04:51Lau_of_DKOk - Better question, is there a java-call I can make to my class, which will show me the contructors requirements?
05:52alinphi
05:52alinpis there a way to call "time" function from java env ?
05:53alinpand I don't mean by calling clojure env
05:53alinptime function have some java method/class associated ?
05:54alinp~doc time
05:54clojurebotGabh mo leithsc�al?
05:54alinp,(doc time)
05:54clojurebot"([expr]); Evaluates expr and prints the time it took. Returns the value of expr."
06:47Lau_of_DKWhy is it - That when I want to use an enumerator from a class, I have to use its fully qualified name ?, ie
06:47Lau_of_DK(import '(com.jme.image Texture))
06:47Lau_of_DKnil
06:47Lau_of_DKcom.jme.image.Texture$Enum1/field1
06:47Lau_of_DK<value returned>
06:47Lau_of_DKTexture$Enum1/field1
06:47Lau_of_DKException
06:47Lau_of_DKWhy is that?
07:11AWizzArdLau, after you did that import, what happens if you just type Texture in the repl?
07:26Chouser(import '(com.jme.image Texture$Enum1))
07:35AWizzArdbtw, are delay and future now basically the same, only that a future will run in its own thread?
07:36AWizzArd(and also run immediately, while a delay will run lazily)
07:36ChouserI think that's right. Not a trivial difference.
07:36AWizzArdok
07:38Lau_of_DKThanks Chouser :)
07:39Lau_of_DKI've updated the project Wiki, so you guys can see when it gets interestined (ie. not yet) http://wiki.github.com/Lau-of-DK/sofiaba
07:39Lau_of_DK...with screenshots
07:39Chousercool
08:28wlrAWizzArd: recently you were interested in bit-twiddling. i stumbled upon http://java.sys-con.com/node/847250 haven't read it myself yet, though.
08:40Vargr_(possibly) stupid question: When I start clojure in an *inferior-lisp* with slime, I should be able to attach to that port with JSwat, no?
08:45kotarakVargr_: I figure, it depends on how you start the java instance.
09:14StartsWithKwhat should i use if i want to walk, transform and exctract parts of the form?
09:15StartsWithKso form could contain list, vector and map literals
09:15StartsWithKis there anything i can use for that right now?
09:17Vargr_kotarak: why, do I need to observe something special here?
09:19kotarakVargr_: I'm not very familiar with Java (coming from Scheme), but there is a debug option, when starting java, which (as I understand) allows you to connect a debugger. So I'm not sure, that you can connect the debugger, when you don't give the necessary options, when starting the java instance.
09:20Vargr_kotarak: oups, seems I've been trying to connect to swank then :)
09:22kotarakVargr_: so I don't know anything about SLIME and swank. :)
09:23Lau_of_DKOla mon kotarak ! :)
09:23kotarakStartsWithK: there is walk in clojure.contrib by Stuart Sierra.
09:23kotarakHi Lau_of_DK
09:23Vargr_thanks for the help anyway, kotarak
09:23Lau_of_DKKota, you'll enjoy this in a few years :) http://wiki.github.com/Lau-of-DK/sofiaba
09:24StartsWithKLet me sketch, http://paste.pocoo.org/show/104912/
09:24StartsWithKkotarak: i looked at it, but can't find any way to extract something, just transform in place
09:25StartsWithKand when i find :id id1 pattern, i want to go back to (mymacro expr) and replace it with (mymacro id1), where :id id1 could be anywhere in body of mymacro
09:28kotarakLau_of_DK: ui. Are you working on this?
09:29Lau_of_DKui?
09:29StartsWithKLau_of_DK: you switched from jogl to jme? hows that working?
09:30kotarakLau_of_DK: "ui" a sound like "ah" or "oh"
09:30Lau_of_DKah
09:30Lau_of_DKStartsWithK: They're worlds apart - Not going back to jogl :)
09:30Lau_of_DKkotarak: Yea - Sofia had a kick out of just switching screensavers on my laptop - So I thought I'd make a fun 3d game for her, figured the rest of you might like the 3D bindings
09:31StartsWithKLau_of_DK: heh, just couple of day ago i started to do experiments with it too :) small world
09:31kotarakhehe :)
09:31Lau_of_DKIts a classic: Slam the keyboard = Fun effects and responses in the environment, type game
09:32StartsWithKhad some problems placing jmecanvas and displaying swing menus around it
09:32Lau_of_DKWhich superclass did you go with ?
09:32StartsWithKSimpleCanvasImpl
09:33Lau_of_DKOh ok - Never heard of it
09:33StartsWithKwith JOGLAWTCanvasConstructor
09:33Lau_of_DKI went with BaseGame, good for fullscreen 3D games - Sounded like something Sofia would enjoy :)
09:34Lau_of_DKSo far, Ive got the world drawn up, and you can fly around in it, thats it
09:34StartsWithKi needed more 'application' look, with swing components around canvas
09:34Lau_of_DKAlso made some functions for loading resources quite easily
09:34StartsWithKresize still dosn't work :)
09:34Lau_of_DKAnyway, gotta run - Will probably be back tonight
09:35StartsWithKso.. any ideas how i could transform firs form in the one inside (let ..)
09:35StartsWithKis there something like, xslt for clojure form :)
10:33digash`anybody going to ILC2009?
11:21Chouserdigash`: yep
11:34MarkVolkmannI'm trying to understand the claim that using alter to change a Ref is more efficient than dereferencing, computing a new value, and using ref-set.
11:35MarkVolkmannIt seems to me this isn't a matter of efficient, just ease of coding.
11:35MarkVolkmannIf two threads are simultaneously trying to change the same ref in different transactions, with either approach, one of them is going to retry their transaction.
11:36MarkVolkmannAm I missing something?
11:39rhickeyMarkVolkmann: who made that claim?
11:40MarkVolkmannIt's in Stuart's book ... page 180 of the latest PDF.
11:41MarkVolkmannIs there a benefit to using alter instead of directly coding the three steps it comprises other than making the code simpler ... which is a good enough reason on its own.
11:43rhickeyI don't see "more efficient" there, but "less contentious" is also not correct
11:44rhickeyMarkVolkmann: alter is by far preferred
11:49MarkVolkmannThe line I'm looking at on page 180 of beta 7 says "The naive approach works, but it is inefficient."
11:49Lau_of_DKrhickey: Have you considered updating the gen-class documentation on clojure.org? I'll start pulling out my hair soon if you dont :)
11:50MarkVolkmannThe three-step naive approach appears just above that sentence.
11:51rhickeyMarkVolkmann: ah, please report to Stu
11:51MarkVolkmannOkay, I will. Thanks!
11:52rhickeyLau_of_DK: (doc gen-class) for now
11:53Lau_of_DKoh wait no - there's good stuff in that doc actually
11:53Lau_of_DKI'll read it - I thought it would be a slimmed down version of whats on the site :)
12:15digash`Chouser: where do i report bugs for contrib packages.
12:15digash`?
12:16Chouserdigash`: the regular Clojure google group.
12:16digash`Chouser: ok, thanks, I will send it there.
12:37Chouser,(import '(java.util GregorianCalendar Calendar))
12:37clojurebotnil
12:37Chouser,(.compareTo (GregorianCalendar.) (.add (GregorianCalendar.) Calendar/DAY_OF_MONTH 5))
12:37clojurebotjava.lang.NullPointerException
12:37Chouserwhat am I doing wrong here?
12:37Chouser(.compareTo (GregorianCalendar.) (.roll (GregorianCalendar.) Calendar/DAY_OF_MONTH 5))
12:37Chouser,(.compareTo (GregorianCalendar.) (.roll (GregorianCalendar.) Calendar/DAY_OF_MONTH 5))
12:37clojurebotjava.lang.NullPointerException
12:44AWizzArd,(conj #{5} #{1 2 3})
12:44clojurebot#{5 #{1 2 3}}
12:44AWizzArd,(conj #{1 2 3} #{5})
12:44clojurebot#{1 2 3 #{5}}
12:44AWizzArd,(conj 5 #{1 2 3})
12:44clojurebotjava.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IPersistentCollection
12:44AWizzArdhmm
12:45Chouseradd() desn't return the calendar. *sigh*
12:45Chouser,(conj #{1 2 3} 5)
12:45clojurebot#{1 2 3 5}
12:45AWizzArdChouser: yeah, that i sone of the not so beautiful things of the JVM. Some methods just return nil
12:45Chouser,(.before (GregorianCalendar.) (doto (GregorianCalendar.) (.add Calendar/DAY_OF_MONTH 5)))
12:45clojurebottrue
12:47Chouserunfortunately, in this case it's probably the right thing to do, short of making the objects immutable.
12:47Chousersure helps you remember you're mutating a thing, not getting a new object.
12:49AWizzArdyes
12:51MarkVolkmannA question about transaction retries ...
12:51MarkVolkmannI understand a transaction will retry if it attempts to modify a Ref that was modified by another thread since the current transaction began.
12:52MarkVolkmannDoes the retry automatically wait until that other transaction completes before trying again?
12:53kotarakMarkVolkmann: I think, the transaction sees the modified value only after the other transaction completed.
12:54MarkVolkmannRight, it doesn't see the other value, but it does not that another transaction changed it and that's why it retries.
12:54MarkVolkmannMy question is whether the retry begins as soon as it sees that situation or does it wait until that other transaction either commits or rolls back.
12:55kotarakMarkVolkmann: I don't think so. My understanding is, that the first transaction completes, and the another thread (which changed the ref) retries.
12:55MarkVolkmannBased on some test code I wrote it seems that it waits for the other transaction to finish. I just want to confirm that.
12:55digashChouser: sorry about the noise about the bug, just did not fully sync up lazy branch with contribs.
12:56Chouserdigash: ok, glad it's resolved.
12:56MarkVolkmannI think if two transactions try to change the same Ref, the first one that does it gets to finish and the other one retries ... but not until the first one finishes. I'd like to have someone confirm this though.
12:58ChouserI'm still too unskilled at reading the code in LockingTransaction.java
12:59kotarakMarkVolkmann: ok. I'm not that deep in the STM, but I got the impression, that the transactions are independent in the sense, that there is no "the first one gets it". Each transaction sees its value. And although the value might be changed in the transaction, if the other one commits first, this one has to try again. No matter which "first" changed the Ref.
13:06AWizzArdbtw, why is there now a clojure-sources.jar? Is that for my classpath, so that debuggers like jswat can access all Clojure code?
13:08MarkVolkmannOkay, I just verified that my guess was wrong.
13:08MarkVolkmannWhen a transaction restarts, it does not wait until other transactions whose changes made it restart complete.
13:09MarkVolkmannIt tries to make it's changes again, restarts again, over and over until it succeeds.
13:09MarkVolkmannIt's seems like not doing this may be a nice optimization ... unless I'm missing an important detail.
13:10AWizzArdkotarak: about your assumption "I think, the transaction sees the modified value only after the other transaction completed". rhickey told me some time ago that Clojure is semi-optimistic, and not fully. So it will not wait until the end of the transaction, but look from time to time if it makes sense to continue the transaction.
13:12AWizzArdMarkVolkmann: I would say that a transaction does *not* wait for others to finish.
13:12MarkVolkmannYeah, that's what I see in the results of my sample code.
13:12AWizzArdThey all try concurrently to change the object, semi-optimistically.
13:12AWizzArdoh ok
13:12kotarakAWizzArd: ok. As I said: in only got "impressions" and don't know the nitty-gritty
13:12AWizzArdkotarak: yes
13:13MarkVolkmannThis really illustrates the difference between using alter and commute.
13:13AWizzArdhow?
13:14MarkVolkmanncommute just keeps going through the transaction, modifying the in-transaction values even though another transaction has changed them. Then at the end of the transaction it reapplies the update functions using the last committed values.
13:15MarkVolkmannIn the output of my sample code, I can see lots of retries when I used alter, but not when I use commute.
13:16AWizzArdso commute will not retry as often?
13:17slashus2Order doesn't matter.
13:18MarkVolkmannIt seem to me commute will never retry. It will just use in-transaction values. The key point is that at the end of the transaction after it has decided to commit, it will call all the update functions again to ensure that their updates are based on the latest committed values, not in-transaction values.
13:19MarkVolkmannSomeone please correct me if I've saying something wrong!
13:19slashus2The order that you call the commutes in the transaction doesn't matter?
13:20MarkVolkmannI don't know about that. I think it does. My point is that what is happening in other transactions that modify the same Refs doesn't seem to matter until the commit point.
13:21MarkVolkmannThat's when it calls all the update functions a second time.
13:21MarkVolkmann... using last committed values instead of in-transaction values.
13:25Chouserright, commutes never cause a retry.
13:26Chouserthe function given to a commute is always called twice -- once to get the in-transaction value, once to get the commit value.
13:29AWizzArdhmm
13:30AWizzArdbut couldn't it be possible that some changes were made that make the commute superfluous?
13:31AWizzArdIf it does not rerun the transaction, it can not find out if this is the case
13:33AWizzArdMaybe commute is simply the wrong thing for transactions like that
13:34AWizzArdfor example for transferring money from one account to another (money in an online game, whatever). If one account is empty then no transfer should happen. But the if that checks for the balance is on top of the transaction.
13:35AWizzArdMarkVolkmann: anyway, good point, thanks for your test
13:36MarkVolkmannSure!
13:37AWizzArdMarkVolkmann: have a look into your private messages
13:46Lau_of_DKGood evening gents
13:50danlarkinhey what's a quick way to get an NPE? I'm testing my exception reporting
13:50Chouser,(nil)
13:50clojurebotjava.lang.IllegalArgumentException: Can't call nil
13:50Chouseroh
13:50rhickey(.foo nil)
13:51danlarkingracias
14:46leafwthe webpage needs updating: clojure.org/lazy says "(Note: this section describes work in progress, currently only available in the lazy branch of SVN)"
14:47cgrayhi, is there a modulo function that's convenient to use?
14:47redalastorcgray: rem
14:48gnuvince_,(rem 5 2)
14:48clojurebot1
14:48rhickeyleafw: updated, thanks
14:48cgrayredalastor: thanks
14:48leafwyou're welcome.
14:48Chouser,(mod 5 2)
14:48clojurebot1
14:49cgrayi tried mod...
14:49Chousercgray: it's more recently added than rem
14:49cgrayi wonder why it didn't work for me
14:51leafwdoes doseq hold onto the head of a sequence?
14:51Chouserit shouldn't
14:51leafwok.
14:53leafwso (doseq [i coll] ...) is the same as (loop [c coll] (if coll (do ..<use (first coll)>. (recur (rest coll)))))
14:55Chousernext not rest. you could macroexpand.
14:57leafwsorry, still on pre-lazy merge.
14:58Chouserah. well, macroexpand should still work. :-)
15:00leafwChouser: it does, but it shows ... lots of gutter
15:00leafw,(macroexpand-1 '(doseq [i (range 5)] (println i)))
15:00clojurebot(clojure.core/loop [sq__3897__auto__ (clojure.core/seq (range 5))] (clojure.core/when sq__3897__auto__ (clojure.core/let [i (clojure.core/first sq__3897__auto__)] (clojure.core/when true (clojure.core/when true (do (println i))) (recur (clojure.core/next sq__3897__auto__))))))
15:00leafwnotice the double when true when true.
15:00leafwis that really needed?
15:01leafwi.e. I don't understand why it's there.
15:02Chouserleafw: that's just to make the macro itself simpler. hotspot should get rid of the extra work in short order.
15:02leafwwhat does "in short order" mean?
15:03leafwI am sure the doseq macro handles much more cases than the simple one above.
15:05danlarkinHm. this is throwing the LazySeq used in 'if' exception: (if-let [result (context (keyword k))] ...)
15:05Chouserleafw: I mean that it is easy for hotspot to optimize away constant tests like that, so very few iterations should be necessary for it to catch on.
15:06danlarkincontext is a hash-map and k is a string
15:06Chouserleafw: yes, those extra tests are for supporting the :when and :while options.
15:06leafwthanks.
15:07Chouserdanlarkin: and the value is a lazy seq? :-)
15:09danlarkinChouser: Hm, yup that's the problem
15:10danlarkinI can't run (seq ...) on it though, since it isn't necessarily a sequential structure
15:11Chousersometimes it's a lazy-seq and sometimes it's something else?
15:11danlarkincorrect
15:12rhickeythen how is the if-let correct?
15:13danlarkinnot sure what you mean? I suppose it isn't correct, since it can end up testing for truth on a lazy seq
15:15rhickeydanlarkin: if it's a "I have something or not (nil)" scenario then this is a false positive, since even an empty lazy seq is something
15:15rhickeyyou don't need to fix it, but it won't work with the flag on
15:17Chouserpre-lazier it might have been correct, I suppose -- true if a non-empty seq or something else
15:17danlarkinlisppaste8: url
15:17lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
15:17rhickeyI think it's still correct, not all tests of lazy seqs are wrong
15:18Lau_of_DKrhickey: What criteria do you use to pick between proxy and gen-class?
15:19rhickeyThe whole point of () != false is to distinguish an empty thing from nothing, so a something/nothing detector is valid for lazy-seqs - not nothing
15:19lisppaste8danlarkin pasted "if-let" at http://paste.lisp.org/display/75976
15:20Chouseryes, the assert can definitely fire in cases that are actually correct.
15:20danlarkinso with assert-if-lazy-seq on that throws the warning, but is it actually correct?
15:20rhickeydanlarkin: right, you want to see if there's something at key :foo
15:22danlarkinokay then, good to know
15:22rhickeyit's not code that tested for empty with sequence return directly, the wrongness comes from your intent with if - is it if-there-is-a-colelction or if-non-empty-collection?
15:24danlarkinwell the value for the key can be anything, including a lazy seq
15:24Chouser(map #(if % :a :b) [1 (map identity [2]) (map identity [])])
15:25Chouserthat used to return [:a :a :b], and would now return [:a :a :a]
15:25ChouserI think.
15:26rhickeyright, if you want emptiness test you need seq
15:26Chouserthat's pretty contrived, but to get the old behavior now would take a few more words
15:29Chouser#(if (if (coll? %) (seq %) %) :a :b)
15:30rhickeyChouser: if that's really the intent they should seq the map results
15:32lisppaste8danlarkin annotated #75976 "untitled" at http://paste.lisp.org/display/75976#1
15:32Chouserah, good point.
15:32danlarkinokay, I can rewrite it that way and avoid this issue
15:32xooxIs there a predicate that always returns true?
15:32Chouser(constantly true)
15:32xooxthanks
15:34Chouserwhat are the possible value types of 'context'?
15:34Chouserreally anything?
15:34danlarkinit's user supplied, so anything
15:35danlarkinthis is library code
15:35Chouserand you need to accept lazy seqs and force them yourself to find out if they're empty, rather than requiring the user to force them?
15:35Chouserand yet treat other empty collections as true?
15:37danlarkinheh, all this code needs to do is first check if (keyword k) is in the map and if it is, return that -- otherwise return (context k)
15:39Chouser(contains? context k)
15:39Lau_of_DKGuys - Which criteria do you use to pick between proxy and gen-class? It seems to me theres a big overlap of functionality
15:40rhickeyLau_of_DK: proxy
15:40ChouserLau_of_DK: I use proxy whenever I can, as I'm sure you've gathered.
15:41danlarkinChouser: oh yes, contains? is (basically) what I used in my annotation. I used some... didn't realize contains? was in core now
15:41Lau_of_DKrich normally Im impressed by how concise you can be - but this time you took it too far :)
15:41Lau_of_DKChouser: And I want to follow that example, but I dont want to write a full proxy extension of a class to find out I should have gone with gen-class, so I need more info :)
15:41rhickeyLau_of_DK: if proxy meets the need, use it
15:42ChouserLau_of_DK: gen-class only if I absolutely need to add a method, get a specifically-named class, or access protected members of the superclass.
15:42Lau_of_DKOk, so if you just need a class, built on a superclass, but which has custom fields and methods, you'd go with proxy ?
15:43ChouserI've been intending to poke around inside proxy and see if it's really impossible to have it allow access to protected members.
15:43ChouserLau_of_DK: proxy can't add members beyond what the superclasses or interfaced define.
15:44Lau_of_DKChouser: I just realized that my question was partly spawned from a naive intention of just directly porting java code, when Clojure actually provides a better alternative
15:45Chouseryeah, that's common when dealing with both proxy and gen-class.
15:45Lau_of_DK:)
15:45Chouseri've got a blog entry percolating about some techniques for moving Java idioms to clojure ones.
15:45Lau_of_DKThis is where binding JMonkeyEngine will be interesting though - to see how much of it I can wrap in Clojurecode
15:45Chouserespecially as found in Java library examples
15:45Lau_of_DKCool - I really need to hook up some RSS to your blog
15:47Chouser"percolating" is code for "I'll probably never get around to it"
15:48Lau_of_DKoh...
15:48ChouserI've had a blog entry comparing iterator constructs in several languages for a few years now
15:48Lau_of_DK*cough* *geek* *cough*
15:48Lau_of_DKTry reading that sentense out loud Chris :)
15:49Chouserpercolating
15:49Chouserthat word belongs in there somewhere.
15:49gnuvince_Does anyone know of a blog post/article that would help people understand closures if they've never used them before?
15:55ayrnieuI'd go with http://letoverlambda.com/index.cl/guest/chap2.html
15:56digashwhat is the best way to store jvm/global state?
15:57digashlike i have an external sensors which I cannot access more often than ten times per second
15:57digashso where do i store last-access-time?
15:58ayrnieuthrottle the access through an agent.
15:59digashinteresting, is there some example somewhere? i am not familiar with agents.
15:59Brackicooldude127: Thx for your improved find-path function.
16:01BrackiI must admit though, that the (or (and (not (includes?.. part is hard to graps.
16:01Brackigrasp
16:03Bracki,(doc declare)
16:03clojurebot"([& names]); defs the supplied var names with no bindings, useful for making forward declarations."
16:03ayrnieudigash - not of this; but after you become familiar with agents, it'll be very easy.
16:05digashayrnieu: I dont get it yet, how to use agents to do throttle
16:07ayrnieudigash - you have the agent access the external device. It can sleep for a calculated (based on a last-access in its own state) or for a set time, and then access the device. Every request that the agent access the device will be interleaved and, with the agent sleeping, throttled.
16:07ayrnieubut actually, I'm thinking like an Erlang programmer. Just use a clojure.
16:08digashayrnieu: i see, use agent like erlang process and send requests to it.
16:09hiredmanor you could create your own thread pool executor
16:09hiredmanthat executes requests no faster then ten per second
16:11ChouserI think ayrnieu's first suggestion sounds good -- and agent that sends to itself to refresh its own state based on the sensor
16:11ayrnieudigash - the agent would throttle access even from multiple concurrent askers. If you don't have this, a closure is sufficient.
16:12Chouserthen all the other code can read the agent value whenever necessary.
16:12BrackiPuh, the agent example code is awfully hard to understand.
16:12ayrnieuyeah, that's an excellent suggestion.
16:12ayrnieumuch better than mine :-)
16:27senxhnsshphow do I chekc if something is null? nil?
16:27senxhnsshpie a java object
16:27Chouseryes, or just use in a boolean context
16:28Chouser,(if (new Object) :true :false)
16:28clojurebot:true
16:28Chouser,(if nil :true :false)
16:28clojurebot:false
16:36digashayrnieu: yes, i need to throttle from multiple askers, so that is why clojure is not enough for me.
16:36digashclosure^
16:38digashthanks for the suggestions i will try out the agent, how big is the send queue?
16:41BrackiHow do I make a :key from a "string"?
16:41hiredman,(keyword "string")
16:41clojurebot:string
16:44ayrnieudigash - use Chouser's suggestion.
16:44ayrnieudigash - if it's acceptable to access the external device every 1/10s
16:53Lau_of_DKRe gen-class, my :init function, can it accept clojure-types, and when Im told to return 'state', what is meant ?
16:55hiredmanwell, generally, a constructor sets up an initial state for a class
16:56hiredmaner
16:56hiredmanobject
16:56AWizzArdhiredman: can one also have uninitialized objects in Java?
16:56Lau_of_DKhiredman: yea...so... whats state?
16:57hiredmansome kind of state
16:57Chousergen-class classes get a single immutable state field
16:57hiredmanI think I returned a ref
16:57hiredmanfor state
16:58Chouseras named by the :state option
16:58hiredmanand the ref got put in the state field
16:58Lau_of_DKAh - So why isnt that just returned automatically ?
16:58Lau_of_DKWhy do I have to do :state name, and then later return name
16:59hiredmanno
16:59hiredmanyou don't return the name
16:59hiredmanyou return the value to be put in the field
16:59Lau_of_DKquote rich: Must return [ [superclass-constructor-args] state]
16:59Lau_of_DK If not supplied, the constructor args are passed directly to
16:59Lau_of_DK the superclass constructor and the state will be nil
17:00hiredmanthe state field's value will be set to nil
17:01senxhnsshp is it normal for just simple GUIs to take sveral hundred lines of code? i made na mp3player using JLayers decoder so I did just the GUI myself(in swing). it has play, stop, shuffle, and some playlist-functions. it is about 400 lines of code...seems a lot althought everything seems necessary
17:01senxhnsshpwait around 300 LOC in clojure
17:01AWizzArdsenxhnsshp: did you write those lines manually?
17:01senxhnsshpnow a lot of it is just wrapping java so it doesnt mean 1000 loc java but still
17:01senxhnsshpyes manually, how else?
17:02AWizzArdI did that.
17:02AWizzArdOnce.
17:02AWizzArdThank you, but, no thanks :)
17:02AWizzArdI am now using NetBeans
17:02AWizzArdYou can download it for free and click your gui together.
17:02senxhnsshpok, and it has a GUI for making GUIs?
17:02Lau_of_DKsenxhnsshp: Checkout MigLayout
17:02senxhnsshpoh nice, lol
17:02AWizzArdsenxhnsshp: it has maybe the best gui builder available
17:02AWizzArddefinitly one of the best
17:03senxhnsshpim using miglayout
17:07lisppaste8bracki pasted "What's wrong with the join function?" at http://paste.lisp.org/display/75986
17:07BrackiFirst branch of the if statement doesn't work.
17:09hiredmanBracki: paste the exception too
17:09hiredmanor explain what you mean by "doesn't work"
17:09lisppaste8bracki annotated #75986 "untitled" at http://paste.lisp.org/display/75986#1
17:10hiredmanactually
17:10hiredmancons needs to be conj
17:10BrackiWhy?
17:10Chouserthe first arg of commute needs to be a ref, not a vector
17:11hiredmancons takes arguments in a different order then conj
17:11hiredmanah
17:11hiredmanindeed
17:11pilkarndoesnt eclispe have somthing similar? i tried netbeans once and hated it. so slow and big
17:12BrackiHm, but isn't that a ref?
17:12Chouser*channels* is a ref
17:12hiredman@*channels* is whatever the ref points to
17:12BrackiSo I put all the dereferencing after that?
17:13Chouseryes
17:13hiredmaner
17:13hiredmanno
17:13Chouseryou might like update-in for that
17:13hiredmancommute does the deref for you, doesn't it?
17:14BrackiBut why does this: http://github.com/technomancy/mire/blob/e6c8943d9dd717fdb44654f248a03dcf1d2915d0/src/mire.clj#L18-23 work?
17:14slashus2AWizzArd: So you create the GUI part with netbeans, and the rest with clojure?
17:14Chousertrue, I was thinking he meant the key lookup
17:14hiredman,(commute (ref 1) doto prn)
17:14clojurebotjava.lang.Exception: Can't take value of a macro: #'clojure.core/doto
17:14hiredmanbah
17:15BrackiAh because bloody :inhabitants is a ref as well.
17:15technomancyBracki: which line in particular? there are nested refs
17:16technomancyBracki: if you're going to read the mire source, I'd recommend reading one branch at a time.
17:16technomancythe application is written step-by-step where each step builds on the last
17:16ChouserBracki: (commute *channels* update-in [(keyword channel)] conj user)
17:16technomancyand each step is separated into its own branch.
17:16technomancyI really need to update the readme to explain that.
17:17BrackiI hadn't looked at rooms.clj, I just assumed it to be a vector and not a ref to a vector.
17:18hiredman,(pl inc $ inc $ inc $ 0)
17:18clojurebot3
17:21pilkarnisnt it possibel to use skins for swing guis?
17:33AWizzArdsenxhnsshp: watch 6 minutes: http://www.netbeans.org/kb/60/java/swing-app-beans-binding-screencast.html
17:33AWizzArdyou get an impression of what NetBeans can do for your gui
17:34AWizzArd(you want to watch it maximized)
17:34AWizzArdslashus2: yes, I click my guis together with NetBeans and write the rest in Clojure
17:35AWizzArdfor example the event handlers
17:38slashus2How do you set up the event handlers to use clojure code? Just call clojure methods?
17:40slashus2AWizzArd:
17:41AWizzArdslashus2: with a proxy
17:44AWizzArdIn NetBeans I write an export method which returns all objects which I want to touch in Clojure. It's very simple, just a few lines, no thinking needed.
17:45AWizzArdIn Clojure then I make an instance of the class that NetBeans automatically generated, and call (.export my-frame), to get an array of all the widgets.
17:46ChouserAWizzArd: it generates Java source code for you, that you then compile?
17:46scodeI want to implement a blocking "wait for something to complete" (in this case, wait for some backgroudn I/O to complete). Would it be ideomatic to send-off a blocking function which does a mutex wait, and await? This is assuming there is hidden mutable state that is being waited on.
17:47Chouserscode: have you looked at 'future'?
17:48scodeChouser: No, not in clojure. Contrib lib?
17:48CardinalFangHi all. I'm trying to piece together a Ant "makefile" to create ahread-of-time compiled class files, which can package and do Stuff with. I'm having trouble with how to do that. I want to use some command-line doo-dad like "javac", which will take .clj and emit .class.
17:48Chouserscode: nope, recent addition to core
17:48Chouser(doc future)
17:48clojurebotTakes a body of expressions and yields a future object that will invoke the body in another thread, and will cache the result and return it on all subsequent calls to deref/@. If the computation has not yet finished, calls to deref/@ will block.; arglists ([& body])
17:48scodeChouser: Futures would be nice, even if somewhat implicit in this case.
17:48scodeChouser: Ah cool. Thanks!
17:49CardinalFang...but my thinking may not be at all Lisp-y. Please correct me or suggest something.
17:49hiredmanCardinalFang: the clojure source tree has a build.xml in it that does AOT compilation, so you should look at that
17:49CardinalFangOoo.
17:50CardinalFang"clojure.lang.Compile". Perfect. Thanks for the tip, hiredman.
17:54scodeChouser: Btw, any place to figure out that futures got added, other than following svn more closely? Did not see obvious mention on the ML (subject search ;)).
17:55Brackitechnomancy: If I understand everything correctly, the binding part in mire-handle-client makes the whole thing work right?
17:56AWizzArdChouser: yes, I compile the code in NetBeans. The .class files it generates I then put into my classpath that I set up in emacs. Then I can simply import these NetBeans classes in Clojure. I simple (import ..) will do.
17:57technomancyBracki: the binding part is one of many parts that makes the whole thing work. =)
17:57technomancyBracki: could you be more specific?
17:58BrackiWell, I wondered how you associate a user's state with *name*.
17:58technomancyBracki: ah yes, everything that needs to be thread-local happens in binding.
17:59BrackiI had expected that you have to save the connection info for every user somewhere, but this way you don't.
17:59Lau_of_DKtechnomancy: Is SLIME/Swank-clojure up and running with the latest rev. of Clojure?
18:00technomancyLau_of_DK: looks like it.
18:00Lau_of_DKcool
18:00technomancyBracki: sure, you "save" it in a binding. but you don't alter anything that already exists.
18:01technomancyBracki: the one exception is that you add each player's *out* stream to the *players* map so that players can speak to each other.
18:04Brackitechnomancy: Can players change their nicks?
18:05technomancyBracki: nope, not without reconnecting
18:05technomancydoes slime's fuzzy-completion package work with swank-clojure?
18:08ayrnieufor another way of doing this, look at chat-serve.clj and its used libraries in http://github.com/ayrnieu/clj-actors/
18:14BrackiNo, that'll spoil the fun and make my humble attempts seem useless.
18:14BrackiBut I'll look anyways.
18:18Brackigood night.
18:43MarkVolkmannI've got a question about root bindings of Vars.
18:43MarkVolkmann(def my-var 1) ; gives it a root binding of 1
18:43MarkVolkmannIsn't the only way to give it a new root binding, to all def again like this?
18:43MarkVolkmann(def my-var 2)
18:44Chouseror alter-var-root
18:44MarkVolkmannI'm experimenting with watchers.
18:44MarkVolkmannThey aren't catching that change to the Var.
18:44Chouserthey will if you use alter-var-root
18:45MarkVolkmannBut not if I use def?
18:45ChouserI think that's correct.
18:45MarkVolkmannThanks! I'll try it.
18:49MarkVolkmannIf I add a watcher to a Ref and then change the Ref with ref-set two times in a transaction, should the watcher be notified once or twice?
18:49MarkVolkmannMaybe just once since the first change is only to the in-transaction value.
18:49MarkVolkmannDoes that sound right?
18:50ayrnieuMark - the watcher won't be notified until the end of the transaction, as with all sends to agents.
18:54Chouserthere are changes planned for the watcher api
18:55Chouserhttp://code.google.com/p/clojure/issues/detail?id=80
18:56MarkVolkmannThanks!
18:56MarkVolkmannThe web page "Vars and the Global Environment" says this about def:
18:56MarkVolkmann"Supplying an initial value binds the root (even if it was already bound)."
18:56MarkVolkmannThat sounds like it can be used to give a new root value to an existing Var.
18:57MarkVolkmannHow does it differ from alter-var-root other than than alter-var-root takes an update function?
18:58Chousukemaybe alter-var-root is atomic?
18:58Chousukehmm
19:03Chouserlooking at the code, it appears that both 'def' and 'alter-var-root' should do validation and notify watchers.
19:04Chouserthat seems to work.
19:05ChouserMarkVolkmann: you might try your experiment again
19:07lisppaste8Chouser pasted "watchers on a Var" at http://paste.lisp.org/display/75994
19:12MarkVolkmannThanks!
19:12MarkVolkmannI think the issue is the way I'm tracking the changes.
19:13MarkVolkmannMy agent state is a map where the keys are reference objects and the values counts of the number of times that reference has changed.
19:13MarkVolkmannFor some reason this works for refs and atoms, but not vars.
19:13MarkVolkmannI suspect there is a problem with the way I'm trying to use Var objects as keys.
19:13MarkVolkmannStill digging ...
19:13MarkVolkmannI sent my code to the mailing list.
19:17MarkVolkmannI realize watchers won't get notified about calls to set!, but I'm trying to learn how to call set!.
19:17MarkVolkmannIt wants a var-symbol, not a var.
19:17MarkVolkmannHow do I get that?
19:18Chouser(def foo 7) (set! foo 42)
19:20senxhnsshphmm does javax.media come with java? because i cant find the jar in clojure-java-jars but i can import it. wodnering if maybe i put it somehwere weird
19:20MarkVolkmannThat's what I was trying initially. I'm getting IllegalStateException: Can't change/establish root binding of: my-var with set
19:21MarkVolkmannI get the same thing when I run your code example in a REPL.
19:23ChouserMarkVolkmann: yes
19:23Chouserthat's correct
19:23Chouser:-)
19:23MarkVolkmannIs it clear why that doesn't work?
19:23Chouser,(binding [filter 99] (set! filter 7) (prn filter))
19:23clojurebot7
19:23senxhnsshphow does stuff like RealPlayer and DivX make money?
19:24Chouser'set!' is only allowed when a thread-local binding has been created
19:24MarkVolkmannOkay, thanks!
19:25jochutechnomancy: swank-clojure doesn't support fuzzy completion as of yet. It does have compound prefix completion though.
19:26AWizzArdhmm, I didn't know about this alter-var-root. Is it new in Clojure? Why are so many side-effectish things added?
19:27drewrAWizzArd: I was just thinking that.
19:27rhickeyAWizzArd: don't use them!
19:28AWizzArdI won't. But their existance will be heaven for people coming from imperative languages.
19:28drewr...and their demise. Muahaha.
19:31AWizzArdI mostly considered def as a defconstant. That one can overwrite it with a new def was only for allowing dynamically evolving the system during runtime, and for administrative purposes.
19:34Chouserthe naming convention for vars that will be changed with alter-var-root is like: ==>->foo<-<==
19:36Chouserconsensus by fiat
19:36AWizzArdwell, the name is of course a bit longer than setf, and it is not as easy to use, but basically it sounds as if Clojure has very easy access to imperative operators now.
19:38Chouserit always did, thought Java interop, re-def'ing, etc. We just politely remind people they shouldn't do it every time they ask a question.
19:38Chousereventually they stop asking
19:38ayrnieuand Erlang can get()/put() everything, and Haskell and use functionsWithScaryNames
19:39Chouser,(let [x (clojure.lang.Box. 7)] (set! (.val x) 42) (.val x))
19:39clojurebot42
19:39AWizzArdmaybe these set!s and alter-var-root things should just disappear, to enforce a less imperative style
19:39rhickeyyes, Clojure is not generally about prohibition, but rather recipes and ingredients for success
19:39Chouser,(let [x (atom 7)] (swap! x inc) @x)
19:39clojurebot8
19:40AWizzArdthe atom approach is different
19:40Chouseris it really?
19:40AWizzArdit is one of the few explicit constructs for managing state
19:40ChouserI mean, it's slightly different, but pretty easy to abuse
19:40AWizzArdyes
19:41AWizzArdWas nicer when there were only refs and agents
19:41Chousernah
19:41rhickeyAWizzArd: then just use refs and agents
19:41ayrnieuas if you can't abuse refs and agents.
19:41rhickeyreal programs need more, and I'm happy to oblige - I've done a lot of MT programming and I want to make it safe
19:42Chouseragents are pretty easy to abuse -- refs a bit harder.
19:42AWizzArdrhickey: well, I don't see the problems for myself or my team. We can have an agreement of not using set! or alter-var-root without having a meeting first.
19:42rhickeyAWizzArd: exactly right
19:42AWizzArdayrnieu: yes, one can abuse anything, it just was very obvious what those constructs are for
19:43AWizzArdI am not so convinced that people coming from imperative langauges will also have so strict rules
19:44rhickeyAWizzArd: all the mutable reference types have the same effect on a program's referential transparency, they only differ in concurrency semantics, all sharing safety
19:45Chouserrhickey: do you have any thoughts about printing type hints as propogated by the compiler?
19:45AWizzArdrhickey: yes, it's of course safer this way, but still.
19:45rhickeyprinting during compilation?
19:45AWizzArdhmm, good idea.. one could have a warning for each set! and each alter-var-root that can not be surpressed
19:45AWizzArdthat would be a nice thing
19:46Chouserrhickey: yeah, I guess. or with a separate step like macroexpand
19:46rhickeyAWizzArd: sorry, responding to Chouser's q
19:46ChouserAWizzArd: cannot be supressed!? yikes
19:46AWizzArd:)
19:46rhickeyChouser: I think there is a general need amongst tools to access to the analysis tree
19:47ayrnieuAWizzArd, write a clojure lint. Popularize it. Recommend it to newbies. etc.
19:48rhickeyin my spare time :)
19:48Chouserrhickey: that task doesn't really need you, does it? or do you have Grand Plans?
19:48AWizzArdayrnieu: yes, I discussed this with a few people already. It could have an optional static type system. But maybe Mark Tarver can be convinced to port Qi to Clojure :)
19:48teHello all.
19:49AWizzArdHello te
19:49Chouserte: hi
19:49rhickeyChouser: I don't know, there's just the last little bit I had/have to do in Java I'd like to get rid of
19:49teHow goes the clojure hacking?
19:50rhickeyAWizzArd: I think once we have Datalog you will be able to build a logical model of type signatures and validate it, completely outside of the code
19:50AWizzArdsounds good
19:51AWizzArdI had something like the Erlang Dialyzer in mind.
19:51rhickeyI like Qi's approach
19:51AWizzArdyes
19:52AWizzArdthe Dialyzer is doing completely optional type analysis and referring to http://www.it.uu.se/research/group/hipe/dialyzer it found several bugs in a huge code base
19:52AWizzArd"Dialyzer has been applied to large code bases, for example the entire code base of AXD301 consisting of about 2,000,000 lines of Erlang code, and has identified a significant number of software defects that have gone unnoticed after years of extensive testing."
19:53AWizzArdobviously in a dynamic system not all potential type errors can be caught
19:53powr-tocI'm toying with some concurrency code which needs to read/write state to disk. Naturally I need to prevent parallel read/writes to the same data... I'm looking at implementing it with two agents (with watches) each managing a hashmap of executing reads/writes, so as to effectively perform a read/write lock... does this sound reasonable? Or should I just use a java concurrent read/write lock?
19:54teIf I manage to hang the REPL in emacs-- is there is a command to abort running that code, or do I need a new REPL?
19:55AWizzArdpowr-toc: maybe an agent that removes read/write jobs from a queue and runs them, while any number of other threads write their jobs into that ref?
19:56rhickeypowr-toc: if the targets are known, you can just set up an agent as a gatekeeper for each one, an agent will effectively serialize access
19:57powr-tocAWizzArd: that would serialize reads though. I want to parallelise reads and only lock in the case where a read/write is done to the same location.
19:57powr-toc(I want to parallelise writes as well).
19:58AWizzArdChouser: did you just say that the watcher interface will change?
19:58ChouserAWizzArd: http://code.google.com/p/clojure/issues/detail?id=80
19:59AWizzArdthx
20:00AWizzArdbtw, is force still needed?
20:00AWizzArdIt seems delays now work fine with deref
20:00rhickeyAWizzArd: force allows apis that work on both delays and non
20:00rhickey,(force 42)
20:00clojurebot42
20:01AWizzArdoh good
20:01rhickey,(deref 42)
20:01clojurebotjava.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IDeref
20:01powr-tocrhickey: That sounds like the approach I'm taking... I'm pretty new to clojure, so I'm just sanity checking. Essentially I'm wanting to implement a simple key/value database-store, to cache large pre-calculated datasets in a concurrent application
20:01AWizzArdapropos delays, does it make sense to run them in their own thread, just as futures, with the difference that their threads don't run immediately?
20:02ChouserAWizzArd: why?
20:02AWizzArdmakes not much sense right?
20:03AWizzArdthe thread requesting data would have to wait anyway
20:03ChouserI'm just wondering what benefit you see in suggesting the change.
20:04AWizzArdmaybe there is an obvious benefit that I haven't seen *shrugs*
20:05pilkarncan i call super from clojure?
20:05Chouserpilkarn: yes. proxy or gen-class?
20:07AWizzArdpilkarn: btw, a cool tool that Clojure offers is find-doc. It can help to find starting points if you have some term about the issue: (find-doc "super")
20:11pilkarnwhat license do I use for: here is what I wrote, do whatever you want with it and blame for anything and yes you can close the source(ie not gpl) fi you want but you cant add something to it and then claim i cant use that.
20:16lisppaste8pilkarn pasted "super java" at http://paste.lisp.org/display/75997
20:16slashus2ayrnieu: http://github.com/ayrnieu/clj-actors/ <-- Is this an example of how the actors model may look in clojure if it is ever added?
20:16pilkarn^^
20:19ayrnieuslashus - no, it's an actors library with a networking library, and some examples.
20:20AWizzArd,(find-doc "weak")
20:20clojurebotnil
20:21pilkarnhow would I implemetn my paste? with gen-class or proxy?
20:21powr-tocwhat would be idiomatic clojure for writing a serializable object to disk?
20:21ayrnieuthe 'Concurrent architecture for Clojure' tagline says enough. If you're interested in it, you should fork it. Add a distribution layer, etc.
20:21powr-tocis it to drop to java?
20:22Chouserpowr-toc: For clojure objects you can use prn and friends.
20:22AWizzArdpowr-toc: you can (binding [*print-dup* true] (print my-clojure-object))
20:23Chouserpilkarn: probably proxy
20:23AWizzArdin in that binding you can as well bind *out* to some stream that points to your file
20:24powr-tocChouser: does that serialize as an ascii sexp, or as a binary sexp, or something else?
20:24Chouserpowr-toc: ascii sexp. well, utf-8 probably
20:24AWizzArd,(binding [*print-dup* true] (print [1 2 3]))
20:24clojurebot[1 2 3]
20:24AWizzArd,(binding [*print-dup* true] (pr-str [1 2 3]))
20:24clojurebot"[1 2 3]"
20:25AWizzArd,(binding [*print-dup* true] (pr-str {:a 1 :b 2}))
20:25clojurebot"#=(clojure.lang.PersistentArrayMap/create {:a 1, :b 2})"
20:25powr-tocI guess that'll do for now... Whilst I get the concurrency stuff sorted out... Ultimately though I'll need to serialize large bitsets
20:27cp2i love github
20:28powr-tocWhat is the convention around *foo* variables? And where are they documented?
20:28cp2useful to look at everyone's clojure projects
20:28cp2:)
20:29durka42powr-toc: all the *foo* vars are supposed to have docstrings
20:29durka42,(doc *print-dup*)
20:29clojurebot"; When set to logical true, objects will be printed in a way that preserves their type when read in later. Defaults to false."
20:29Chouserpowr-toc: indicates the var is meant to be rebound using 'binding'. Dunno if it's documented anywhere other than in lengthy discussion group threads.
20:30Chouserdurka42: lots of vars without * have doc strings.
20:30powr-tocdurka42: Ok, I tried that and got back nil for print-dup... I guess my clojure's a little long in the tooth :-)
20:30durka42well, since fns are vars, i suppose so :)
20:31powr-tocok, I'm on svn rev 1162... guess I need an update :-)
20:31hiredman~latest
20:31clojurebotlatest is 1299
20:31ayrnieuyou can say it's a CL-ism that doesn't make sense when you separate binding from let , or you can say that it helps identify a global environment variable like print-dup without , in a lisp-1 , interfering with the function itself.
20:31durka42be careful updating... you may break everything
20:32durka42isn't 1162 the last revision before the move to google code?
20:32durka42~svn rev 1163
20:32clojurebotsvn is http://clojure.googlecode.com/svn/trunk/
20:32hiredmansvn rev 1163
20:32powr-tocdurak42: probably is... svn up doesn't update... I'll switch repos and try again
20:33hiredmanclojurebot's svn.clj needs an over haul
20:33teI am struggling a little bit to understand refs and dosync
20:33powr-tocare there any plans to migrate clojure to git, or is that a dirty word? :-)
20:34ayrnieute - http://en.wikipedia.org/wiki/Software_transactional_memory
20:34ayrnieupowr - look for clones on github.
20:34teayrnieu: thanks ill read it
20:34AWizzArdpowr-toc: there already is a clojure repo
20:34AWizzArdbut svn works very well for rhickey so far
20:34clojurebotsvn rev 1163; made default build run clean
20:35powr-tocIs it frequently updated?
20:35teayrnieu: what about persistence with the STM?
20:35AWizzArdbtw, why git and not Mercurial? ;)
20:35AWizzArdpowr-toc: yes, very frequently
20:35ayrnieute - what about it?
20:35teayrnieu: Just trying to understand if persistence applies to the STM or not
20:35powr-tocAWizzArd: is it a direct clone, or are there other patches applied to it?
20:35AWizzArddirect clone
20:35ayrnieute - they have nothing to do with each other.
20:36teayrnieu: thanks
20:36powr-tocAWizzArd: is this the repo? git://github.com/kevinoneill/clojure.git
20:36AWizzArdexactly
20:36powr-tocsweet
20:36slashus2What about bzr?
20:37AWizzArda few months now it gets very frequent updates
20:37slashus2bazaar VCS
20:37powr-toclol - I didn't mean to start a flame war... I should never have asked :-)
20:37AWizzArdmaybe darcs?
20:38pilkarnclojure uses STM right?
20:38durka42yes, with refs
20:38ayrnieupilkarn - refs provide STM.
20:38slashus2Bazaar is similar to git, but it doesn't have as steep of learning curve.
20:38AWizzArdyes
20:38pilkarnwe should make a distributed version ctrol system!
20:38pilkarnor not
20:38AWizzArdyeah sure, there is need for one ;)
20:39AWizzArdanyway, powr-toc, this issue comes up every few days, but so far svn works very well. No need to switch
20:40powr-tocAWizzArd: thought as much... Like I said I didn't mean to stir, I should've known better than to ask :-)
20:46AWizzArdpowr-toc: btw, if you get your concurrent reads + writes running let me know pls
20:46teomg I think I just understood something in clojure
20:46AWizzArdgrats te, what is it?
20:47teBasic stuff, refs, derefs
20:47teive been playing a lot and messing things up, trying to understand how to fit pieces of stuff together
20:47tethe idea of #{} is pretty jarring at first tbh
20:48ayrnieu_the idea of set literals?
20:48tenod
20:48teI just think in general I'm starting to understand the structure.
20:49teIt feels a little bit more natural than it did yesterday.
20:49powr-tocAWizzArd: I'm just toying about, but if there's interest I might throw it up on github or something
20:50AWizzArdsounds good
20:51powr-tocAWizzArd: as I said I'm mostly doing it to learn about clojures concurrency primitives... There's a slim chance if I get anywhere that I might use it in production
20:51lisppaste8pilkarn pasted "untitled" at http://paste.lisp.org/display/75999
20:52durka42eww, java
20:52durka42:)
20:52pilkarnhttp://paste.lisp.org/display/75999 <- so what should I proxy there?
20:53pilkarn JTextArea or JFrame?
20:53durka42JTextArea, i think
20:53powr-tocI want to focus on correctness first, then wrapping it up in java api, then maybe performance.
20:54durka42pilkarn: what does the block marked "instance initializer" do?
20:54durka42is that an anonymous constructor?
20:57cp220:52:27 [durka42] is that an anonymous constructor?
20:57cp2no
20:57tewow this is awesome.
20:57cp2its just in its own block
20:57te(show #{})
20:57cp2oh
20:57tei know that's pretty meh., but that does me a world of good
20:57cp2its not in any method
20:57cp2durka42: its basically a "quick" way to get something shoved into the default constructor
20:57durka42te: c.c.repl-utils is awesome
20:57senxhnsshpdurka42: iwas wondering the same thing :)
20:57tedurka42: yeah this is amazing
20:57te:)
20:58durka42cp2: proxy can't do that, can it?
20:58cp2i dont know
20:58tedurka42: I can't seem to get my emacs to complete clojure.contrib
20:58durka42also those instance variables are going to have to be in a let wrapped around the proxy
20:58teany ideas?
20:58durka42te: don't use emacs, don't know, sorry
20:58teoh no prob
20:58durka42err, as in i don't use emacs, not telling you not to
21:01teoh cool -- i see what Lancet is now
21:02teit took me awhile to really start to freaking understand this stuff
21:02teit was like i had sunglasses on
21:03senxhnsshphow do I refer to this?
21:03ayrnieusenx - in gen-class or in proxy?
21:04teso do i understand right, collections are [], (), and {}?
21:04senxhnsshpproxy
21:04ayrnieu,(map coll? [[] () {} #{} "" 1 :hi 'hi 1/2])
21:04clojurebot(true true true true false false false false false)
21:05tebooya!
21:05teyou rule.
21:09te,(map coll? [\a])
21:09clojurebot(false)
21:09te,(map coll? [[\a]])
21:09clojurebot(true)
21:11pilkarnhow do I refer to this in proxy?
21:11Chouserthe name 'this' is bound for you.
21:12pilkarnso just, this
21:12Chouseryes
21:14RaynesI wish somebody would make a Clojure wallpaper, I don't feel like it :|
21:14pilkarnand super?
21:15ayrnieu,(ancestors String)
21:15clojurebot#{java.lang.Object java.lang.Comparable java.lang.CharSequence java.io.Serializable}
21:15powr-tocam I right in thinking watchers used to be just functions but are now agents?
21:15Chouserpilkarn: proxy-super
21:15Chouserpowr-toc: yes
21:16lisppaste8pilkarn pasted "untitled" at http://paste.lisp.org/display/76000
21:16tehaha -- Man I am getting a kick out of clojure
21:17Chouserpowr-toc: they used to be called 'watches' and worked only on agents
21:17pilkarnwhy am I getting a nullpoinrtexception from that code ? ^^
21:18pilkarni dont really know what im doing but i didnt expect a nullpointer exception
21:18powr-tocChouser: yeah... this is hurting my head... I used to have a watch on an agent, that would then dispatch a message to another agent... now watchers are agents, do I need to do that?
21:19Chouserpowr-toc: probably not
21:20hiredmanpilkarn: are you sure JPane shouldn't be JPanel?
21:20Chouserpowr-toc: might depend on the args you used to pass to the agent action
21:22hiredmanpilkarn: NPE with proxy usually means clojure cannot resolve the class you are trying to proxy
21:22hiredmanresolve? locate? use?
21:22te(if "foo" "We are in clojure" "We are in common lisp")
21:22tereturns "We are clojure"
21:23teyet (true? "foo") == false
21:23tenevermind im an idiot
21:23teim just trying to get it to print the else without reading ahead
21:23powr-tocok, so here's the deal I have an agent encapsulating a map. Every N modifications I want it to rewrite itself to disk. I don't see why I need the watcher to be an agent, as it doesn't have any state... essentially I just want a callback to do the dispatch to a writer agent.
21:24powr-tocare there any simple examples demonstrating watchers??
21:24ChouserI have an example. I don't know if its simple. Just a sec...
21:26powr-toc(actually that's not strictly true... It serializes everytime the map's size is a ^N... i.e. every Nth add (assuming no removes))
21:27cp2ah windows, what a joy you are!
21:28ayrnieute, that would say "We are in clojure" in CL.
21:28Chouserpowr-toc: http://gist.github.com/32494
21:28powr-tocChouser: cheers mate
21:28Chousernot very simple, sorry.
21:29powr-toclol... no a little more complex than I was hoping =)
21:29Chouserthe code you want is in use-agents
21:30powr-tocChouser: ok.. so I take it there, your watcher-agent has no state?
21:30Chouserhere's the related blog entry. http://blog.n01se.net/?p=34
21:30powr-toci.e. (agent nil) is just to appease the add-watcher API?
21:30Chouseryes, that's right
21:30rlbWhy would (.update msg-dig buf) work but (.update msg-dig buf 0 5) fail? Clojure complains about not being able to cast java.nio.DirectByteBuffer in the second case (buf), but not in the first. msg-dig is an instance of java.securityMessageDigest.
21:32Chouserno such class?
21:32powr-tocWhat is the motivation for making watchers agents?
21:33Chouserpowr-toc: watches used to be synchronous -- run in the same thread as the agent they were watching
21:33rlbChouser: which class? The program works fine as long as I don't call the update method that takes an offset and count.
21:33Chouserpowr-toc: when watchers were added to ref, atom, agents, etc. they were made to run on agents so they would be asynchronous.
21:34Chouserpowr-toc: apparently rhickey now wants them to be synchronous again -- I'm not sure what that'll do to the api.
21:34powr-tocChouser: yeah I remember that... but isn't it better to allow them to be synchronous, as asynchrony is easily added by passing off directly to an agent
21:35Chouserpowr-toc: yep, exactly as the issue describes: http://code.google.com/p/clojure/issues/detail?id=80
21:35powr-toci.e. the current design seems to force you through another asynchronous message, even if you don't want it
21:36powr-toclol, rhickey's always ahead in design :-)
21:37senxhnsshphttp://confusion.tweakblogs.net/blog/1418/why-functional-programming-doesnt-catch-on.html <- and there clojure comes in. I have just "finsihed" an mp3player in it(ok mostly wrapping swing).
21:37rlbIs it possible that clojure just doesn't handle the second update method (overload) properly?
21:37powr-tocpresumably that'll mean the return to a 3 arity function again?
21:39Chouserrlb: no
21:39Chouserrlb: I don't have a java.securityMessageDigest class
21:39senxhnsshpah JPanel duh
21:40rlbChouser: http://java.sun.com/j2se/1.4.2/docs/api/java/security/MessageDigest.html
21:40rlbI'm just using the current clojure .zip and the Debian unstable java packages.
21:41hiredmanI also get a classnotfound for that class
21:42Chouserjust missing a dot
21:42Chouser(show java.security.MessageDigest "getInstance")
21:42rlboh, soory.
21:42rlbs/soory/sorry/
21:42Chousersorry: (show java.security.MessageDigest "update")
21:42rlbRight -- (java.security.MessageDigest/getInstance "sha-1")
21:42Chouserthe method with 3 args takes a byte[] as the first arg
21:43Chouserinstead of ByteBuffer like the 1 arg method
21:44rlbOK, so clojure isn't matching the Java docs. (Thanks for pointing out "show".)
21:45hiredmanuh
21:45hiredmanjava isn't matching the javadocs
21:45Chouser(.update (java.security.MessageDigest/getInstance "sha-1") (.getBytes "foo") 0 5)
21:46cp221:38:39 [rlb] Chouser: http://java.sun.com/j2se/1.4.2/docs/api/java/security/MessageDigest.html
21:46cp2why are you looking at the 1.4.2 doc
21:46hiredmanhttp://www.docjar.com/docs/api/java/security/MessageDigest.html
21:46cp2http://java.sun.com/javase/6/docs/api/java/security/MessageDigest.html
21:47cp2there is an update(byte[])
21:47rlbcp2, hiredman: oh, that's obviously my problem.
21:47cp2yes :)
21:48rlbI had just hit the 1.4 docs first and hadn't gone further.
21:48rlbThanks for the cluebat.
21:49slashus2,(array-map 1 1 1 1 1 1 2 2)
21:49clojurebot{1 1, 1 1, 1 1, 2 2}
21:49slashus2{1 1 1 1 1 1 2 2}
21:50slashus2,{1 1 1 1 1 1 2 2}
21:50clojurebot{1 1, 1 1, 1 1, 2 2}
21:50Chouserslashus2: yeah, don't do that. :-)
21:50slashus2I was wondering because when I put the previous one into my repl, I get the correct answer {1 1, 2 2}
21:51Chouser,(:a {:a 1 :a 2 :a 3})
21:51clojurebot1
21:51slashus2user=> (array-map 1 1 1 1 1 1 2 2)
21:51slashus2{1 1, 1 1, 1 1, 2 2}
21:51slashus2user=> {1 1 1 1 1 1 2 2}
21:51slashus2{1 1, 2 2}
21:51Chouserhm, what version of clojure?
21:52slashus2The latest svn
21:52slashus2wait
21:52slashus2No, that was the December release.
21:52slashus2sorry
21:52slashus2I thought I had my path setup to run the latest svn.
21:53Chouserit was probably a hash-map.
21:53Chouseroh. i guess not
21:53slashus2No, (class gives an array map
21:57slashus2Is this correct behavior?
21:59Chouserslashus2: http://groups.google.com/group/clojure/msg/7e330411cd04ca71
22:01slashus2eh
22:01powr-tocAre there any clojure functions to create and write to files?
22:01powr-tocor do I just use Java?
22:01Chouserpowr-toc: clojure.contrib.duckstreams, or just Java.
22:02Chouserby which I mean calling into Java class APIs from clojure code, of course, not actually writing a .java file.
22:02powr-tocChouser: yeah, I knew what you meant :-)
22:03pilkarn (proxy [WindowAdapter] []
22:03pilkarn (windowClosing [evt] /////// doe sit have to be like that? is it class and then what class-args and then methods for the class?
22:03Chouserok, good. You mentioned dropping to java earlier, and I didn't want to give you any encouragement.
22:03pilkarnwindowClosing ins a method on WindowAdapter?
22:04powr-tocChouser: Ultimately I'll need to create a java callable API out of whatever clojure code I write... but not yet :-)
22:04Chouserpowr-toc: gen-class
22:04slashus2So, even though there are inconsistencies between hash-map and array-map, it will continue to behave this way?
22:04Chouserwhen you get there
22:05powr-tocChouser: sweet! :-) It should be pretty minimal... probably just one or two classes
22:05Chouserslashus2: apparently. You'd prefer the check when building an array-map?
22:05powr-tocChouser: btw... is there any way to create java-docs with genclass or the like? That would be awesome!
22:06slashus2Just for consistency sake.
22:06Chouserpowr-toc: not yet, I think.
22:07slashus2,{1 1 1 1 1 1 2 2 3 3 4 4 5 5 6 6}
22:07clojurebot{1 1, 1 1, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6}
22:07slashus2,{1 1 1 1 1 1 2 2 3 3 4 4 5 5 6 6 7 7}
22:07clojurebot{1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7}
22:08slashus2In practice, it looks strange, especially when it automatically switches when your map gets longer.
22:08Chouserwhy would you build an array-map with duplicate keys?
22:08senxhnsshpwhy is ther eno lazy-conj? how do I lazily add somethign to a vector?
22:08Chousersenxhnsshp: vectors aren't lazy
22:09digash,(binding [clojure.core/*print-dup* true] (read-string (pr-str (clojure.xml/parse (java.io.StringBufferInputStream. "<a>A</a>")))))
22:09clojurebotjava.lang.RuntimeException: java.lang.IllegalArgumentException: No matching method found: create
22:09digashisn't it suppose to work?
22:11Chouserhm, struct maps do not yet print and readable way.
22:12powr-tochas clojure-contrib been updated to avoid lazy-cons yet?
22:13Chouserdigash: http://clojure-log.n01se.net/date/2008-12-29.html#17:49b
22:13Chouserpowr-toc: mostly
22:14digashChouser: are you really a person or AI? :)
22:14slashus2Chouser: It seems to only be the case when the array map is being built. When you use assoc, it will not create a duplicate.
22:15Chouserslashus2: right
22:17digashChouser: parse/emit should work for me, thank you again.
22:17powr-tocmy bad... I was pointing at an old clojure-contrib.jar
22:19slashus2I guess the argument from inconsistency won't persuade. Besides, I can't think of a good reason that someone would build an array map with duplicate keys. It would just be nice to apply that assumption to every map.
22:24lisppaste8pilkarn pasted "proxy problem" at http://paste.lisp.org/display/76005
22:24senxhnsshpcant i let there ^^
22:24Chouserno
22:24Chouserdo it outside the proxy
22:27lisppaste8pilkarn annotated #76005 "untitled" at http://paste.lisp.org/display/76005#1
22:27senxhnsshphttp://paste.lisp.org/display/76005#1
22:27senxhnsshpthing is i dont really understna dwhat im doing :P
22:32xavieranarray-map and hash-map should be consistent!
22:33slashus2I thought I was the only one.
22:36CptPicard.... which means...?
22:39CptPicardhmmh so... what's the definition of the keyset of the map?
22:39CptPicardis it a set or a multiset..
22:40slashus2CptPicard: Would it be better to call it an associative array?
22:40pilkarnhas anyoen ever displayed a bitma s background ina swinggui? how did you do it?
22:40CptPicardmaybe... better term..
22:41CptPicardbut of course the problem is... if you have equivalent keys and many of them, which of the associated items do you get out of the map?
22:41Chouserthe first
22:41CptPicardok
22:42Chouserit's an array, it is scanned for the first matching item.
22:42Chouser,(:a {:a 1 :a 2 :a 3})
22:42clojurebot1
22:42slashus2" collection of unique keys and a collection of values, where each key is associated with one value (or set of values)"
22:42CptPicardslashus2, well, arraymap is the latter case.. set of values
22:42CptPicard:)
22:43CptPicardI guess I can see the rationale for it to be inconsistent... at least you have that sort of functionality when you need it..
22:43slashus2CptPicard: That doesn't mean that. The first part exclusively says that it is a collection of unique keys, the second part is talking about what those unique keys may be associated with.
22:44pilkarnhow do I override a method fo a superclass?
22:44CptPicardwell the keys are unique, it's just that array-map is an implementation tactic.. :-)
22:45CptPicardthe map value could just be "some object" otherwise...
22:46slashus2Is it true that a hash-map's performance profile is better when a map becomes larger?
22:46Chouser(foo :x [1 2 3]) ==> ((:x 1) (:x 2) (:x 3)) What's foo called?
22:46CptPicardcompared to what?
22:46slashus2CptPicard: Compared to an array map.
22:46CptPicardsure.. linear vs. constant time
22:47slashus2right
22:47Chouserinner collections can be seqs or vectors.
22:48rlb(Hmm, I must still be doing something wrong -- passing a byte[] to "update/digest" works fine, but trying to use what I think is the same content via a ByteBuffer, doesn't.) Oh well, I'll come back to it later.
22:48rlb(by doesn't, I mean it generates an incorrect checksum)
22:48pilkarnJTextArea textArea = new JTextArea() { super.paintComponent(g); }
22:49pilkarnis that calling the paint method on its super-class?
22:52hiredmanChouser: I give up, what is it called?
22:53hiredman,(map (partial list :x) [1 2 3])
22:53clojurebot((:x 1) (:x 2) (:x 3))
22:53ChouserIt's a real question, not a quiz.
22:53Chouserhm, not bad.
22:53ChouserI have 3, but I don't like any of them
22:54hiredmanI have no idea what you'd call that
22:54Chouser,(for [value [1 2 3]] [:x value])
22:54clojurebot([:x 1] [:x 2] [:x 3])
22:55hiredman~for
22:55clojurebotfor is not a loop
22:55Chouseroh, actually the other two were wrong.
22:55hiredmanhmmm
22:55hiredman~for
22:55clojurebotfor is not a loop
22:55hiredmanfine
22:55hiredmanhmmm
22:58pilkarnahahahah
22:59pilkarnhead explosion
23:03hiredman, (
23:03clojurebotEOF while reading
23:03hiredmanerp
23:03hiredman,(map (partial apply list) (apply array-map (cons :x (interpose :x [1 2 3]))))
23:03clojurebot((:x 1) (:x 2) (:x 3))
23:07danlarkinI liked (map (partial list :x) [1 2 3]) better
23:10rlbThis:
23:10rlb(def d (java.security.MessageDigest/getInstance "md5"))
23:10rlb(def v (java.nio.ByteBuffer/allocateDirect 1))
23:10rlb(.put v 0 102)
23:10rlb
23:10rlbdoes not give the right digest if you call (.digest d) after that.
23:11rlbi.e. if you create a file containing a single "f" and run md5sum on it, the result is different.
23:11rlbHowever if you use a byte[] rather than a ByteBuffer, it works.
23:12rlb(assuming I'm not doing something else silly...)
23:14ChouserHow are you creating the ByteBuffer?
23:14hiredmanuser=> (*1 (repeat :x) [1 2 3])
23:14hiredman((:x 1) (:x 2) (:x 3))
23:14rlbChouser: see the "def v" above.
23:14rlb(followed by the .put)
23:14Chouseroh
23:15Chouserhm.
23:16rlbI though maybe I was printing the contents in hex improperly, so I double-checked the result with a series of (.get digest i) calls.
23:16rlbIt was still wrong.
23:17rlbHowever, I'm very new to nio, so I may well be doing something wrong.
23:17Chouserwell, here's what I've done this weekend: http://gist.github.com/68781 produces http://clojure.googlegroups.com/web/issues-graph.png
23:18danlarkinOoooooooo
23:18rlbChouser: nice.
23:19Chouserrlb: how are you printing the byte array?
23:19digashChouser: very cool, i needed an example how to use JChart.
23:20rlbChouser: I was just using a per byte print, but then I realized java only has signed bytes, and switched to this:
23:20rlb(which may be wrong)
23:20rlb(dorun (map
23:20rlb (fn [x] (println (bit-and x 255)))
23:20rlb (seq (.digest d))))
23:20rlb(println)
23:20rlb
23:21slashus2Chouser: Is there a reason that you used (Integer. n) instead of (int n) ?
23:21slashus2line 40-41
23:22Chouser,(int "5")
23:22clojurebotjava.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Character
23:22slashus2ouch
23:22Chouserhm, "close" should be "total"
23:26rlbI guess I can just switch to byte[]. I was trying to use nio because I had the impression that it was more efficient, but I can worry about that later.
23:27pilkarnhow do i calc n log n when n = 1000000
23:28pilkarnuser=> (* 1000 (Math/log 1000))
23:28pilkarn6907.755278982137
23:28pilkarnis that correct?
23:29Chouserrlb: is there a newline in your test file?
23:31Chouser,(import '(java.security MessageDigest) '(java.nio ByteBuffer))
23:31clojurebotnil
23:31Chouser,(let [d (MessageDigest/getInstance "md5"), v (ByteBuffer/allocateDirect 1)] (.put v 0 102) (.update d v) (apply str (map #(format "%x" %) (.digest d))))
23:31clojurebot"8fa14cdd754f91cc6554c9e71929cce7"
23:31gnuvince_pilkarn: assuming it's log and not lg, yes.
23:31rlbChouser: no, and I double checked with od.
23:32Chouser$ echo -n f | md5sum ==> 8fa14cdd754f91cc6554c9e71929cce7 -
23:33rlbChouser: hang on -- I think I may have gotten it.
23:33rlbI may have misunderstood a bit about messagedigest...
23:37rlbSo after each read/update, would it be correct to call .clear on the buf to reset it for the next read?
23:38ChouserI don't know, sorry.
23:39cooldude127please kill me, why is finding a path with a BFS so damn unnatural
23:39rlbNo problem -- I appreciate the help. Though I think perhaps I should stop soon. I'm overlooking obvious mistakes.
23:48pilkarnhow can I reimplement a method for a class?