Re: how goes ClojureCheck?
Hi, On Dec 2, 2:48 am, Raoul Duke rao...@gmail.com wrote: ah. i guess i'm supposed to use clojure.test and clojure.test.tap, i see. This is probably the right thing to do. I plan to work on ClojureCheck again soon. But at the moment I don't have enough spare time. I hope to find some time over christmas. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: HOWTO: Compojure Development without Web Server Restarts using VimClojure
Hi, Cool. Thank you for your report! Just some notes. On Dec 2, 3:10 am, Gilbert gilbert.kf.le...@gmail.com wrote: - vimclojure offers a number of features, but the documentation is hidden in a text file inside ~/.vim/doc/clojure.txt (you can also read it here: http://bitbucket.org/kotarak/vimclojure/src/tip/doc/clojure.txt) It is not hidden there. This is the official place for plugin documentation in vim. (see also :helptags) - you need to put your source files in the classpath when running the nailgun server; if you use lein, you can install lein-nailgun as a dev- dependency and call lein nailgun to run the nailgun server 2. Fire up vim; open up the files you want to edit. 3. Type \sr to open a REPL. 4. Call (run-server ) in the REPL to start your server. 5. Edit some of the source files on which your server runs. When you're done, type \ef, which evaluates the entire file in the REPL. 6. Refresh your browser. Voila! Please note that this can break your system. Say you have a multimethod which is extended in one or more other namespaces. When you change something in the namespace containing the defmulti and reload it via \ef the other namespaces containing the defmethod will stop working, because their defmethod extension is lost. There is currently no other way in Clojure than to reload all these namespaces manually. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: simple journal-based persistenсe for Clojure
It creates journals in readable and executable form: 1.journal (tr-fn 1 2) ;1 (tr-fn 10 20) ;2 (tr-fn-swap) ;3 (tr-inc) ;4 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Handling XML
Howdy, Being new to clojure, I am having a difficult time parsing XML in an elegant manner. I am pulling metric information from a ganglia server as XML and then parsing it. The below function works but it makes me feel icky. I was hoping for some tips. The dc variable contains a map with some data center information (not really interesting), and the stream variable comes from http.agent. (defn handle-xml [dc stream] (let [xml-out (xml-seq (parse (http/stream stream)))] (doseq [x xml-out] (doseq [y (:content x)] (doseq [z (:content y)] (doseq [a (:content z)] (println (:dc dc) (:NAME (:attrs z)) (:NAME (:attrs a)) (:VAL (:attrs a)) (:TN (:attrs a) The XML is of the form: ganglia multiple clusters multiple hosts multiple metrics Example of the XML: GANGLIA_XML VERSION=3.0.7 SOURCE=gmond CLUSTER NAME=cluster.example.com LOCALTIME=1258396022 OWNER=unspecified LATLONG=unspecified URL=unspecified HOST NAME=server.example.com IP=127.0.0.1 REPORTED=1258396019 TN=3 TMAX=20 DMAX=86400 LOCATION=unspe cified GMOND_STARTED=1255757736 METRIC NAME=disk_total VAL=1320.124 TYPE=double UNITS=GB TN=6684 TMAX=1200 DMAX=0 SLOPE=both SOURCE=gmond/ METRIC NAME=cpu_speed VAL=2493 TYPE=uint32 UNITS=MHz TN=682 TMAX=1200 DMAX=0 SLOPE=zero SOURCE=gmond/ ... Thanks, Dennis -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Datatypes and protocols - update
On Dec 2, 12:29 am, Krukow karl.kru...@gmail.com wrote: On Dec 1, 10:56 pm, Rich Hickey richhic...@gmail.com wrote: [snip] There are 2 ways to make a deftype reach a protocol. First, you can implement the protocol directly in the deftype/reify, supplying the protocol where you do interfaces, and the methods of the protocol as methods of the type. The type will be made to implement the protocol's interface. OK. With extend you can use maps and merge to share implementations. Does directly implementing the protocol in deftype allow also for abstract super-classes, i.e., sharing protocol-function implementations across types? Right now you would just call an implementation helper inside your method. I'm still considering if more support is needed, and what form it might take. Different methods of implementing the protocol have different performance. Implementing directly in deftype or reify is as fast as a direct interface call. Using extend-* is not quite as fast, but still fast. Both methods have direct support in callsites, so a call to a protocol fn has support both for using the interface and caching lookup results. Great. So the preferred way for data-types in my program is to implement the protocol directly, whereas for other types I can still use my protocol with extend. Just to confirm my understanding: Is it correct to say, for example, that clojure.lang.Seqable will be a protocol implemented directly in the Clojure data types, whereas it would reach the Java lang types using extend? Yes. extend is the key to removing the current (closed) multiway conditionals in, e.g., RT.seq/seqFrom, and is much faster as well. In Clojure-in-Java interfaces like IPersistentCollection extend Seqable: would these be unrelated type-wise as protocols? Yes. One of the reasons we use interface inheritance in a language like Java is that, short of generifying everything, we have no way to say: foo(Counted+Sorted+Seqable+Collection coll){...} We only get to specify one type, and any other interfaces it doesn't imply require casts. So we use hierarchy to reduce the required casting, but it has a cost in flexibility - i.e. you can't make a non- Seqable collection, if that made sense. In a dynamic language with protocols there is no reason to do it this way. You don't need to have a single type imply multiple types via hierarchy, and you don't need to declare anything. So each protocol is a la carte, and a piece of code that requires the collection support Counted, Sorted, Seqable and Collection protocols will simply use those protocols, and work with anything that supports them. A type can support any and just the protocols that make sense for it, without bringing in others as a side effect of hierarchy. Protocols are very much about polymorphism without hierarchy. Rich -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: What about contains? for lists
On Wed, Dec 2, 2009 at 10:10 AM, Stefan Kamphausen ska2...@googlemail.comwrote: OK, the doc of contains? told me that for indexed collection-types it will only check, whether the index is within the valid range. So maybe: user (contains? (list 1 2 3) 1) false At that point I dived into the implementation and found that in RT.java checks for the type of collection passed but leaves out PersistenList. I'd like to understand the (probably well-grounded) reason for that. As far as I can see PersistentList extends Counted, so the check for the index-range should at least be possible. However, I think people would expect an equality check in the background, which OTOH would be O (N), probably. It was my impression that in Clojure, lists aren't numerically indexed collections. That might explain the following: user= (contains? '(1 2 3) 1) false user= ('(1 2 3) 1) java.lang.ClassCastException: clojure.lang.PersistentList (NO_SOURCE_FILE:0) even though: user= (contains? [1 2 3] 1) true user= ([1 2 3] 1) 2 But I might be mistaken, so take this as speculation rather than explanation. e -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Eleven Theses on Clojure
Tim Bray starts with the delightfull forthright Clojure is the best Lisp ever! and then goes on to explain why the JVM's current lack of hard tail calls don't matter. http://www.tbray.org/ongoing/When/200x/2009/12/01/Clojure-Theses Interesting, and certainly confirms my own prejudices about Clojure as a language. (via http://lambda-the-ultimate.org/node/3700) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
inverse of interleave = unravel
Recently I need something which works as inverse of interleave I did something like that: (defn unravel [expr-list] (loop [flist () slist () tic-tac 0 olist expr-list] (let [item (first olist)] (if (= item nil) (list flist slist) (if (= tic-tac 0) (recur (concat flist (list item)) slist 1 (rest olist)) (recur flist (concat slist (list item)) 0 (rest olist))) Test: (def dl (interleave (iterate inc 1) [A B C D E])) (unravel dl) And the classic question is it possible to do it simple, more in a functional manner, without explicit looping? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Handling XML
On Wed, Dec 2, 2009 at 11:29 AM, Dennis shr3ks...@gmail.com wrote: Sean, I probably did not make it clear, but I am using parse. The second line of handle-xml function in my original E-Mail has the parse in it. I then iterate over the xml-seq. Are you familiar with 'zippers'? There is a zipper for xml-seqs in contrib: http://richhickey.github.com/clojure-contrib/zip-filter-api.html This might afford you a better way to navigate your XML documents. I don't know of any how-to docs on xml zippers, but a quick google found this blog article: http://netzhansa.blogspot.com/2008/10/trying-clojure.html Best, Graham I am also using: (ns zod (:require [clojure.contrib.http.agent :as http]) (:import (java.util Timer TimerTask)) (:use [clojure.xml :only (parse)])) -- Dennis On Wed, Dec 2, 2009 at 10:23 AM, Sean Devlin francoisdev...@gmail.com wrote: Try the clojure.xml namespace. There's a funciton parse in there that should help. On Dec 2, 10:51 am, Dennis shr3ks...@gmail.com wrote: Howdy, Being new to clojure, I am having a difficult time parsing XML in an elegant manner. I am pulling metric information from a ganglia server as XML and then parsing it. The below function works but it makes me feel icky. I was hoping for some tips. The dc variable contains a map with some data center information (not really interesting), and the stream variable comes from http.agent. (defn handle-xml [dc stream] (let [xml-out (xml-seq (parse (http/stream stream)))] (doseq [x xml-out] (doseq [y (:content x)] (doseq [z (:content y)] (doseq [a (:content z)] (println (:dc dc) (:NAME (:attrs z)) (:NAME (:attrs a)) (:VAL (:attrs a)) (:TN (:attrs a) The XML is of the form: ganglia multiple clusters multiple hosts multiple metrics Example of the XML: GANGLIA_XML VERSION=3.0.7 SOURCE=gmond CLUSTER NAME=cluster.example.com LOCALTIME=1258396022 OWNER=unspecified LATLONG=unspecified URL=unspecified HOST NAME=server.example.com IP=127.0.0.1 REPORTED=1258396019 TN=3 TMAX=20 DMAX=86400 LOCATION=unspe cified GMOND_STARTED=1255757736 METRIC NAME=disk_total VAL=1320.124 TYPE=double UNITS=GB TN=6684 TMAX=1200 DMAX=0 SLOPE=both SOURCE=gmond/ METRIC NAME=cpu_speed VAL=2493 TYPE=uint32 UNITS=MHz TN=682 TMAX=1200 DMAX=0 SLOPE=zero SOURCE=gmond/ ... Thanks, Dennis -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: inverse of interleave = unravel
the only solution comes to mind is a two pass partition. ie (flatten (partition 1 2 dl)) for the first list and (flatten (partition 1 2 (rest dl))) for the 2nd list. 2009/12/2 Konrad Kułakowski (kony) kulakow...@gmail.com: Recently I need something which works as inverse of interleave I did something like that: (defn unravel [expr-list] (loop [flist () slist () tic-tac 0 olist expr-list] (let [item (first olist)] (if (= item nil) (list flist slist) (if (= tic-tac 0) (recur (concat flist (list item)) slist 1 (rest olist)) (recur flist (concat slist (list item)) 0 (rest olist))) Test: (def dl (interleave (iterate inc 1) [A B C D E])) (unravel dl) And the classic question is it possible to do it simple, more in a functional manner, without explicit looping? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Omnem crede diem tibi diluxisse supremum. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Datatypes and protocols - update
Thanks for sharing the insights. /Karl -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Handling XML
On Dec 2, 4:51 pm, Dennis shr3ks...@gmail.com wrote: The XML is of the form: ganglia multiple clusters multiple hosts multiple metrics Use XPath. Seriously, I hate XML and XSLT, but XPath is simply the most concise way to extract things from a nested structure. Most XPath- libraries allow for precompilation of XPath-expressions (similar to RegEx-precompilation) and don't require the whole XML-file to reside in memory, which makes this a nice solution for huge XML-files (though in your case this is probably no issue). To get a list of all metrics in all hosts in all clusters, you'd simply use the XPath-expression ganglia/cluster/host/metric against an XML-document; recursive fetching (if clusters could contain other clusters) could be done by using a double slash instead of a single slash. A Clojure-solution for a similar expression language would be clojure.contrib.zip-filter.xml, though I did not use it, but you might try it out. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Handling XML
Hi! Taking minor liberties with your code (for clarity), the following gives pretty much the same result as your handle-xml function: (ns blah (:require [clojure.xml :as xml] [clojure.zip :as zip]) (:use clojure.contrib.zip-filter.xml)) (defn my-test [] (doseq [x (xml- (zip/xml-zip (xml/parse /my-path-to/GANGLIA.xml)) :CLUSTER :HOST :METRIC (fn [loc] [[(xml1- (zip/up loc) (attr :NAME)) (xml1- loc (attr :NAME)) (xml1- loc (attr :VAL)) (xml1- loc (attr :TN))]]))] (apply println x))) The call to zip/xml-zip creates a zipper object, a simple trick to travel around xml. Each argument to xml- (after the first) drills down the tree. The last argument, once I've drilled down to the :METRIC node, collects the attributes you're interested in. The sourcecode has handy examples to play along with. For your reference: http://github.com/richhickey/clojure-contrib/blob/81b9e71effbaf6aa2945cd684802d87c762cdcdd/src/clojure/contrib/zip_filter/xml.clj#L94 Note: If you print the zipper object, its representation will be pretty, pretty big. If that's a problem, remember to call zip/node at the end, as per the examples. Or do the crazy thing I do, which is to customize print-method (specifying each zipper object's :type metadata), so it'll have a tiny representation like: #ganglia gmond Hope that makes sense, Tayssir On Dec 2, 4:51 pm, Dennis shr3ks...@gmail.com wrote: Howdy, Being new to clojure, I am having a difficult time parsing XML in an elegant manner. I am pulling metric information from a ganglia server as XML and then parsing it. The below function works but it makes me feel icky. I was hoping for some tips. The dc variable contains a map with some data center information (not really interesting), and the stream variable comes from http.agent. (defn handle-xml [dc stream] (let [xml-out (xml-seq (parse (http/stream stream)))] (doseq [x xml-out] (doseq [y (:content x)] (doseq [z (:content y)] (doseq [a (:content z)] (println (:dc dc) (:NAME (:attrs z)) (:NAME (:attrs a)) (:VAL (:attrs a)) (:TN (:attrs a) The XML is of the form: ganglia multiple clusters multiple hosts multiple metrics Example of the XML: GANGLIA_XML VERSION=3.0.7 SOURCE=gmond CLUSTER NAME=cluster.example.com LOCALTIME=1258396022 OWNER=unspecified LATLONG=unspecified URL=unspecified HOST NAME=server.example.com IP=127.0.0.1 REPORTED=1258396019 TN=3 TMAX=20 DMAX=86400 LOCATION=unspe cified GMOND_STARTED=1255757736 METRIC NAME=disk_total VAL=1320.124 TYPE=double UNITS=GB TN=6684 TMAX=1200 DMAX=0 SLOPE=both SOURCE=gmond/ METRIC NAME=cpu_speed VAL=2493 TYPE=uint32 UNITS=MHz TN=682 TMAX=1200 DMAX=0 SLOPE=zero SOURCE=gmond/ ... Thanks, Dennis -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Handling XML
BTW, I should point out that zip-filter.xml/xml- is surprisingly syntaxy. (xml- loc :CLUSTER :HOST :METRIC (fn [loc] [[(xml1- (zip/up loc) (attr :NAME)) (xml1- loc (attr :NAME)) (xml1- loc (attr :VAL)) (xml1- loc (attr :TN))]])) In the above, I pass keywords, a function and calls to attr() to the xml- (and xml1-) functions. The keywords (like :CLUSTER, :HOST and :METRIC) expand into things like (tag= :CLUSTER) which return functions that operate on zipper objects. So if you're a bit overwhelmed by all the stuff that xml- accepts, just note that much of it is syntactic sugar, for your convenience. Tayssir On Dec 2, 7:41 pm, Tayssir John Gabbour tayssir.j...@googlemail.com wrote: Hi! Taking minor liberties with your code (for clarity), the following gives pretty much the same result as your handle-xml function: (ns blah (:require [clojure.xml :as xml] [clojure.zip :as zip]) (:use clojure.contrib.zip-filter.xml)) (defn my-test [] (doseq [x (xml- (zip/xml-zip (xml/parse /my-path-to/GANGLIA.xml)) :CLUSTER :HOST :METRIC (fn [loc] [[(xml1- (zip/up loc) (attr :NAME)) (xml1- loc (attr :NAME)) (xml1- loc (attr :VAL)) (xml1- loc (attr :TN))]]))] (apply println x))) The call to zip/xml-zip creates a zipper object, a simple trick to travel around xml. Each argument to xml- (after the first) drills down the tree. The last argument, once I've drilled down to the :METRIC node, collects the attributes you're interested in. The sourcecode has handy examples to play along with. For your reference:http://github.com/richhickey/clojure-contrib/blob/81b9e71effbaf6aa294... Note: If you print the zipper object, its representation will be pretty, pretty big. If that's a problem, remember to call zip/node at the end, as per the examples. Or do the crazy thing I do, which is to customize print-method (specifying each zipper object's :type metadata), so it'll have a tiny representation like: #ganglia gmond Hope that makes sense, Tayssir On Dec 2, 4:51 pm, Dennis shr3ks...@gmail.com wrote: Howdy, Being new to clojure, I am having a difficult time parsing XML in an elegant manner. I am pulling metric information from a ganglia server as XML and then parsing it. The below function works but it makes me feel icky. I was hoping for some tips. The dc variable contains a map with some data center information (not really interesting), and the stream variable comes from http.agent. (defn handle-xml [dc stream] (let [xml-out (xml-seq (parse (http/stream stream)))] (doseq [x xml-out] (doseq [y (:content x)] (doseq [z (:content y)] (doseq [a (:content z)] (println (:dc dc) (:NAME (:attrs z)) (:NAME (:attrs a)) (:VAL (:attrs a)) (:TN (:attrs a) The XML is of the form: ganglia multiple clusters multiple hosts multiple metrics Example of the XML: GANGLIA_XML VERSION=3.0.7 SOURCE=gmond CLUSTER NAME=cluster.example.com LOCALTIME=1258396022 OWNER=unspecified LATLONG=unspecified URL=unspecified HOST NAME=server.example.com IP=127.0.0.1 REPORTED=1258396019 TN=3 TMAX=20 DMAX=86400 LOCATION=unspe cified GMOND_STARTED=1255757736 METRIC NAME=disk_total VAL=1320.124 TYPE=double UNITS=GB TN=6684 TMAX=1200 DMAX=0 SLOPE=both SOURCE=gmond/ METRIC NAME=cpu_speed VAL=2493 TYPE=uint32 UNITS=MHz TN=682 TMAX=1200 DMAX=0 SLOPE=zero SOURCE=gmond/ ... Thanks, Dennis -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: inverse of interleave = unravel
On Dec 2, 9:10 am, Konrad Kułakowski (kony) kulakow...@gmail.com wrote: Recently I need something which works as inverse of interleave I did something like that: (defn unravel [expr-list] (loop [flist () slist () tic-tac 0 olist expr-list] (let [item (first olist)] (if (= item nil) (list flist slist) (if (= tic-tac 0) (recur (concat flist (list item)) slist 1 (rest olist)) (recur flist (concat slist (list item)) 0 (rest olist))) Test: (def dl (interleave (iterate inc 1) [A B C D E])) (unravel dl) And the classic question is it possible to do it simple, more in a functional manner, without explicit looping? How about this? (defn skip [coll n] (lazy-seq (when-let [s (seq coll)] (cons (first s) (skip (drop n (next s)) n) (defn unravel [coll n] (for [i (range n)] (skip (drop i coll) (dec n -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Handling XML
Thanks, I think I have the idea. (ns ziptest (:require [clojure.zip :as zip] [clojure.xml :as xml] [clojure.contrib.zip-filter :as zf]) (:use clojure.contrib.zip-filter.xml) (:import (java.io ByteArrayInputStream))) (def *xml-string* a1b1c1a1b1c1/c1c2a1b1c2/c2/b1b2c1a1b2c1/c1/b2/a1) (defn string-to-zip [s] (zip/xml-zip (xml/parse (ByteArrayInputStream. (.getBytes s) (defn parse-xml [string] (doseq [x (xml- (string-to-zip string) zf/descendants :c1)] (println --- (:content (first x) (parse-xml *xml-string*) [dr...@drowe][h:10013][J:0] ./clojure src/ziptest.clj --- [a1b1c1] --- [a1b2c1] On Wed, Dec 2, 2009 at 11:38 AM, pmf phil.fr...@gmx.de wrote: On Dec 2, 4:51 pm, Dennis shr3ks...@gmail.com wrote: The XML is of the form: ganglia multiple clusters multiple hosts multiple metrics Use XPath. Seriously, I hate XML and XSLT, but XPath is simply the most concise way to extract things from a nested structure. Most XPath- libraries allow for precompilation of XPath-expressions (similar to RegEx-precompilation) and don't require the whole XML-file to reside in memory, which makes this a nice solution for huge XML-files (though in your case this is probably no issue). To get a list of all metrics in all hosts in all clusters, you'd simply use the XPath-expression ganglia/cluster/host/metric against an XML-document; recursive fetching (if clusters could contain other clusters) could be done by using a double slash instead of a single slash. A Clojure-solution for a similar expression language would be clojure.contrib.zip-filter.xml, though I did not use it, but you might try it out. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Space usage of lazy seqs
I don't understand Clojure's space requirements when processing lazy sequences. Are there some rules-of-thumb that I could use to better predict what will use a lot of space? I have a 5.5 GB pipe-delimited data file, containing mostly floats (14 M rows of 40 cols). I'd like to stream over that file, processing columns as I go, without holding the whole thing in RAM. As a first test, I'm trying to just split each row and count the total number of fields. Why does reduce seem to load in the whole file, yet test-split-4 not? Why does the if-let in test-split-3 vs test-split-3b make such a difference? And finally, is there any way I can parallelize this to use multiple cores without slurping in the whole file? If it matters, I'm using a snapshot of 1.1.0-alpha; the jar included with incanter. Here's the code: (defn afile /path/to/big/file) ;; Count the lines in the file. ;; 12.8 s, light memory use (0.8 GB). (defn test-count [] (with-open [rdr (duck-streams/reader afile)] (count (line-seq rdr ;; Split and count. ;; 183.2 s, heavy memory use (8.6 GB). (defn test-split [] (with-open [rdr (duck-streams/reader afile)] (reduce + (map #(count (.split %1 \\|)) (line-seq rdr) ;; 190.8 s, heavy memory use (8.8 GB). (defn test-split-2 [] (with-open [rdr (duck-streams/reader afile)] (loop [counts (seq (map #(count (.split %1 \\|)) (line-seq rdr))) cnt 0] (if counts (recur (next counts) (+ cnt (first counts))) cnt ;; Use rest instead, if-let (following http://clojure.org/lazy.) ;; 166.1 s, light memory use (1.4 GB) (defn test-split-3 [] (with-open [rdr (duck-streams/reader afile)] (loop [counts (map #(count (.split %1 \\|)) (line-seq rdr)) cnt 0] (if-let [s (seq counts)] (recur (rest s) (+ cnt (first s))) cnt ;; Try without the if-let. ;; 211.6 s, heavy memory use (8.7 GB). Surprise! (defn test-split-3b [] (with-open [rdr (duck-streams/reader afile)] (loop [counts (map #(count (.split %1 \\|)) (line-seq rdr)) cnt 0] (if (seq counts) (recur (rest counts) (+ cnt (first counts))) cnt ;; 160 s, light memory use. (1.5 GB) (defn test-split-4 [] (with-open [rdr (duck-streams/reader afile)] (loop [lines (line-seq rdr) cnt 0] (if lines (recur (next lines) (+ cnt (count (.split (first lines) \\| cnt ;; Parallel split and count. ;; Based on test-split-3, but using pmap. ;; 95.1 s, heavy memory use (8.7 GB) (defn test-psplit-1 [] (with-open [rdr (duck-streams/reader afile)] (loop [counts (pmap #(count (.split %1 \\|)) (line-seq rdr)) cnt 0] (if-let [s (seq counts)] (recur (rest s) (+ cnt (first s))) cnt -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Handling XML
Thanks a bunch, this has been very helpful. -- Dennis On Wed, Dec 2, 2009 at 1:03 PM, Tayssir John Gabbour tayssir.j...@googlemail.com wrote: BTW, I should point out that zip-filter.xml/xml- is surprisingly syntaxy. (xml- loc :CLUSTER :HOST :METRIC (fn [loc] [[(xml1- (zip/up loc) (attr :NAME)) (xml1- loc (attr :NAME)) (xml1- loc (attr :VAL)) (xml1- loc (attr :TN))]])) In the above, I pass keywords, a function and calls to attr() to the xml- (and xml1-) functions. The keywords (like :CLUSTER, :HOST and :METRIC) expand into things like (tag= :CLUSTER) which return functions that operate on zipper objects. So if you're a bit overwhelmed by all the stuff that xml- accepts, just note that much of it is syntactic sugar, for your convenience. Tayssir On Dec 2, 7:41 pm, Tayssir John Gabbour tayssir.j...@googlemail.com wrote: Hi! Taking minor liberties with your code (for clarity), the following gives pretty much the same result as your handle-xml function: (ns blah (:require [clojure.xml :as xml] [clojure.zip :as zip]) (:use clojure.contrib.zip-filter.xml)) (defn my-test [] (doseq [x (xml- (zip/xml-zip (xml/parse /my-path-to/GANGLIA.xml)) :CLUSTER :HOST :METRIC (fn [loc] [[(xml1- (zip/up loc) (attr :NAME)) (xml1- loc (attr :NAME)) (xml1- loc (attr :VAL)) (xml1- loc (attr :TN))]]))] (apply println x))) The call to zip/xml-zip creates a zipper object, a simple trick to travel around xml. Each argument to xml- (after the first) drills down the tree. The last argument, once I've drilled down to the :METRIC node, collects the attributes you're interested in. The sourcecode has handy examples to play along with. For your reference: http://github.com/richhickey/clojure-contrib/blob/81b9e71effbaf6aa294... Note: If you print the zipper object, its representation will be pretty, pretty big. If that's a problem, remember to call zip/node at the end, as per the examples. Or do the crazy thing I do, which is to customize print-method (specifying each zipper object's :type metadata), so it'll have a tiny representation like: #ganglia gmond Hope that makes sense, Tayssir On Dec 2, 4:51 pm, Dennis shr3ks...@gmail.com wrote: Howdy, Being new to clojure, I am having a difficult time parsing XML in an elegant manner. I am pulling metric information from a ganglia server as XML and then parsing it. The below function works but it makes me feel icky. I was hoping for some tips. The dc variable contains a map with some data center information (not really interesting), and the stream variable comes from http.agent. (defn handle-xml [dc stream] (let [xml-out (xml-seq (parse (http/stream stream)))] (doseq [x xml-out] (doseq [y (:content x)] (doseq [z (:content y)] (doseq [a (:content z)] (println (:dc dc) (:NAME (:attrs z)) (:NAME (:attrs a)) (:VAL (:attrs a)) (:TN (:attrs a) The XML is of the form: ganglia multiple clusters multiple hosts multiple metrics Example of the XML: GANGLIA_XML VERSION=3.0.7 SOURCE=gmond CLUSTER NAME=cluster.example.com LOCALTIME=1258396022 OWNER=unspecified LATLONG=unspecified URL=unspecified HOST NAME=server.example.com IP=127.0.0.1 REPORTED=1258396019 TN=3 TMAX=20 DMAX=86400 LOCATION=unspe cified GMOND_STARTED=1255757736 METRIC NAME=disk_total VAL=1320.124 TYPE=double UNITS=GB TN=6684 TMAX=1200 DMAX=0 SLOPE=both SOURCE=gmond/ METRIC NAME=cpu_speed VAL=2493 TYPE=uint32 UNITS=MHz TN=682 TMAX=1200 DMAX=0 SLOPE=zero SOURCE=gmond/ ... Thanks, Dennis -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Space usage of lazy seqs
On Dec 2, 10:50 am, Johann Hibschman joha...@gmail.com wrote: I don't understand Clojure's space requirements when processing lazy sequences. Are there some rules-of-thumb that I could use to better predict what will use a lot of space? I have a 5.5 GB pipe-delimited data file, containing mostly floats (14 M rows of 40 cols). I'd like to stream over that file, processing columns as I go, without holding the whole thing in RAM. As a first test, I'm trying to just split each row and count the total number of fields. Why does reduce seem to load in the whole file, yet test-split-4 not? Why does the if-let in test-split-3 vs test-split-3b make such a difference? And finally, is there any way I can parallelize this to use multiple cores without slurping in the whole file? If it matters, I'm using a snapshot of 1.1.0-alpha; the jar included with incanter. Here's the code: (defn afile /path/to/big/file) ;; Count the lines in the file. ;; 12.8 s, light memory use (0.8 GB). (defn test-count [] (with-open [rdr (duck-streams/reader afile)] (count (line-seq rdr ;; Split and count. ;; 183.2 s, heavy memory use (8.6 GB). (defn test-split [] (with-open [rdr (duck-streams/reader afile)] (reduce + (map #(count (.split %1 \\|)) (line-seq rdr) ;; 190.8 s, heavy memory use (8.8 GB). (defn test-split-2 [] (with-open [rdr (duck-streams/reader afile)] (loop [counts (seq (map #(count (.split %1 \\|)) (line-seq rdr))) cnt 0] (if counts (recur (next counts) (+ cnt (first counts))) cnt ;; Use rest instead, if-let (followinghttp://clojure.org/lazy.) ;; 166.1 s, light memory use (1.4 GB) (defn test-split-3 [] (with-open [rdr (duck-streams/reader afile)] (loop [counts (map #(count (.split %1 \\|)) (line-seq rdr)) cnt 0] (if-let [s (seq counts)] (recur (rest s) (+ cnt (first s))) cnt ;; Try without the if-let. ;; 211.6 s, heavy memory use (8.7 GB). Surprise! (defn test-split-3b [] (with-open [rdr (duck-streams/reader afile)] (loop [counts (map #(count (.split %1 \\|)) (line-seq rdr)) cnt 0] (if (seq counts) (recur (rest counts) (+ cnt (first counts))) cnt ;; 160 s, light memory use. (1.5 GB) (defn test-split-4 [] (with-open [rdr (duck-streams/reader afile)] (loop [lines (line-seq rdr) cnt 0] (if lines (recur (next lines) (+ cnt (count (.split (first lines) \\| cnt ;; Parallel split and count. ;; Based on test-split-3, but using pmap. ;; 95.1 s, heavy memory use (8.7 GB) (defn test-psplit-1 [] (with-open [rdr (duck-streams/reader afile)] (loop [counts (pmap #(count (.split %1 \\|)) (line-seq rdr)) cnt 0] (if-let [s (seq counts)] (recur (rest s) (+ cnt (first s))) cnt After looking over the code, I'm inclined to not trust those numbers. You're generating a lot of intermediate String instances, which is where the memory is likely going. My guess is the wildly varying memory numbers are due to the GC kicking in (note the times are all in the same ballpark). -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Space usage of lazy seqs
On Dec 2, 10:50 am, Johann Hibschman joha...@gmail.com wrote: I don't understand Clojure's space requirements when processing lazy sequences. Are there some rules-of-thumb that I could use to better predict what will use a lot of space? I have a 5.5 GB pipe-delimited data file, containing mostly floats (14 M rows of 40 cols). I'd like to stream over that file, processing columns as I go, without holding the whole thing in RAM. As a first test, I'm trying to just split each row and count the total number of fields. Why does reduce seem to load in the whole file, yet test-split-4 not? Why does the if-let in test-split-3 vs test-split-3b make such a difference? And finally, is there any way I can parallelize this to use multiple cores without slurping in the whole file? If it matters, I'm using a snapshot of 1.1.0-alpha; the jar included with incanter. Here's the code: (defn afile /path/to/big/file) ;; Count the lines in the file. ;; 12.8 s, light memory use (0.8 GB). (defn test-count [] (with-open [rdr (duck-streams/reader afile)] (count (line-seq rdr ;; Split and count. ;; 183.2 s, heavy memory use (8.6 GB). (defn test-split [] (with-open [rdr (duck-streams/reader afile)] (reduce + (map #(count (.split %1 \\|)) (line-seq rdr) ;; 190.8 s, heavy memory use (8.8 GB). (defn test-split-2 [] (with-open [rdr (duck-streams/reader afile)] (loop [counts (seq (map #(count (.split %1 \\|)) (line-seq rdr))) cnt 0] (if counts (recur (next counts) (+ cnt (first counts))) cnt ;; Use rest instead, if-let (followinghttp://clojure.org/lazy.) ;; 166.1 s, light memory use (1.4 GB) (defn test-split-3 [] (with-open [rdr (duck-streams/reader afile)] (loop [counts (map #(count (.split %1 \\|)) (line-seq rdr)) cnt 0] (if-let [s (seq counts)] (recur (rest s) (+ cnt (first s))) cnt ;; Try without the if-let. ;; 211.6 s, heavy memory use (8.7 GB). Surprise! (defn test-split-3b [] (with-open [rdr (duck-streams/reader afile)] (loop [counts (map #(count (.split %1 \\|)) (line-seq rdr)) cnt 0] (if (seq counts) (recur (rest counts) (+ cnt (first counts))) cnt ;; 160 s, light memory use. (1.5 GB) (defn test-split-4 [] (with-open [rdr (duck-streams/reader afile)] (loop [lines (line-seq rdr) cnt 0] (if lines (recur (next lines) (+ cnt (count (.split (first lines) \\| cnt ;; Parallel split and count. ;; Based on test-split-3, but using pmap. ;; 95.1 s, heavy memory use (8.7 GB) (defn test-psplit-1 [] (with-open [rdr (duck-streams/reader afile)] (loop [counts (pmap #(count (.split %1 \\|)) (line-seq rdr)) cnt 0] (if-let [s (seq counts)] (recur (rest s) (+ cnt (first s))) cnt After reading the code, I'm inclined to not trust those numbers. Note that the time metrics for test-split* are all in the same ballpark, creating the same number of superfluous, intermediate String instances, but the memory numbers you list are wildly different. How are you collecting these numbers? Have you controlled for the GC kicking in? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: inverse of interleave = unravel
Hi, 2009/12/2 Konrad Kułakowski (kony) kulakow...@gmail.com Recently I need something which works as inverse of interleave I did something like that: (defn unravel [expr-list] (loop [flist () slist () tic-tac 0 olist expr-list] (let [item (first olist)] (if (= item nil) (list flist slist) (if (= tic-tac 0) (recur (concat flist (list item)) slist 1 (rest olist)) (recur flist (concat slist (list item)) 0 (rest olist))) Test: (def dl (interleave (iterate inc 1) [A B C D E])) (unravel dl) And the classic question is it possible to do it simple, more in a functional manner, without explicit looping? (defn unravel [s] [(take-nth 2 s) (take-nth 2 (rest s))]) Christophe -- Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.cgrand.net/ (en) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: inverse of interleave = unravel
On Wed, Dec 2, 2009 at 2:06 PM, ataggart alex.tagg...@gmail.com wrote: On Dec 2, 9:10 am, Konrad Kułakowski (kony) kulakow...@gmail.com wrote: Recently I need something which works as inverse of interleave How about this? (defn skip [coll n] (lazy-seq (when-let [s (seq coll)] (cons (first s) (skip (drop n (next s)) n) (defn unravel [coll n] (for [i (range n)] (skip (drop i coll) (dec n Not bad. Your unravel takes an n, which is needed because interleave accepts any number of collections, not just two. Your 'skip' is a lot like take-nth. Here's what I had: (defn unravel [n coll] (map #(take-nth n (drop % coll)) (range n))) --Chouser -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: What about contains? for lists
On Dec 2, 7:10 am, Stefan Kamphausen ska2...@googlemail.com wrote: Hi, while studying the collection types and trying to find out which functions work on all collection types (i.e. lists, vectors, maps, sets) I was flabbergasted by the following user (contains? (list 1 2 3) 3) false OK, the doc of contains? told me that for indexed collection-types it will only check, whether the index is within the valid range. So maybe: user (contains? (list 1 2 3) 1) false At that point I dived into the implementation and found that in RT.java checks for the type of collection passed but leaves out PersistenList. I'd like to understand the (probably well-grounded) reason for that. As far as I can see PersistentList extends Counted, so the check for the index-range should at least be possible. However, I think people would expect an equality check in the background, which OTOH would be O (N), probably. Kind regards, Stefan That's because contains? checks for keys not values. Since a list isn't associative (unlike vectors and maps), it doesn't have keys, thus contains? doesn't apply. I too was first thrown off by assuming contains? worked on the values of a collection; for that you can instead use some. (if (some #(= :a) '(:a :b :c)) :contains-a :does-not-contain-a -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: What about contains? for lists
On Dec 2, 12:06 pm, ataggart alex.tagg...@gmail.com wrote: On Dec 2, 7:10 am, Stefan Kamphausen ska2...@googlemail.com wrote: Hi, while studying the collection types and trying to find out which functions work on all collection types (i.e. lists, vectors, maps, sets) I was flabbergasted by the following user (contains? (list 1 2 3) 3) false OK, the doc of contains? told me that for indexed collection-types it will only check, whether the index is within the valid range. So maybe: user (contains? (list 1 2 3) 1) false At that point I dived into the implementation and found that in RT.java checks for the type of collection passed but leaves out PersistenList. I'd like to understand the (probably well-grounded) reason for that. As far as I can see PersistentList extends Counted, so the check for the index-range should at least be possible. However, I think people would expect an equality check in the background, which OTOH would be O (N), probably. Kind regards, Stefan That's because contains? checks for keys not values. Since a list isn't associative (unlike vectors and maps), it doesn't have keys, thus contains? doesn't apply. I too was first thrown off by assuming contains? worked on the values of a collection; for that you can instead use some. (if (some #(= :a) '(:a :b :c)) :contains-a :does-not-contain-a Erm... that predicate should be #(= :a %) or (partial = :a) or #{:a}. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Leiningen Run ?
On Dec 2, 12:38 pm, David Nolen dnolen.li...@gmail.com wrote: Yeah it sounds like you'll need to package up JOGL 2 and push it to Clojars right? On Wed, Dec 2, 2009 at 3:20 PM, Zach Tellman ztell...@gmail.com wrote: On Dec 1, 3:31 pm, David Nolen dnolen.li...@gmail.com wrote: So just to keep the conversation going: http://download.java.net/maven/2/net/java/dev/gluegen/http://download... I note that these two maven repos specify the platform with the following: lib-{platform}-{arch} where platform is: macosx linux windows arch is: universal i586 followed by the architecture. I'm assuming lein should resolve this auto-magically based on the platform Java is running on? I don't mind contributing some code to make this work if there's feedback on how it should work what it should look like. David That maven repository isn't for JOGL 2.0, which is what I'm using. I'm not sure a maven repo exists for that version currently. Would the solution be to make such a repository for any JNI libraries we use? That's not really a problem, I'm just unclear on precisely what you're suggesting. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en If that's what it takes, great. Someone just needs to define what a multi-platform JNI package looks like. I'm willing to go along with whatever is decided upon by technomancy et al. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
concurrent tests?
hi, i've seen some blog posts / code about using agents to use up cores/hyper-threading and speed up testing cycles. how might one do that with clojure.test{.tap}? like if somebody already has that in github somewhere i don't want to reinvent the wheel. thanks. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Hiring clojure devs again :)
We need to hire another two full-time devs (!) to work on a clojure project (distributed backend on clojure). Don't be nervous about that old job - take a risk! Wake up and work in your PJs with interesting code and get paid to code in clojure! (I live on Kauai, HI) The team currently consists of myself (dysinger), phil (technomancy), dan (danlarkin), george (gjahad) and Steve (scgilardi) and we all use and love Emacs (requirement so we can pair). We would prefer a well rounded polyglot w/ some real exposure to jvm, lisps and functional programming. We practice remote TDD pair-programming (Skype/Gizmo/Emacs/Screen) on our team. A typical day is a morning stand-up on voip followed by pair-programming sessions. Occasional spikes require solo work. If you feel you have clojure under your belt, please drop a resume with an intro on why you want this job to j...@sonian.net. If you are involved in any open source clojure code, please include links. If you have sent me an email in the past, please try again (sorry I have been swamped). It's impossible to know what it's like to work for us and us with you in interviews. We don't do grueling interviews. Our pattern for interviewing is 30 days paid work where either party can walk away. We currently aren't looking for part-timers or people with distracting interests on the side. This is a dead-serious job with a funded start-up and we need focus. The job includes a 15 MBP 3g. Tim Dysinger VP of Engineering, Sonian Networks -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: What about contains? for lists
On Dec 2, 1:32 pm, Stefan Kamphausen ska2...@googlemail.com wrote: Hi, On Dec 2, 10:24 pm, ataggart alex.tagg...@gmail.com wrote: My guess is that String and array, while not implementing the IAssociative interface, all have the O(1) lookup performance guarantees of associative data structures, um, no? According to the bit-partition implementation of vector and the slightly more complex implementation of maps they are O(log_{32} (N)), which of course given the size of Integer doesn't get too large. So I wouldn't think, the Big-O was the reason. Yes, yes it's not truly O(1), but it's close enough. Vectors are distinct from lists not only in which end new elements are appended, but also in the performance guarantees they try to meet. Again, my guess is that the lookup complexity was the driver as the intention of the function is to be used with associative structures. But lists, as others, have O(1) lookup for count, so at least the index-based contains? which is used for vectors, Strings and arrays should be usable. I will further guess that lists weren't added since the key to contains? can't be used to lookup a value in (near) O(1), whereas you can do so with Strings and arrays, e.g., (get hello 1) returns \e. The parameter to get is map and not coll. I would agree that contains? should likewise reflect the associative nature of the collection (though the doc does use the word key). Actually it may be usable for every class extending Counted. If you want to know the number of elements in a collection, or whether an index is valid for a collection, use count. The contains? function, like the get function, is intended to operate on suitable data structures without being concerned with type. In short, if you can't pass your data to get, you shouldn't expect contains? to work either. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Clojure Koans?
On Dec 2, 2009, at 4:36 PM, ataggart wrote: If by koan you mean usage examples, then there are plenty of them within the clojure source itself, as well as clojure-contrib. The Koans are more than just examples. They are designed to demonstrate one concept at a time and are arranged so that each example builds on the previous ones. Leave it to rubyists to turn a simple concept like examples into some religious indoctrination. I kid! Actually, the Ruby Koans were very much inspired by the question/ answer style of the Little Lisper. So now it has come full circle back to the Lisp world. At one point in time I was considering putting together a set of Clojure koans, but got sidetracked with the SICP study. I discovered I can't learn Scheme and learn Clojure at the same time, so Clojure Koans are on hold for the moment. If anyone wants to run with the idea, feel free. -- -- Jim Weirich -- jim.weir...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Minimum value in a vector
I am having difficulty approaching this problem. I'm not sure if it can be done in one swoop, or requires a few steps. I have 5 vectors as such: a [2 4 6 7] b [1 3 9 2] c [2 4 5 6] d [6 1 3 8] e [4 8 2 1] And I want to take the minimum value at a given index between the vectors. Therefore, minimum value at index 0 would yield the value 1 from vector b. Thank You. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Article in German Linux Magazin
Hi, having received the blessings of #clojure (kind of) I'll be bold enough to post a link to an article on Clojure that was published today. http://www.linux-magazin.de/Heft-Abo/Ausgaben/2010/01/Nebenlaeufig Please note, that as of today you can also buy that fine magazine in print. ;-) Hopefully I got everything correct and the article provides a useful introduction to the language (whatever is possible on just four pages). Uhm, I think, I should add that I wrote it. Criticism welcome. Kind regards, Stefan -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Minimum value in a vector
assuming, vector a b c d e are already defined. I'd do user= (map vector a b c d e) ([2 1 2 6 4] [4 3 4 1 8] [6 9 5 3 2] [7 2 6 8 1]) you can then use the solutions provided from previous messages to find the min value of each vector. so you then end up with [0 1 0 0 0] [0 0 0 1 0] [0 0 0 0 1] [0 0 0 0 1] at that point, you repeat the same trick (map vector [0 1 0 0 0] [0 0 0 1 0] [0 0 0 0 1] [0 0 0 0 1]) and that will give you [0 0 0 0] [1 0 0 0] [0 0 0 0] [0 1 0 0] [0 0 1 1] On Wed, Dec 2, 2009 at 6:22 PM, Don josereyno...@gmail.com wrote: Thank you Stefan and Kevin. Awesome solutions that answer my question. However I actually made a mistake in posing my question. Let me attempt to ask my question again. I have 5 vectors as such: a [2 4 6 7] b [1 3 9 2] c [2 4 5 6] d [6 1 3 8] e [4 8 2 1] and the output i want is this a1 [0 0 0 0] b1 [1 0 0 0] c1 [0 0 0 0] d1 [0 1 0 0] e1 [0 0 1 1] Now I'm not sure if it can be done in one swoop, or should be done in a loop. I was thinking a loop, but I'm having trouble thinking about it. I initially thought of creating a function that takes in 5 vectors and returns a single vector. So the first time its called it would return a1 [0 0 0 0] then call it again and return b1 [1 0 0 0] etc... I know it will repeat calculations however I couldn't come up with anything else. Thank you. On Dec 2, 2:55 pm, Kevin Downey redc...@gmail.com wrote: user= (vec (map min [2 4 6 7] [1 3 9 2] [2 4 5 6] [6 1 3 8] [4 8 2 1])) [1 1 2 1] user= On Wed, Dec 2, 2009 at 2:53 PM, Stefan Kamphausen ska2...@googlemail.com wrote: Hi, On Dec 2, 11:43 pm, Don josereyno...@gmail.com wrote: I am having difficulty approaching this problem. I'm not sure if it can be done in one swoop, or requires a few steps. I have 5 vectors as such: a [2 4 6 7] b [1 3 9 2] c [2 4 5 6] d [6 1 3 8] e [4 8 2 1] And I want to take the minimum value at a given index between the vectors. Therefore, minimum value at index 0 would yield the value 1 from vector b. a quick shot would be (reduce min (map #(get % 0) (list a b c d e))) It would be nicer to have a vector of vectors or a list of vectors at the beginning, probably. Cheers, Stefan -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Omnem crede diem tibi diluxisse supremum. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Minimum value in a vector
On Wed, Dec 2, 2009 at 5:43 PM, Don josereyno...@gmail.com wrote: I am having difficulty approaching this problem. I'm not sure if it can be done in one swoop, or requires a few steps. I have 5 vectors as such: a [2 4 6 7] b [1 3 9 2] c [2 4 5 6] d [6 1 3 8] e [4 8 2 1] And I want to take the minimum value at a given index between the vectors. Therefore, minimum value at index 0 would yield the value 1 from vector b. (defn min-col [col vecs] (apply min (map #(nth % col) vecs))) user= (min-col 0 [[2 4 6 7] [1 3 9 2] [2 4 5 6] [6 1 3 8] [4 8 2 1]]) 1 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Clojure Koans?
On Dec 2, 12:43 pm, Jim Weirich jim.weir...@gmail.com wrote: On Dec 2, 2009, at 4:36 PM, ataggart wrote: If by koan you mean usage examples, then there are plenty of them within the clojure source itself, as well as clojure-contrib. The Koans are more than just examples. They are designed to demonstrate one concept at a time and are arranged so that each example builds on the previous ones. Leave it to rubyists to turn a simple concept like examples into some religious indoctrination. I kid! Actually, the Ruby Koans were very much inspired by the question/ answer style of the Little Lisper. So now it has come full circle back to the Lisp world. Would you recommend the Little Lisper today (assuming you've read it) and have it be application enough to Clojure that it would be worth reading? At one point in time I was considering putting together a set of Clojure koans, but got sidetracked with the SICP study. I discovered I can't learn Scheme and learn Clojure at the same time, so Clojure Koans are on hold for the moment. If anyone wants to run with the idea, feel free. The Ruby Koans were really fun to go through and I always recommend it to people new to Ruby. And BTW, I was pleasantly surprised to see you respond to this post. I don't know if you recall our conversation (I'm who drove you around Oahu while you were in town for Aloha on Rails :)), but our Emacs talk really got me motivated and using Emacs full time which got me interested in Lisps which brought me to Clojure! So thanks for the inspiring talk! -Matt -- -- Jim Weirich -- jim.weir...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Article in German Linux Magazin
Is there a translation? Google translator is not so good and I only know basic German... 2009/12/2 Stefan Kamphausen ska2...@googlemail.com Hi, having received the blessings of #clojure (kind of) I'll be bold enough to post a link to an article on Clojure that was published today. http://www.linux-magazin.de/Heft-Abo/Ausgaben/2010/01/Nebenlaeufig Please note, that as of today you can also buy that fine magazine in print. ;-) Hopefully I got everything correct and the article provides a useful introduction to the language (whatever is possible on just four pages). Uhm, I think, I should add that I wrote it. Criticism welcome. Kind regards, Stefan -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Space usage of lazy seqs
On Wed, Dec 02, 2009 at 02:01:36PM -0800, Johann Hibschman wrote: There is a qualitative difference between the runs, though. I can run test-split-3 five times in a row, all with similar times, without having the java process size get bigger than 0.6 GB. When I run any of the others, the size quickly balloons up to something more like 8.5 GB. How much memory do you have on your machine. A recent Sun JVM on a machine with a bunch of memory will consider it to be a server machine. It will set the heap max to 1/4 of total physical memory (which suggests you might have 16GB of RAM). You can tune the max with -Xmx1G for example, to limit it to one GB. The actual interaction with the GC can be hard to predict, and Sun's GC seems to like to sometimes use as much memory as it has been given. If you're running JDK 6, you can run the virtualvm, or jconsole to get a better handle on the memory usage, and even dig into what it might used for. David -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Minimum value in a vector
(defn min-dist [coll] (let [minval (reduce min coll)] (map #(if (= minval %) 1 0) coll))) this function, if you pass user= (min-dist [2 1 2 6 4]) (0 1 0 0 0) assume the 5 vectors are stored in a b c d e. user= (apply map vector (map min-dist (map vector a b c d e))) ([0 0 0 0] [1 0 0 0] [0 0 0 0] [0 1 0 0] [0 0 1 1]) On Wed, Dec 2, 2009 at 7:59 PM, Don josereyno...@gmail.com wrote: I still can't figure it out. If have this set. a [2 4 6 7] b [1 3 9 2] c [2 4 5 6] d [6 1 3 8] e [4 8 2 1] If I do (reduce min (map #(get % 0) (list a b c d e))) It grabs the min value from index 0 of the five vectors and returns 1 corresponding to 'b'. But I'm not sure how I would determine it's coming from 'b'. I need to know that it comes from 'b' in order to build the new vector. If I do (vec (map min a b c d e)) It grabs the min value from index (0, 1, 2, 3) and puts it in a vector [1 1 2 1] And I don't know from what vector the minimum value is coming from. The solution is probably already here but I can't think of it. Sorry. On Dec 2, 3:40 pm, Wilson MacGyver wmacgy...@gmail.com wrote: assuming, vector a b c d e are already defined. I'd do user= (map vector a b c d e) ([2 1 2 6 4] [4 3 4 1 8] [6 9 5 3 2] [7 2 6 8 1]) you can then use the solutions provided from previous messages to find the min value of each vector. so you then end up with [0 1 0 0 0] [0 0 0 1 0] [0 0 0 0 1] [0 0 0 0 1] at that point, you repeat the same trick (map vector [0 1 0 0 0] [0 0 0 1 0] [0 0 0 0 1] [0 0 0 0 1]) and that will give you [0 0 0 0] [1 0 0 0] [0 0 0 0] [0 1 0 0] [0 0 1 1] On Wed, Dec 2, 2009 at 6:22 PM, Don josereyno...@gmail.com wrote: Thank you Stefan and Kevin. Awesome solutions that answer my question. However I actually made a mistake in posing my question. Let me attempt to ask my question again. I have 5 vectors as such: a [2 4 6 7] b [1 3 9 2] c [2 4 5 6] d [6 1 3 8] e [4 8 2 1] and the output i want is this a1 [0 0 0 0] b1 [1 0 0 0] c1 [0 0 0 0] d1 [0 1 0 0] e1 [0 0 1 1] Now I'm not sure if it can be done in one swoop, or should be done in a loop. I was thinking a loop, but I'm having trouble thinking about it. I initially thought of creating a function that takes in 5 vectors and returns a single vector. So the first time its called it would return a1 [0 0 0 0] then call it again and return b1 [1 0 0 0] etc... I know it will repeat calculations however I couldn't come up with anything else. Thank you. On Dec 2, 2:55 pm, Kevin Downey redc...@gmail.com wrote: user= (vec (map min [2 4 6 7] [1 3 9 2] [2 4 5 6] [6 1 3 8] [4 8 2 1])) [1 1 2 1] user= On Wed, Dec 2, 2009 at 2:53 PM, Stefan Kamphausen ska2...@googlemail.com wrote: Hi, On Dec 2, 11:43 pm, Don josereyno...@gmail.com wrote: I am having difficulty approaching this problem. I'm not sure if it can be done in one swoop, or requires a few steps. I have 5 vectors as such: a [2 4 6 7] b [1 3 9 2] c [2 4 5 6] d [6 1 3 8] e [4 8 2 1] And I want to take the minimum value at a given index between the vectors. Therefore, minimum value at index 0 would yield the value 1 from vector b. a quick shot would be (reduce min (map #(get % 0) (list a b c d e))) It would be nicer to have a vector of vectors or a list of vectors at the beginning, probably. Cheers, Stefan -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Omnem crede diem tibi diluxisse supremum. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Omnem crede diem tibi diluxisse supremum. -- You received this message because you
Re: Minimum value in a vector
On Wed, Dec 2, 2009 at 6:22 PM, Don josereyno...@gmail.com wrote: Thank you Stefan and Kevin. Awesome solutions that answer my question. However I actually made a mistake in posing my question. Let me attempt to ask my question again. I have 5 vectors as such: a [2 4 6 7] b [1 3 9 2] c [2 4 5 6] d [6 1 3 8] e [4 8 2 1] and the output i want is this a1 [0 0 0 0] b1 [1 0 0 0] c1 [0 0 0 0] d1 [0 1 0 0] e1 [0 0 1 1] (defn min-cols [v] (map #(apply min-key % (range (count v))) (apply map vector v))) (defn mark-cols [v m] (map (fn [i] (map #(if % 1 0) (map = m (repeat (count m) i (range (count v (def v [[2 4 6 7] [1 3 9 2] [2 4 5 6] [6 1 3 8] [4 8 2 1]]) user= (mark-cols v (min-cols v)) ((0 0 0 0) (1 0 0 0) (0 0 0 0) (0 1 0 0) (0 0 1 1)) --Chouser -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Java Class Factory
Hello, I'm trying to create a factory method for Java classes, however I'm doing something wrong. (import '(java.util Dictionary HashMap)) (def *containers* { :dict Dictionary :hash HashMap}) (defn new-container [type] (new (*containers* type))) (def d (new-container :dict)) The above gives me Exception in thread main java.lang.IllegalArgumentException: Unable to resolve classname: (*containers* type) (t.clj:6) at clojure.lang.Compiler.analyzeSeq(Compiler.java:4599) at clojure.lang.Compiler.analyze(Compiler.java:4405) at clojure.lang.Compiler.analyze(Compiler.java:4366) at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:3942) at clojure.lang.Compiler$FnMethod.parse(Compiler.java:3777) at clojure.lang.Compiler$FnMethod.access$1100(Compiler.java:3654) at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3024) at clojure.lang.Compiler.analyzeSeq(Compiler.java:4590) at clojure.lang.Compiler.analyze(Compiler.java:4405) at clojure.lang.Compiler.analyzeSeq(Compiler.java:4580) at clojure.lang.Compiler.analyze(Compiler.java:4405) at clojure.lang.Compiler.access$100(Compiler.java:35) at clojure.lang.Compiler$DefExpr$Parser.parse(Compiler.java:373) at clojure.lang.Compiler.analyzeSeq(Compiler.java:4592) at clojure.lang.Compiler.analyze(Compiler.java:4405) at clojure.lang.Compiler.analyze(Compiler.java:4366) at clojure.lang.Compiler.eval(Compiler.java:4646) at clojure.lang.Compiler.load(Compiler.java:4972) at clojure.lang.Compiler.loadFile(Compiler.java:4939) at clojure.main$load_script__7423.invoke(main.clj:211) at clojure.main$script_opt__7460.invoke(main.clj:263) at clojure.main$main__7484.doInvoke(main.clj:338) at clojure.lang.RestFn.invoke(RestFn.java:413) at clojure.lang.Var.invoke(Var.java:359) at clojure.lang.AFn.applyToHelper(AFn.java:173) at clojure.lang.Var.applyTo(Var.java:476) at clojure.main.main(main.java:37) Caused by: java.lang.IllegalArgumentException: Unable to resolve classname: (*containers* type) at clojure.lang.Compiler$NewExpr$Parser.parse(Compiler.java:2243) at clojure.lang.Compiler.analyzeSeq(Compiler.java:4592) ... 26 more What is the right way to do this? Thanks, -- Miki -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: ClojureCLR questions
1. CLR Interop: Interop is the focus of development at the moment. Work is progressing on those things that the JVM implementation doesn't worry about: ref/out params, assembly references, generics, etc.I haven't spent much think time on attributes yet. Do you have some specific use cases? That would be stimulating. 2. Performance goals: Clojure:Java::ClojureCLR:C#.Not there yet, but no reason why this is not achievable.If you look at the IL generated, ClojureCLR is almost identical to ClojureJVM. At this point, I consider interop the bigger impediment. The game plan for the near future: Interop, implementing the new deftype/reify/protocol goodness, then maybe performance. deftype/c affect IL generation, so I'd like to get that done before coming back to look at the grungy details of whether or not the CLR is inlining some little thing. 3. I'll let the folks who are better at Clojure programming style answer this one. -David M On Dec 1, 11:41 pm, Mike K mbk.li...@gmail.com wrote: Hi Clojurites! I'm reading about Clojure and ClojureCLR with great interest. Since I'm a .net developer with little Java / JVM experience, I'm particularly interested in ClojureCLR. It seems like David M. and crew are doing a fantastic job with the CLR implementation! A few quick questions: 1. Re. CLR Interop -- one thing I didn't see mentioned on the wiki is .net attributes (metadata). Will annotating methods, properties, etc with attributes be supported? 2. What are the performance goals for ClojureCLR? I saw a video overview of Clojure by Rich in which he stated (perhaps with certain caveats that I don't recall) that essentially Clojure ran at speeds comparable to Java. Is having ClojureCLR run at speeds comparable to C# a realistic goal? What's the current performance story? 3. I get the basic concept that native Clojure data structures are immutable and persistent. This is obviously an impedance mismatch when dealing with JVM or .net objects and APIs that are built around mutable state. Where can I more info regarding best practices in getting these two different animals to work well together within an app? Thanks, Mike -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Minimum value in a vector
Thanks to everyone for the solutions. I actually wrote this terribly ugly function. Terrible. This should go in the don't write code like this section in clojure book. (defn md2 [d1 d2 d3 d4 d5] (let [cnt (count d1)] (loop [i 0 v []] (if (= i cnt) v (do (if (= (get d1 i) (reduce min (map #(get % i) (list d1 d2 d3 d4 d5 (recur (inc i) (conj v 1)) (recur (inc i) (conj v 0 On Dec 2, 7:43 pm, Chouser chou...@gmail.com wrote: On Wed, Dec 2, 2009 at 6:22 PM, Don josereyno...@gmail.com wrote: Thank you Stefan and Kevin. Awesome solutions that answer my question. However I actually made a mistake in posing my question. Let me attempt to ask my question again. I have 5 vectors as such: a [2 4 6 7] b [1 3 9 2] c [2 4 5 6] d [6 1 3 8] e [4 8 2 1] and the output i want is this a1 [0 0 0 0] b1 [1 0 0 0] c1 [0 0 0 0] d1 [0 1 0 0] e1 [0 0 1 1] (defn min-cols [v] (map #(apply min-key % (range (count v))) (apply map vector v))) (defn mark-cols [v m] (map (fn [i] (map #(if % 1 0) (map = m (repeat (count m) i (range (count v (def v [[2 4 6 7] [1 3 9 2] [2 4 5 6] [6 1 3 8] [4 8 2 1]]) user= (mark-cols v (min-cols v)) ((0 0 0 0) (1 0 0 0) (0 0 0 0) (0 1 0 0) (0 0 1 1)) --Chouser -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Java Class Factory
(new) tries to resolve the argument at compile-time, not runtime. You need to spell out each (new class) in a cond. You might write a macro to make it a little less verbose. -Mike -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Java Class Factory
On Dec 2, 8:15 pm, lazy1 miki.teb...@gmail.com wrote: Hello, I'm trying to create a factory method for Java classes, however I'm doing something wrong. (import '(java.util Dictionary HashMap)) (def *containers* { :dict Dictionary :hash HashMap}) (defn new-container [type] (new (*containers* type))) (def d (new-container :dict)) The above gives me Exception in thread main java.lang.IllegalArgumentException: Unable to resolve classname: (*containers* type) (t.clj:6) at clojure.lang.Compiler.analyzeSeq(Compiler.java:4599) at clojure.lang.Compiler.analyze(Compiler.java:4405) at clojure.lang.Compiler.analyze(Compiler.java:4366) at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:3942) at clojure.lang.Compiler$FnMethod.parse(Compiler.java:3777) at clojure.lang.Compiler$FnMethod.access$1100(Compiler.java:3654) at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3024) at clojure.lang.Compiler.analyzeSeq(Compiler.java:4590) at clojure.lang.Compiler.analyze(Compiler.java:4405) at clojure.lang.Compiler.analyzeSeq(Compiler.java:4580) at clojure.lang.Compiler.analyze(Compiler.java:4405) at clojure.lang.Compiler.access$100(Compiler.java:35) at clojure.lang.Compiler$DefExpr$Parser.parse(Compiler.java:373) at clojure.lang.Compiler.analyzeSeq(Compiler.java:4592) at clojure.lang.Compiler.analyze(Compiler.java:4405) at clojure.lang.Compiler.analyze(Compiler.java:4366) at clojure.lang.Compiler.eval(Compiler.java:4646) at clojure.lang.Compiler.load(Compiler.java:4972) at clojure.lang.Compiler.loadFile(Compiler.java:4939) at clojure.main$load_script__7423.invoke(main.clj:211) at clojure.main$script_opt__7460.invoke(main.clj:263) at clojure.main$main__7484.doInvoke(main.clj:338) at clojure.lang.RestFn.invoke(RestFn.java:413) at clojure.lang.Var.invoke(Var.java:359) at clojure.lang.AFn.applyToHelper(AFn.java:173) at clojure.lang.Var.applyTo(Var.java:476) at clojure.main.main(main.java:37) Caused by: java.lang.IllegalArgumentException: Unable to resolve classname: (*containers* type) at clojure.lang.Compiler$NewExpr$Parser.parse(Compiler.java:2243) at clojure.lang.Compiler.analyzeSeq(Compiler.java:4592) ... 26 more What is the right way to do this? Thanks, -- Miki What Mike said. Also, you might not even need to nor want to. There may be a better option given a bit more info. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Hiring clojure devs again :)
On Dec 2, 2009, at 5:04 PM, dysinger wrote: We need to hire another two full-time devs (!) to work on a clojure project (distributed backend on clojure). Don't be nervous about that old job - take a risk! Wake up and work in your PJs with interesting code and get paid to code in clojure! (I live on Kauai, HI) The team currently consists of myself (dysinger), phil (technomancy), dan (danlarkin), george (gjahad) and Steve (scgilardi) and we all use and love Emacs (requirement so we can pair). We would prefer a well rounded polyglot w/ some real exposure to jvm, lisps and functional programming. We practice remote TDD pair-programming (Skype/Gizmo/Emacs/Screen) on our team. A typical day is a morning stand-up on voip followed by pair-programming sessions. Occasional spikes require solo work. If you feel you have clojure under your belt, please drop a resume with an intro on why you want this job to j...@sonian.net. If you are involved in any open source clojure code, please include links. If you have sent me an email in the past, please try again (sorry I have been swamped). It's impossible to know what it's like to work for us and us with you in interviews. We don't do grueling interviews. Our pattern for interviewing is 30 days paid work where either party can walk away. We currently aren't looking for part-timers or people with distracting interests on the side. This is a dead-serious job We aren't /that/ serious :) with a funded start-up and we need focus. The job includes a 15 MBP 3g. Tim Dysinger VP of Engineering, Sonian Networks -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
API pages
Hey, the API page doesn't look right in Firefox 3.5 The cut off around halfway through the page. I think this also happens in Safari, but I'm not sure right now. Oh, and IE 6... YUCK! (But that's expected :)) Sean -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Specified behavior of every?
The following return true: user=(every? even? nil) true user=(every? even? []) true Is this behavior the specified behavior? Can I ASSUME it is true in my code? Sean -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Specified behavior of every?
I've always relied on this being true without losing sleep at night (or during the day), and it has a good grounding in predicate logic: http://en.wikipedia.org/wiki/Universal_quantification#The_empty_set Cheers, Mark Sean Devlin francoisdev...@gmail.com writes: The following return true: user=(every? even? nil) true user=(every? even? []) true Is this behavior the specified behavior? Can I ASSUME it is true in my code? -- Mark Triggs mark.h.tri...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Specified behavior of every?
Is this behavior the specified behavior? Can I ASSUME it is true in my code? I imagine that Clojure's some?/every? follow Common Lisp's every and some, defined as: every returns false as soon as any invocation of predicate returns false. If the end of a sequence is reached, every returns true. Thus, every returns true if and only if every invocation of predicate returns true. some returns the first non-nil value which is returned by an invocation of predicate. If the end of a sequence is reached without any invocation of the predicate returning true, some returns false. Thus, some returns true if and only if some invocation ofpredicate returns true. even? never returns false (because it's never called), and so every? returns true when it reaches the end of the sequence. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: concurrent tests?
Hello Raoul, I don't know if one of the blog posts that you are referring to was mine. I did blog yesterday about running tests concurrently. I have put the code that I use to run my tests on GitHib here: http://github.com/brentonashworth/fpl-clojure-util See the file test.clj I use this with clojure.test. You can create tests using deftest from clojure.test or you can use the def-test macro to define a test. This will allow you to turn logging on and off by setting the *logging* var to true or false. It assumes that tests for namespace com.company.file.clj will be in com.company.test_file.clj and located under the test project directory. If you pass -seq when running the tests, they will be run sequentially. If you pass the file name then only the tests for that namespace will be run. Finally, it runs each test namespace concurrently, not each test. Anyway, this is what I use. I hope you find it helpful. Brenton On Dec 2, 1:59 pm, Raoul Duke rao...@gmail.com wrote: hi, i've seen some blog posts / code about using agents to use up cores/hyper-threading and speed up testing cycles. how might one do that with clojure.test{.tap}? like if somebody already has that in github somewhere i don't want to reinvent the wheel. thanks. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Getting Started in Mac OS X Snow Leopard
Matthew; Thank you! Now I'm being able to program with Clojure. This was the route I should have use from the begging. Aquamacs is not very suitable for ELPA installations. Anyone who wants to use Clojure in Emacs, in a Mac OS X computer should follow this instructions. It's very easy. Guido On Dec 2, 1:42 pm, Matthew Williams matthew.d.willi...@gmail.com wrote: Using the Cocoa build of Emacs 23 (http://www.emacsformacosx.com) I was able to get up and running extremely quickly with Technomancy's swank-clojure install. http://technomancy.us/swank-clojure After just a few minutes I was in the REPL and ready to go. Good luck! On Nov 30, 8:32 pm, Charras guido.carba...@gmail.com wrote: Hello; I already install Clojure using MacPorts, and I can use it with clj. But the environment is not what I will like. I'm trying to set up clojure, so I can use it inAquamacs. I already download the clojure- mode.el, in there says that I can install it using ELPA, but I don't know how to install ELPA inaquamacs. Please, if someone can help me to setup clojure, in my Mac, and be able to use it, withAquamacs, I'll appreciated very much. Regards! Guido -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Space usage of lazy seqs
On Dec 2, 9:09 pm, David Brown cloj...@davidb.org wrote: ... If you're running JDK 6, you can run the virtualvm, or jconsole to get a better handle on the memory usage, and even dig into what it might used for. Google does not return useful references to a tool called virtualvm; perhaps you mean VisualVM (jvisualvm)? -Dave -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Space usage of lazy seqs
On Dec 2, 9:09 pm, David Brown cloj...@davidb.org wrote: How much memory do you have on your machine. A recent Sun JVM on a machine with a bunch of memory will consider it to be a server machine. It will set the heap max to 1/4 of total physical memory (which suggests you might have 16GB of RAM). I have 96 GB, so I'm not in danger of running out. I just want to understand if I'm using the sequence functions properly, so that I can run a few instances of this, plus some R, etc. You can tune the max with -Xmx1G for example, to limit it to one GB. That's a good idea; then I'll know for sure if it's keeping a handle to the entire file. If you're running JDK 6, you can run the virtualvm, or jconsole to get a better handle on the memory usage, and even dig into what it might used for. Ah, I'd forgotten about jconsole. Well, I'll muddle around and see what I can figure out. Thanks, Johann -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Java Class Factory
On Dec 2, 11:15 pm, lazy1 miki.teb...@gmail.com wrote: Hello, I'm trying to create a factory method for Java classes, however I'm doing something wrong. (import '(java.util Dictionary HashMap)) (def *containers* { :dict Dictionary :hash HashMap}) (defn new-container [type] (new (*containers* type))) (def d (new-container :dict)) The above gives me Exception in thread main java.lang.IllegalArgumentException: Unable to resolve classname: (*containers* type) (t.clj:6) new does not evaluate its arguments, so it is trying to interpret the form (*containers* type) as a classname, which it cannot do. Another problem with your example is that java.util.Dictionary is an abstract class, and cannot be instantiated directly; of the two classes you gave, you will only be able to create instances of HashMap. ... What is the right way to do this? Aside from the issue with Dictionary being abstract, I think you need a macro to do what you want to do: (defmacro new-container [type] `(new ~(*containers* type))) -Dave Thanks, -- Miki -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en