#clojure logs

2008-09-26

07:20leafwis zipmap lazy?
07:33fyuryuleafw: after looking at the definition, I don't think so
07:33fyuryuleafw: it returns a map built in a loop/recur
07:34leafwthanks.
07:39leafw"No matching ctor found" means "you can't instantiate an abstract class". Could use some makeup ...
07:40leafwwell, actually, it's true that the abstract class didn;t have that constructor.
07:48ChouserYou also get that error if you provide wrong argument types to the constructor of a concrete class.
07:48Chouseras you might expect.
09:57drewrIs there a way to tell how much memory an object is using?
10:10fyuryudrewr: if you mean something like sizeof() in C: not really, almost everything is a reference
10:11drewrI didn't know if Object had some clues to where I could do some investigation.
10:12drewrI'd really like to find out how much memory a collection is using so I can determine the optimum number of rows to return in a db query.
10:15ozzileedrewr: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html Does that help?
10:16ozzileeI don't know if anything in there will do much good.
10:16drewrIt's not object-specific, but it's helpful. Thanks.
10:17ozzileeJust calling the freeMemory method from Clojure seems to allocate memory, so you'd have to account for that, and who knows what else.
10:17ozzileeProbably there's a better way.
11:08drewrIs there something wrong with conj'ing a map in a commute?
11:08drewrhash
11:08drewrEr..
11:08drewr(def pool (ref (sorted-map))) (dosync (commute pool conj {(:id @agt) agt}))
11:09drewrI get a ClassCastException: clojure.lang.PersistentHashMap because of the map after the conj.
11:09drewrAgent state looks like {:id 123, :conn jdbc.Connection...}.
11:11Chouserconj on map wants a vector I think
11:11drewrwm> (conj {} {:foo 1 :bar 2})
11:11drewr{:bar 2, :foo 1}
11:12drewrThis even works:
11:12drewrwm> (conj (sorted-map :quux 3) {:foo 1 :bar 2})
11:12drewr{:bar 2, :foo 1, :quux 3}
11:12drewrI can't figure out what's unique about my situation.
11:12Chouserhuh, I thought you needed "merge" for that. hm...
11:14ozzileedrewr: It looks like it's saying that pool is a PersistentHashMap, not a Ref.
11:15ozzileeAre you maybe doing (commute @pool ...) ?
11:15ChouserIf I do: (def agt (ref {:id 123, :conn "aconn"})) ...and then run your example, it works fine for me.
11:16Chouseror if I do (agent {...}) instead of (ref {...}), it also works.
11:16ozzileeThis is a prime example of where clojure needs better error messages :-)
11:17drewrozzilee: You aren't kidding. I can figure out that it's the conj that's complaining, but that's about it.
11:17Chouserthere's some difference remaining between your real code and what you've posted here, since what you've posted works fine.
11:18lisppaste8drewr pasted "commute ref" at http://paste.lisp.org/display/67484
11:19lisppaste8drewr annotated #67484 with "Actually, I'm using conj" at http://paste.lisp.org/display/67484#1
11:22drewrCall it like (add-agent *agent-pool* (make-agent conn)).
11:23lisppaste8drewr annotated #67484 with "better summary" at http://paste.lisp.org/display/67484#2
11:25drewrAm I off base here with the general idea?
11:25lisppaste8drewr annotated #67484 with "exception" at http://paste.lisp.org/display/67484#3
11:28Chouserwhat happens if you use a hash-map instead of a sorted-map?
11:30drewrHm, that works.
11:31Chouserthe clue is the PersistentTreeMap calling compare, and then failing
11:31drewrYep.
11:31Chouserall the keys in a sorted-map have to be comparable to each other.
11:32drewrIn this case they're integers, which should be straightforward.
11:32drewrThat's why I threw in a sorted-map. I might as well have them in order when I'm looking at it.
11:33Chouseryou can dump out the hash afterwards and see they's nothing unusual in there?
11:33drewrYep, here's from an earlier version:
11:33drewr{1 clojure.lang.Agent@bad094, 2 clojure.lang.Agent@d3cae0, 3 clojure.lang.Agent@ac5024, ... }
11:34drewrThat might have been before I used a sorted-map though.
12:47ozzileedrewr: java.lang.instrument.Instrumentation/getObjectSize
12:48ozzileeCan't get it to work here, though.
13:49aperotteHello everyone, I had a quick question about agents
13:51aperotteIf you have an agent with a collection in it, and you want to change an element of that collection, does the collection need to be a collection of refs and does the change have to happen in the context of a transaction?
13:53ozzileeaperotte: Hopefully someone more knowledgeable will chime in, but I don't believe so.
13:54aperotteok, thanks ozzilee. I have just started experimenting.
13:54ozzileehttp://clojure.org/state I think the second paragraph under "Concurrency" will explain things.
14:00avidaaperotte: collections are immutable, so you need to assign a new collection to it using send
14:01shooveraperotte: An agent's value can only be changed by sending an action to the agent. The action is passed the agent's current value as an argument, and then you can do whatever you want with that argument. Whatever the action returns becomes the agent's new value.
14:02shooverIf the value is a collection containing Refs and you want to change those Refs, you'll need a transaction around the Ref changes
14:03avidaaperotte: (def ag (agent '(1 2 3))) (send ag #(conj % 4)) @ag
14:03avidaaperotte: clojure that'll insert a 4 to the list (1 2 3) and assign it to the agent
14:03aperottefantastic
14:04aperottethat's exactly what I wanted to know
14:04aperotteoh, one more thing
14:04aperotteis it possible for two agents to share a collection?
14:05avidaaperotte: yes, since they are immutable anyone can share a collection without worrying aboutchanges
14:05avidawhen you send a change to an agent, you actually create a new collection (although efficiently shared behind-the-scenes)
14:05aperotteahh, but if I make "changes" to the collection in one agent
14:05aperotteit won't show up in the other
14:05avidaso two agents can share one collection, but when you make changes to one agent, you actually end up with two different collections
14:05aperotteI see
14:06aperotteThen, if I have two agents sharing a collection of refs, and change the refs within a transaction, will the changes show up in both?
14:08avidai think the refs stay the same, only the values they refer to have changed, so if your collection is of refs, then the collections wont change, however you can reference the changed values of the refs
14:08aperotteok, I think I'm going to try it out
14:09aperottethanks avida, thanks shoover, thanks ozzilee
14:29aperotteIt worked ... albeit a bit of a round about way of getting at what I wanted
14:29aperotte(def x [(ref 1) (ref 2) (ref 3)])
14:29aperotte(def a1 (agent x))
14:29aperotte(def a2 (agent x))
14:29aperotte@(get @a1 1)
14:29aperotte(dosync (ref-set (get @a1 1) 10))
14:29aperotte@(get @a1 1)
14:29aperotte@(get @a2 1)
14:31avidayep, you never changed the values of a1, a2 so you would always see the same refs
14:32aperotteThe aim is to have the agents operate on themselves in this way asynchronously and independently
14:33aperotteI'm not sure that this is correct, but this might be exactly the kind of thing clojure was made to avoid
14:36avidaaperotte: ops on the agents are async but you're updatings refs which are synchrnous
14:37aperotteif I used send to tell an agent to (dosync (ref-set ... , that would make it asynchronous right?
14:37avidayou could read from the refs, and change the refs themselves in the collection async
14:38aperottehow could I read and change the refs async without using agents?
14:39avidai think what you are doing is good, im not thinking this through all the way
14:53shooverupdating refs in an agent action is asynchronous as far as the rest of the program is concerned. from the perspective of the action, its own changes to the refs are synchronous
14:56shooversorry. aperotte: if you tell an agent to (dosync (refset ..)), then yes, that makes an asynchronous change to the ref
14:57shooverbut within the action that executes the ref-set, you'll see the new value right away
14:58akingLooks like Rich's slides from the jvm summit are up: http://wiki.jvmlangsummit.com/pdf/27_Hickey_clojure.pdf
14:59lisppaste8shoover pasted "Agent sees new value" at http://paste.lisp.org/display/67493
15:02aperottethanks guys
15:02shooverThat paste doesn't prove the async part of the above statements, but we'd need a real problem to solve for that
15:07aperotteThe motivation behind this is to write a machine learning prototyping system where each element/layer contains and can operate async on an input vector to create an output vector that is shared with another element/layer as it's input layer (a connection)
15:08aperottethe last "layer" should be "vector"
15:10aperotteI wanted to make the elements operate async by using agents, but then the shared data that represents the connections between the elements becomes problematic
15:10ozzileeaperotte: Is this something like Cells? http://common-lisp.net/project/cells/
15:12shooverYou should be able to get what you want by sharing refs. If you don't like that you may want to check out the agent watchers that were added recently in svn
15:14joubertrhickey: I started looking at the lib functionality that is now part of clojure proper. Will (in-ns) be deprecated since (ns) appears to supersede it?
15:14aperotteok, thanks
15:15aperotteozzilee: I hadn't used cells before, but it sounds like something very similar
15:27Chouserjoubert: no, in-ns is still recommended if you want to switch to a namespace without changing it at all.
15:28joubertchouser: ok, why the different usage of symbol vs. non-symbol?
15:28joubert(also, in-ns creates a namespace if it doesn't already exist)
15:29joubert(which seems to me to "change" a namespace :-)
15:29Chouserin-ns is from a kind of "lower layer" which also has things like use, require, import, etc -- all of which are functions instead of macros
15:30Chousereach of those will continue to exist, I think, but if you can use (ns) instead that's preferred.
15:30Chouserwell, yeah, I guess in-ns does create the ns, but it doesn't muck about with the imports, referred symbols, etc.
15:32joubertok, so when "declaring" a namespace, (ns) is now preferred over (in-ns), with the latter really more geared towards (switch-ns)
15:32ozzileeaperotte: There was some discussion about Cells on the mailing list (sorry, was afk): http://groups.google.com/group/clojure/browse_thread/thread/d79392e4c79f8cde#
15:32Chouserright, you've got it.
15:33drewrIs there a Java standard for JDBC -> XML serialization?
15:34drewrLike, taking a resultset and saving the text to a file?
15:35joubertcool; do you think it worthwhile to normalize the way namespace names are passed to these 2 forms? either always as symbol or as non-symbol?
15:35aperotteozzilee: thanks, this might be exactly what I'm looking for
15:36Chouserjoubert: probably not. I like that (ns) uses unquoted symbols -- uncluttered. But that means it has to be a macro, which can be clumsier to use programmatically if you're doing something really unusual.
15:37Chouserjoubert: but (ns) is just a wrapper around the underlying functions, which must have their args quoted since they are functions.
15:43drewrI keep getting java.lang.IncompatibleClassChangeErrors, but Clojure doesn't tell me what classes were involved in the exception.
15:45ChouserHuh, when I try to put the wrong type of key into a sorted hash, I get: java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to java.lang.Integer
15:45drewrChouser: Sorry, different problem :-)
15:46drewrI knew how to fix this one; just frustrated at the error message.
15:46Chouseroh, IncompatibleClassChangeErrors is not ClassCastException. I misread that, sorry.
15:56drewrNo complaints here. :-0
15:56drewr:-)
18:37achim_phey. i began playing around with that jar-classpath-dependency-download-thing i talked about recently. here it is, for those interested: http://www.bitbucket.org/achimpassen/clojure-ties/
18:38achim_pit's very much unfinished and untested, but i ran it successfully at least once. this was when i decided it needed a logo ;) raises the bar for absurd lambda iconography considerably.
18:39achim_pany opinions on the approach in general? how do you deal with dependencies? i feel the existing java frameworks are way to bulky for what i want to do ...
18:40Chouserthat's a fantastic logo
18:50hsynhi there
18:54Chouserhsyn: hi
18:56hsyni am very new clojure and also to lisp so i have allready problems with the getting start tutotial for java programmers as described in the clojure wiki.
18:56hsynif i try to load the script with
18:56hsyn RT.loadResourceScript ( "C:/app/foo.clj" ) ;
18:56hsyni get a resouce not found exception.
18:56hsyni realized that this method only takes the name part of the given path. How can i load the script form a path which is not in the classpath?
19:03Chouserhsyn: are you sure you need to load clojure from within your own java app? It's a bit easier to run from the command line.
19:04hsyni going to use the result in java.
19:04hsynin future
19:05achim_phsyn: you could extend your classpath with RT.addURL
19:06achim_pdidn't try it though ...
19:07hsynthx achim it work
19:07Chouseryou could also use clojure.lang.Compiler.load(rdr, sourcePath, sourceName)
19:07Chouseroh, good, nm then. :-)
19:19pjb3So I take it Clojure's instance? method doesn't map to Java's instanceof operator?
19:19pjb3(instance? java.util.Map {}) => false
19:23rhickeyClojure maps are not java,util.Maps
19:44pjb3Clojure maps are not java.util.Maps? Hmm...that's a bummer when trying to work with Java APIs that expect maps
19:45pjb3I assume there's a good reason why clojure maps aren't java.util.Maps?
19:46ChouserClojure maps are persistent (immutable)
19:46ChouserYou can still work with java.util.Maps pretty easily if you're sure you want them.
19:48pjb3I want to pass a clojure map to a Java API that expects a java.util.Map
19:56shooverthere was some discussion mentioning it as a possibility, but it seemed to get bogged down on incompatibilities between Collection and Map: http://clojure-log.n01se.net/date/2008-07-18.html
19:57Chouser(reduce (fn [m [k v]] (.put m k v) m) (java.util.HashMap.) {:a 1 :b 2})
20:00pjb3I'm trying to see if I can use clojure with velocity
20:00pjb3Chouser: that function helps
20:00pjb3but then the next problem is that what about maps that contain maps
20:01pjb3Since clojure maps don't even have a get method, they wouldn't work in a velocity context
20:04Chouser(defn jum [cm] (reduce (fn [m [k v]] (.put m k (if (map? v) (jum v) v)) m) (java.util.HashMap.) cm))
20:04Chouser(jum {:a 1 :b {:c 3 :d 4 :e {:f 5}}})
20:06pjb3Chouser: nice, I guess I'll try that for now
20:08pjb3But I agree with meredydd from that earlier discussion, I think it would be really nice to not have to do a deep copy everytime you want to have a java library use a clojure map
20:26hsynis there any ATN parser available
23:13Chouserrhickey: I saw your "agents/refs in use" slides. Very nice.
23:14ChouserWhat kind of responses have you gotten to your talk?
23:14rhickeyreally great. I just got to the airport - an amazing conference
23:14rhickeyso many interesting people
23:15Chouser:-)
23:15rhickeyClojure was very well received
23:16blackdogcongrats rhickey
23:16Chousergreat! anybody promise you tagged numbers? ;-)
23:16rhickeyno, but they and tail calls were the most requested changes
23:17rhickeysome hope in escape analysis for local optimization of boxed numbers in the JITs
23:17rhickeyCliff Click ran the ACO TSP code on 600 cores - scaled well
23:18Chouserthat's pretty cool
23:22rhickeyhe had some amazing perf tools for his boxes - so much fun to see Clojure pop the bar meters on 600 cores
23:25blackdogi didn't realise the jvm scaled like that, never mind clojure
23:25blackdogv. impressive
23:26rhickeythose boxes are amazig - the sim was allocating 18GB a second, GC wasn't sweating
23:26rhickeyamazing
23:26blackdogcrikey, all in makes one feel the jvm is a good choice :)
23:27blackdogdoes the .net vm scale like that?
23:27rhickeyI don't know if there are boxes like that for .Net
23:28rhickeythese things are like 200 cores in 5U
23:28rhickey1/2 TB RAM
23:29blackdogso this is really a milestone for clojure getting that coverage
23:29avidarhickey: are these the Azul boxes? my company trialled something like that
23:30rhickeylots of people there had only barely heard of Clojure, now they know what it's about
23:30rhickeyavida: yes, Azul
23:31blackdogcongrats again, you must be feeling over the moon after the hard work, and innovation!
23:31rhickeyI'm totally spent - 3 days of intense conversations
23:33blackdogi mean really all the years on clojure and then taking it to a conference like that and getting the recognition etc
23:33blackdogtis very cool
23:33rhickeyblackdog: yes, thanks
23:34rhickeynow I have to gear up for Monday at MIT - very sophisticated Lisp group
23:34blackdoghehe
23:35rhickeyplus maybe some Sun STM folks I hear
23:35blackdogdo you know when infoq will publish the videos?
23:35blackdogof the conf
23:35rhickeyblackdog: no idea
23:36rhickeyI had only 1/2 hour - I talked as fast as I could
23:36blackdogdid you come away with any inspiration, ideas?
23:37rhickeyIt will take a while to filter through, but overall I felt good about where Clojure is at. Some perf ideas, some more research topics to pursue
23:37blackdogwell obviously, but any new implementation stuff :P
23:38blackdognice
23:38blackdogprobably more folks took away from what you've already achieved i bet
23:39rhickeythere was a lot of talk about functional programming
23:39blackdogesp after your successful 600 core test :)
23:46blackdogwell on a more modest scale (1 core), my brother is selling 3d training videos which has a simple clojure backend producing json, so it's my first production use of clojure
23:51yangsxjava -cp clojure.jar clojure.lang.Compiler src/clj/clojure/boot.clj won't work, is that expected?
23:51yangsxI'm using svn version
23:53yangsxOr how can I compile a Clojure program into Java classes?
23:55blackdogyangsx, you can't do that yet, rhickey is investigating aot compilation to java though
23:57yangsxblackdog: OK, I got that from clojure.markdown in the svn repo.