JVM 7 support (invokedynamic)
Hey folks, I just want to reassure y'all that I am working on this. It took a while to create a test environment: one of the challenges of using invokedynamic is that the Java language does not support it; so the best way to test right now is with ASM 4.0, which is still not officially released. Documentation on the opcode is also somewhat scattered, and mostly out of date, since JSR-292 has changed quite a bit until the final release. The JRuby folk are definitely at the cutting edge of this right (well, after all, JRuby's John Rose is the key mover and architect behind the JSR), and I'm trying to learn from their implementation. Right now I'm working on a code tree outside the main Clojure source, and once that seems to work, I will try to merge it into a branch. So, it's not *quite* as easy as I hoped, but I still think it will be much easier to use invokedynamic in Clojure than in JRuby. I'll keep the mailing list updated on my (slow) progress, and will definitely make the code public once it becomes ... presentable. -- 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: clojurescript support of ns-* functions
On Fri, Aug 19, 2011 at 8:59 AM, Chouser wrote: > Does that help? > --Chouser Yes, thanks Chouser. I can see how fully supporting namespaces would require introspection abilities not available at run time. For my use case, which basically involves checking to see if a symbol is defined in any of the required namespaces, I'd be happy with a compile time solution. Having these functions work at compile time for ClojureScript and runtime for Clojure sounds like too much of a mismatch, though. For now I'll just hard code the ns/symbol. Best, Jim -- 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: Seq of Numbers from 0 to N and Back
Thanks Aaron. Very neat! On Aug 24, 7:05 pm, Aaron Cohen wrote: > One way: > > user=>(concat (range 5) (range 5 0 -1)) > (0 1 2 3 4 5 4 3 2 1) > > user=>(take 15 (cycle (concat (range 5) (range 5 0 -1))))) > (0 1 2 3 4 5 4 3 2 1 0 1 2 3 4) > > On Wed, Aug 24, 2011 at 6:49 PM, HiHeelHottie wrote: > > > > > > > > > > > How can you generate a sequence of numbers from 0 to n and back? Here > > is my try. > > > user> (require '(clojure.contrib [math :as math])) > > nil > > user> (take 15 (let [n 3] (drop n (map #(math/abs (- (mod % (* n 2)) > > n)) (range) > > (0 1 2 3 2 1 0 1 2 3 2 1 0 1 2) > > > -- > > 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: Web Services with Clojure
You can also look at Prudence, which underneath uses Restlet: http://threecrickets.com/prudence/ -- 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: Seq of Numbers from 0 to N and Back
One way: user=>(concat (range 5) (range 5 0 -1)) (0 1 2 3 4 5 4 3 2 1) user=>(take 15 (cycle (concat (range 5) (range 5 0 -1))))) (0 1 2 3 4 5 4 3 2 1 0 1 2 3 4) On Wed, Aug 24, 2011 at 6:49 PM, HiHeelHottie wrote: > > How can you generate a sequence of numbers from 0 to n and back? Here > is my try. > > user> (require '(clojure.contrib [math :as math])) > nil > user> (take 15 (let [n 3] (drop n (map #(math/abs (- (mod % (* n 2)) > n)) (range) > (0 1 2 3 2 1 0 1 2 3 2 1 0 1 2) > > -- > 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: Why can't I print new sequence?
On Wed, Aug 24, 2011 at 5:58 PM, octopusgrabbus wrote: > (defn f1 > [in-seq] > (loop [new-seq [] cur-seq in-seq] > (if (nil? (first cur-seq)) > new-seq > (if-not (nil? (x-in-seq (first cur-seq) new-seq)) > (recur (conj new-seq (first cur-seq)) (rest cur-seq)) You don't have a second branch for that last if, so the whole thing evaluates to nil if there are any duplicates, which there are. You need an else clause of (recur new-seq (rest cur-seq)). Or you could just use clojure.core/distinct :) -- Protege: What is this seething mass of parentheses?! Master: Your father's Lisp REPL. This is the language of a true hacker. Not as clumsy or random as C++; a language for a more civilized age. -- 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: Apply concat and mapcat evaluate seqs unnecessarily
On Wed, Aug 24, 2011 at 3:49 PM, Asim Jalis wrote: > I used "take 0" as a simple example to illustrate the problem. But in general > the standard mapcat evaluates terms than are needed. My f function does a web > call and processes the JSON records produced by this call, so each extra call > is a significant performance and resource hit. You may be able to wrap each web call in an explicit delay, and construct your lazy seq of these delays, then force the ones you actually want to use. Then the expensive JSON calls won't take place for any element until needed, no matter how far any of the sequence processing functions look ahead, as long as none of them will need to peek inside the delays until outside the problematic mapcat. (So, (mapcat (filter ...)) would be trouble, as the filter predicate may need to force the delays in the inner sequence, but (filter (mapcat ...)) should be ok unless filter is also looking ahead.) -- Protege: What is this seething mass of parentheses?! Master: Your father's Lisp REPL. This is the language of a true hacker. Not as clumsy or random as C++; a language for a more civilized age. -- 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
Seq of Numbers from 0 to N and Back
How can you generate a sequence of numbers from 0 to n and back? Here is my try. user> (require '(clojure.contrib [math :as math])) nil user> (take 15 (let [n 3] (drop n (map #(math/abs (- (mod % (* n 2)) n)) (range) (0 1 2 3 2 1 0 1 2 3 2 1 0 1 2) -- 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
Why can't I print new sequence?
I am probably missing something fundamental in the following example, which is trying to remove duplicates from a sequence. What am I doing wrong? I call it with (f1 d3). Thanks. cmn (ns test-csv (:gen-class) (:use clojure.contrib.command-line) (:require [clojure.contrib.string :as cstr]) (:use clojure-csv.core)) (def d3 [1 2 3 1 4 1 2]) (defn x-in-seq [x temp-seq] (if (nil? (some #(= x %) temp-seq)) x)) (defn f1 [in-seq] (loop [new-seq [] cur-seq in-seq] (if (nil? (first cur-seq)) new-seq (if-not (nil? (x-in-seq (first cur-seq) new-seq)) (recur (conj new-seq (first cur-seq)) (rest cur-seq)) -- 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: is there some gotchas with the contains? function and strings?
See the doc below. What (contains? [1 2] 1) is testing is whether [1 2] has a value at index 1 (the key value for numerically indexed collections). It does, so it returns true. What you are probably looking for is the Java method .contains of the vector: (.contains ["a" "b"] "a") ;=> true (.contains [1 2 5] 5) ;=> true user> (doc contains?) - clojure.core/contains? ([coll key]) Returns true if key is present in the given collection, otherwise returns false. Note that for numerically indexed collections like vectors and Java arrays, this tests if the numeric key is within the range of indexes. 'contains?' operates constant or logarithmic time; it will not perform a linear search for a value. See also 'some'. On Wed, Aug 24, 2011 at 4:57 PM, Andrew Xue wrote: > the below seems odd > > user=> (contains? [1 2] 1) > true > user=> (contains? ["a" "b"] "a") > false > > am i missing something? > > -- > 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: is there some gotchas with the contains? function and strings?
I believe contains? tests for the presence of a key in a collection: user> (contains? {:a 1 :b 2} 1) false user> (contains? {:a 1 :b 2} :a) true user> (get [0 2 3] 1) 2 user> (contains? [0 2 3] 1) true user> >From the docstring: "Returns true if key is present in the given collection, otherwise returns false. Note that for numerically indexed collections like vectors and Java arrays, this tests if the numeric key is within the range of indexes. 'contains?' operates constant or logarithmic time; it will not perform a linear search for a value. See also 'some'." U -- 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
is there some gotchas with the contains? function and strings?
the below seems odd user=> (contains? [1 2] 1) true user=> (contains? ["a" "b"] "a") false am i missing something? -- 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: online chapters of Practical Common Lisp
On Wed, 24 Aug 2011 09:31:53 -0700 (PDT) Vincent wrote: > will this online http://www.gigamonkeys.com/book/ > helpful in clojure/functional programming understanding... I'd recommend reading a Clojure book, though. There are some similarities between CL and Clojure, but it's not like there isn't a rich selection of books for Clojure :) regards, Marek -- 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
Michael Fogus will talk about ClojureScript tomorrow night (8/25)
If you're in the Washington DC area, and are interested in hearing about ClojureScript from Fogus, he'll be presenting at the CAPCLUG meeting tomorrow night http://www.meetup.com/Cap-Clug/events/16237174/. I believe his talk will be something about the compilation of ClojureScript to JavaScript, but maybe he can jump in and give details. See you there! Paul -- 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: Apply concat and mapcat evaluate seqs unnecessarily
I used "take 0" as a simple example to illustrate the problem. But in general the standard mapcat evaluates terms than are needed. My f function does a web call and processes the JSON records produced by this call, so each extra call is a significant performance and resource hit. On Aug 24, 2011, at 10:57 AM, Steve Miner wrote: > I'd be careful about writing my own version of mapcat. You might save a call > or two on the f function, but you'll probably lose in the general. Try some > experiments with larger take numbers. You might be better off concentrating > on your f function. I've found that trying to special-case degenerate cases > (for empty collections, etc.) has actually hurt my performance, presumably > because my cleverness got in the way of hotspot optimizations. > > > On Aug 22, 2011, at 10:32 AM, Asim Jalis wrote: > >> user=> (defn f [[x]] (println "computing x:" (inc x)) (vector (inc x))) >> #'user/f >> user=> (->> (iterate f [0]) (take 0)) >> () >> user=> (->> (iterate f [0]) (apply concat) (take 0)) >> computing x: 1 >> computing x: 2 >> computing x: 3 >> () >> user=> (->> (iterate f [0]) (mapcat identity) (take 0)) >> computing x: 1 >> computing x: 2 >> computing x: 3 >> () >> >> Is there a way to rewrite mapcat (or apply concat) so that they don't >> evaluate the incoming seq unnecessarily? >> >> -- >> 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: online chapters of Practical Common Lisp
> > will this online http://www.gigamonkeys.com/book/ > > helpful in clojure/functional programming understanding... > > That's an extremely good book and worth the read, but Common Lisp and > Clojure don't have a too big overlap, so it won't help you immediately > for getting started with Clojure or functional programming in general. > > There is a blog by Stuart Halloway where he ported the examples from CL to Clojure: http://thinkrelevance.com/blog/2008/09/16/pcl-clojure.html Have fun, Manuel -- 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: Apply concat and mapcat evaluate seqs unnecessarily
I'd be careful about writing my own version of mapcat. You might save a call or two on the f function, but you'll probably lose in the general. Try some experiments with larger take numbers. You might be better off concentrating on your f function. I've found that trying to special-case degenerate cases (for empty collections, etc.) has actually hurt my performance, presumably because my cleverness got in the way of hotspot optimizations. On Aug 22, 2011, at 10:32 AM, Asim Jalis wrote: > user=> (defn f [[x]] (println "computing x:" (inc x)) (vector (inc x))) > #'user/f > user=> (->> (iterate f [0]) (take 0)) > () > user=> (->> (iterate f [0]) (apply concat) (take 0)) > computing x: 1 > computing x: 2 > computing x: 3 > () > user=> (->> (iterate f [0]) (mapcat identity) (take 0)) > computing x: 1 > computing x: 2 > computing x: 3 > () > > Is there a way to rewrite mapcat (or apply concat) so that they don't > evaluate the incoming seq unnecessarily? > > -- > 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: about the lazy-seq
There's a pretty good explanation here: http://stackoverflow.com/questions/4992298/clojure-lazy-sequence-usage On Aug 23, 11:48 pm, xiaoguizi87 wrote: > I feel it is too difficult to understand the 'lazy-seq'.Can someone > recommend something may help me? I have goolge it, but found nothing > helpful. -- 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: online chapters of Practical Common Lisp
Vincent writes: Hi Vincent, > will this online http://www.gigamonkeys.com/book/ > helpful in clojure/functional programming understanding... That's an extremely good book and worth the read, but Common Lisp and Clojure don't have a too big overlap, so it won't help you immediately for getting started with Clojure or functional programming in general. Bye, Tassilo -- 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
online chapters of Practical Common Lisp
will this online http://www.gigamonkeys.com/book/ helpful in clojure/functional programming understanding... thanks vincent -- 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
about the lazy-seq
I feel it is too difficult to understand the 'lazy-seq'.Can someone recommend something may help me? I have goolge it, but found nothing helpful. -- 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: Peculiar transients behaviour
> Ticket is athttp://dev.clojure.org/jira/browse/CLJ-829 Thanks Alan, that's great! -- 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: Web Services with Clojure
You can have a look at Compojure [1], Noir[2], and Conjure[3], but if you want the "enterprise standard", you will probably need to wrap one of the Java frameworks that do that stuff well. [1] https://github.com/weavejester/compojure [2] https://github.com/ibdknox/noir [3] https://github.com/macourtney/Conjure - Mark On Wed, Aug 24, 2011 at 9:21 AM, Michael Jaaka wrote: > Beside this is there any framework for dynamic WebServices in clojure? > I would like to achive usage scenario like. > > (declare webservice with its details > (define method with signature of input output parameters types) > (define another method and so on)) > > > What is required from WS stack is ability to generate WSDL in runtime > programatically. > Attaching invocation handler to published end point. > The authentication and attachments could be made with threads vars. > > Do you know already such solution? > It would give good flexibility to the potential system. > > > The reference example usage scenario would look like: > > > (with-web-service { :wsdl "myservice.wsdl" > :url "http://someurl/"; > :name "myservice "} > > > (^String someQueryFunction[ ^String a ^List b ] > (str "Hello world " a (interpose ", " b))) > > > (^Map someQueryFunction[ ^Integer a ^Integer b ^Map m ] > (assoc m a (+ b (get m a > > > ) > > Any suggestions? RESTful seems to be how far the only options ;-( But > I would like to achieve enterprise standard. > > -- > 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
Web Services with Clojure
Beside this is there any framework for dynamic WebServices in clojure? I would like to achive usage scenario like. (declare webservice with its details (define method with signature of input output parameters types) (define another method and so on)) What is required from WS stack is ability to generate WSDL in runtime programatically. Attaching invocation handler to published end point. The authentication and attachments could be made with threads vars. Do you know already such solution? It would give good flexibility to the potential system. The reference example usage scenario would look like: (with-web-service { :wsdl "myservice.wsdl" :url "http://someurl/"; :name "myservice "} (^String someQueryFunction[ ^String a ^List b ] (str "Hello world " a (interpose ", " b))) (^Map someQueryFunction[ ^Integer a ^Integer b ^Map m ] (assoc m a (+ b (get m a ) Any suggestions? RESTful seems to be how far the only options ;-( But I would like to achieve enterprise standard. -- 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
Compojure
RESTFUL in Clojure? Hi I have found http://groups.google.com/group/clojure/browse_thread/thread/cfb2e5c29bb1337/92e2b8356a50189c?lnk=gst&q=web+services#92e2b8356a50189c But it doesn't work anymore. Anyone can point to fresh tutorial? Bye! -- 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: Peculiar transients behaviour
On Aug 24, 12:27 am, Alan Malloy wrote: > On Aug 23, 11:38 pm, Ken Wesson wrote: > > > What does zipmap do if the key seq contains duplications? > > That was my instinct too, but (a) a few thousand numbers won't collide > very often at all given the problem space, and (b) some experimenting > indicates that the key-seq is always 100k elements large - no > duplicates. > > HOWEVER, I did find the problem: the keys themselves don't collide, > but their hashes do. The number of elements that get messed up is > related to the number of hash collisions, but I still don't quite > understand how they interact. > > Here's a modified code snippet that demonstrates the issue: > > user> (let [m (apply zipmap (repeatedly 2 #(repeatedly 10 rand)))] > (println (count (distinct (map hash (keys m) > ((juxt count identity) (persistent! > (reduce dissoc! (transient m) (keys m) > 10 ;; no collisions > [0 {}] ;; map is empty at the end > > user> (let [m (apply zipmap (repeatedly 2 #(repeatedly 10 rand)))] > (println (count (distinct (map hash (keys m) > ((juxt count identity) (persistent! > (reduce dissoc! (transient m) (keys m) > 6 ;; four collisions > [8 {0.30426231137219917 0.8531183785687654, 0.8893047006425385 > 0.4788315896128895, 0.47854633997540674 0.45133768991797785, > 0.5265638224227486 0.7724779126227945}] ;; a four-element map that > reports its count as eight!!! > > That last comment seems to indicate a very serious error somewhere: > not only is the transient map broken, but it creates a broken > persistent object. I'll file a JIRA issue for this, and see if I can > find out any more about the cause. > > FWIW, I'm using 1.2.1 for the above output. Ticket is at http://dev.clojure.org/jira/browse/CLJ-829 -- 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: Recursion for nested comments
A somewhat related problem within all this: In the following code, the recursive call of comments-rendition-recur leads to the compile-time error "java.lang.Exception: Unable to resolve symbol: comments-rendition-recur in this context (views.clj:181)", unless I use declare. views.clj:181 is the last line of the comments-rendition-recur defn. What's going on, here? Code also on http://paste.pocoo.org/show/463499/ --- (defhtml comment-rendition [{:keys [index parent author link body created updated time-stamps css-class]} children] [:div.comment time-stamps [:div {:class (str "comment-body " css-class)} [:p.meta [:a.comment-anchor {:name index :href (str "#" index)} (str "#" index " ")] [:span.author [:a {:href link} author] ":"]] body children]]) (defhtml comment-new-level [] [:div {:class "hyphenate editable start-blank new-level"} "foo"]) (declare comments-rendition-recur) (defn comments-rendition-recur "Recurse for nested Comments." [comments] (cons ;; comments are [parent children] lists: (map #(let [c (first %) cs (rest %)] (apply comment-rendition (if (empty? cs) ;; Create one level deeper, just for ;; the reply field: [c (comment-new-level)] ;; Recurse to handle cs: [(into c (derive-time-stamps c)) (comments-rendition-recur cs)]))) comments) ;; Place comment field like a last sibling: (html [:div {:class "hyphenate editable start-blank end"} (-> comments last first :parent)]))) (defhtml comments-rendition [comments] [:div#comments [:h3 "Comments"] [:noscript [:p "Without JavaScript, you cannot add comments, here!"]] (comments-rendition-recur comments)]) (defhtml tree-rendition [{:keys [comments] :as all}] (article-rendition (into all (derive-time-stamps all))) (comments-rendition comments)) -- Thorsten Wilms thorwil's design for free software: http://thorwil.wordpress.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: Peculiar transients behaviour
On Aug 23, 11:38 pm, Ken Wesson wrote: > What does zipmap do if the key seq contains duplications? That was my instinct too, but (a) a few thousand numbers won't collide very often at all given the problem space, and (b) some experimenting indicates that the key-seq is always 100k elements large - no duplicates. HOWEVER, I did find the problem: the keys themselves don't collide, but their hashes do. The number of elements that get messed up is related to the number of hash collisions, but I still don't quite understand how they interact. Here's a modified code snippet that demonstrates the issue: user> (let [m (apply zipmap (repeatedly 2 #(repeatedly 10 rand)))] (println (count (distinct (map hash (keys m) ((juxt count identity) (persistent! (reduce dissoc! (transient m) (keys m) 10 ;; no collisions [0 {}] ;; map is empty at the end user> (let [m (apply zipmap (repeatedly 2 #(repeatedly 10 rand)))] (println (count (distinct (map hash (keys m) ((juxt count identity) (persistent! (reduce dissoc! (transient m) (keys m) 6 ;; four collisions [8 {0.30426231137219917 0.8531183785687654, 0.8893047006425385 0.4788315896128895, 0.47854633997540674 0.45133768991797785, 0.5265638224227486 0.7724779126227945}] ;; a four-element map that reports its count as eight!!! That last comment seems to indicate a very serious error somewhere: not only is the transient map broken, but it creates a broken persistent object. I'll file a JIRA issue for this, and see if I can find out any more about the cause. FWIW, I'm using 1.2.1 for the above output. -- 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