(con)current confusion
Hi all, I finished porting my model to clojure, and am now trying to get it to run concurrently. During the porting I already to care to wrap the main functions (birth [loc], death [loc] etc) in dosyncs, and all the slots in the world-vector are refs. I've the feeling those are all fine, and I am doing something wrong in starting the whole machinery. In the below code, I (hope that I) am sending off a list of instructions to each position in the world in such a way that the instructions can be processed concurrently. However, it seems like dotimes is waiting for the send-off agent to have finished before sending off another one. I think I know this because when I introduce side-effects (println) into the birth, death etc functions, the side-effects are fully in order both on the popsize level and within an agent. Can anyone tell me what mistake I am making? (time (do (dotimes i popsize (send-off (agent i) (doseq a [birth death infect infect evolve evolve evolve evolve evolve] (a i (println "We've send off the whole population") (dosync (commute year inc -> output of the model. trying evolution of 997 trying evolution of 997 trying evolution of 997 trying birth of 998 trying infection by 998 trying infection by 998 trying evolution of 998 trying evolution of 998 trying evolution of 998 trying evolution of 998 trying evolution of 998 trying birth of 999 trying infection by 999 trying infection by 999 trying evolution of 999 trying evolution --~--~-~--~~~---~--~~ 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 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: (con)current confusion
On Sun, Dec 14, 2008 at 5:48 AM, bOR_ wrote: > > Can anyone tell me what mistake I am making? > > (time > (do > (dotimes i popsize >(send-off (agent i) > (doseq a [birth death infect infect evolve > evolve evolve evolve evolve] (a i > (println "We've send off the whole population") > (dosync (commute year inc 'send-off' takes a function, not a block of code, so your 'doseq' does all its work in the main thread. Since 'doseq' always returns nil, that's the action you're sending to each agent. If you were maintaining a reference to each agent, you'd be able to dereference any of them and see it has errors: user=> (def x (agent nil)) #'user/x user=> @x nil user=> (send-off x nil) # user=> @x java.lang.Exception: Agent has errors (NO_SOURCE_FILE:0) --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 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: The return of the monads: lessons learned about macros
Jim, > I would make some minor changes in two places. I would write with- > monad as: Obviously this is a better version. > And I would write m-lift as I like that one as well. I have uploaded a new version that integrates your improvements. Another one is that the monad operations are now named functions (a feature I discovered by accident), which helps in debugging. > I've also modified my parser combinator monad and uploaded a new > version at: > > http://groups.google.com/group/clojure/web/monad-parser%20%282%29.clj That looks like a good opportunity to look at monadic parsers... Konrad. --~--~-~--~~~---~--~~ 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 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: (con)current confusion
Thanks! Needed only a small change then :) (time (do (dotimes i popsize (doseq a [birth death infect infect evolve evolve evolve evolve evolve] (send-off (agent i) a))) (dosync (commute year inc (report) --~--~-~--~~~---~--~~ 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 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: (con)current confusion
On Sun, Dec 14, 2008 at 8:49 AM, bOR_ wrote: > > Thanks! Needed only a small change then :) > > (time > (do > (dotimes i popsize >(doseq a [birth death infect infect evolve evolve evolve > evolve evolve] > (send-off (agent i) a))) > (dosync (commute year inc > (report) Note that you've now got popsize*9 agents, and the actions in your vector are not guaranteed to happen in order for any given 'i' -- I don't know if that matters to you or not. --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 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: (con)current confusion
The order doesn't matter, and a somewhat mixed order would even be a welcome side-effect of the whole concurrency bit. What does worry me is that the agents are very short-lived. The longest of these tasks takes 0.5msec (any evolution event), so I am not sure if spawning all these agents is worth the overhead. There are several other possibilities: I could have each place in the world be a single agent, which just continuously cycles through the events, even if there is no host occupying the place. I could also tie hosts to agents (which I think is somewhat like ant.clj does). Will look into it. On Dec 14, 2:55 pm, Chouser wrote: > On Sun, Dec 14, 2008 at 8:49 AM, bOR_ wrote: > > > Thanks! Needed only a small change then :) > > > (time > > (do > > (dotimes i popsize > > (doseq a [birth death infect infect evolve evolve evolve > > evolve evolve] > > (send-off (agent i) a))) > > (dosync (commute year inc > > (report) > > Note that you've now got popsize*9 agents, and the actions in your > vector are not guaranteed to happen in order for any given 'i' -- I > don't know if that matters to you or not. > > --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 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: DISCUSS: replace (rand)
On Saturday 13 December 2008 23:19, Mark H. wrote: > So I'm going to stop pretending like I'm an expert and actually post > some Clojure code. Be constructively critical 'cause I'm a n00b in > that regard ;-) This is a pseudorandom number generator for the > Gaussian (0,1) distribution. > > ... [ lots of unreadable stuff ] ... Why don't you send it as an attachment? > ... > > mfh Randall Schulz --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
test-is source
I see that the file clojure/contrib/test_clojure.clj does a "use" on clojure.contrib.test-is. That source file doesn't "use" anything else. Is the soure file clojure/contrib/test_is/test_is.clj used by anything or is it obsolete code? -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Fibonacci: Clojure vs the World
Hi, I'm just learning Clojure but I thought I would do a little experiment to see where Clojure sits performance-wise compared to a number of other languages on the old Fibonacci sequence. I think it handles itself quite well. The full writeup: http://www.mikeperham.com/2008/12/13/clojure-vs-ruby/ The results: Java 1.2 sec C (gcc 4.0.1) 2.6 sec Clojure 20080916 11.3 sec Ruby 1.9pr1 44.3 sec JRuby 1.1.5 118.1 sec Ruby 1.8.6 195.6 sec Java's native speed is outstanding and while Clojure adds some language overhead, the benefits of running on the JVM are obvious. 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 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: Fibonacci: Clojure vs the World
On Dec 14, 9:01 am, Mike Perham wrote: > Hi, I'm just learning Clojure but I thought I would do a little > experiment to see where Clojure sits performance-wise compared to a > number of other languages on the old Fibonacci sequence. I think it > handles itself quite well. > > The full writeup:http://www.mikeperham.com/2008/12/13/clojure-vs-ruby/ > > The results: > Java 1.2 sec > C (gcc 4.0.1) 2.6 sec > Clojure 20080916 11.3 sec > Ruby 1.9pr1 44.3 sec > JRuby 1.1.5 118.1 sec > Ruby 1.8.6 195.6 sec > > Java's native speed is outstanding and while Clojure adds some > language overhead, the benefits of running on the JVM are obvious. > In your article, you mentioned running "native" -- you should probably use Clojure's AOT to get a valid comparison. And provide type hints so that it uses the same numerical types to perform the computation -- by default, Clojure, like most other Lisps, have arbitrary-precision integers, and have to do BigInt conversion behind the scene. Chez Scheme 7.4 (Pentium 4 3.2 GHz, using only one thread) takes 12.134 s with a straight implementation of your code (and 0 ms with an iterative version), so on your machine, Clojure is performing decently. What's your exact set-up? (machine type, how the code is compiled, etc.) -- Michel --~--~-~--~~~---~--~~ 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 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: Bug in read-line?
I've not had time to look at the source yet, but want to note that the exception with Swank happens at r1158: r1158 | rhickey | 2008-12-12 21:37:12 -0500 (Fri, 12 Dec 2008) | 2 lines force instance member interpretation of (.method ClassName), e.g. (.getMethods String) works Any idea how this could break Swank? Reverting to r1157 (thank you, git-svn) fixed the problem for now. Thanks, -- Michel On Dec 13, 2:15 pm, "Stephen C. Gilardi" wrote: > I'm looking at the terminal case. It's the difference between running > clojure.lang.Repl and clojure.main (which runs a repl by default). The > reading done by the latter is intended to be identical to the reading > done by the former but isn't in the case of read-line. If anyone sees > the fix before I find it, please let me know. > > --Steve > > On Dec 13, 2008, at 10:57 AM, Michel Salim > wrote: > > > > > On Dec 13, 4:26 am, Michel Salim wrote: > >> Using up-to-date clojure and swank-clojure, I've not been able to use > >> read-line: > > >> - In Emacs (with Slime / swank-clojure), (read-line) never stops > >> consuming inputs > > >> - Running clojure directly from a terminal console, (read-line) > >> always > >> returns "" > > The terminal case, as it turns out, is what happens if I invoke > > clojure using java -jar clojure.jar instead of java -cp clojure.jar > > clojure.lang.Repl . Not sure what's causing the Swank problems though. > > > -- > > Michel --~--~-~--~~~---~--~~ 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 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: Functional programming newbie question
Ah, ok... I would have assumed that would be labeled as O(2n). Didn't realize that was rolled into the constant factor. So, when graphed, ANY linear function is O(n), no matter how "steep" the line is? Obviously I have some reading to do. Thanks for the clarification, -Luke On Dec 13, 6:35 pm, Randall R Schulz wrote: > On Saturday 13 December 2008 14:29, levand wrote: > > > > ... > > > > Calling reverse when done is still O(N) > > > Really? Maybe my grasp of big-O notation is faulty, but isn't the > > recursive function itself O(n), and then a reversal another O(n) > > operation on top of that, leading to two complete traversals of the > > source list? I thought it was impossible to do a reversal on a linked > > list in constant time. Or is the implementation actually doubly- > > linked? > > Any algorithm that requires to O(n) steps is itself O(n). The big-O > concept is roughly "equality up to a constant factor." > > > Thanks for the reply, Rich! I am really impressed by what you've done > > with Clojure. > > > -Luke > > Randall Schulz --~--~-~--~~~---~--~~ 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 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: Functional programming newbie question
yep. a function f(n) is O(n) if there are constants c and n0 such that f(n) <= c * n for all n >= n0. sometimes you do care about the c and the n0, though. On Sun, Dec 14, 2008 at 12:41 PM, levand wrote: > > Ah, ok... I would have assumed that would be labeled as O(2n). Didn't > realize that was rolled into the constant factor. So, when graphed, > ANY linear function is O(n), no matter how "steep" the line is? > > Obviously I have some reading to do. > > Thanks for the clarification, > -Luke > > On Dec 13, 6:35 pm, Randall R Schulz wrote: > > On Saturday 13 December 2008 14:29, levand wrote: > > > > > > ... > > > > > > Calling reverse when done is still O(N) > > > > > Really? Maybe my grasp of big-O notation is faulty, but isn't the > > > recursive function itself O(n), and then a reversal another O(n) > > > operation on top of that, leading to two complete traversals of the > > > source list? I thought it was impossible to do a reversal on a linked > > > list in constant time. Or is the implementation actually doubly- > > > linked? > > > > Any algorithm that requires to O(n) steps is itself O(n). The big-O > > concept is roughly "equality up to a constant factor." > > > > > Thanks for the reply, Rich! I am really impressed by what you've done > > > with Clojure. > > > > > -Luke > > > > Randall Schulz > > > --~--~-~--~~~---~--~~ 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 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: Fibonacci: Clojure vs the World
On Dec 14, 2:01 pm, Mike Perham wrote: > Hi, I'm just learning Clojure but I thought I would do a little > experiment to see where Clojure sits performance-wise compared to a > number of other languages on the old Fibonacci sequence. I think it > handles itself quite well. Interesting, but because your tests use a very inefficient algorithm, this is more a test of recursion than general performance. I find it quite intriguing that Java came out on top of GCC; I guess that must be Hotspot performing some optimizations. - James --~--~-~--~~~---~--~~ 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 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: Fibonacci: Clojure vs the World
On Sun, Dec 14, 2008 at 11:06 AM, Michel Salim wrote: > > > > On Dec 14, 9:01 am, Mike Perham wrote: >> Hi, I'm just learning Clojure but I thought I would do a little >> experiment to see where Clojure sits performance-wise compared to a >> number of other languages on the old Fibonacci sequence. I think it >> handles itself quite well. >> >> The full writeup:http://www.mikeperham.com/2008/12/13/clojure-vs-ruby/ >> >> The results: >> Java 1.2 sec >> C (gcc 4.0.1) 2.6 sec >> Clojure 20080916 11.3 sec >> Ruby 1.9pr1 44.3 sec >> JRuby 1.1.5 118.1 sec >> Ruby 1.8.6 195.6 sec >> >> Java's native speed is outstanding and while Clojure adds some >> language overhead, the benefits of running on the JVM are obvious. >> > In your article, you mentioned running "native" -- you should probably > use Clojure's AOT to get a valid comparison. AOT doesn't change the speed of code execution at all - code is always compiled to bytecode in Clojure. AOT just puts that bytecode on disk. 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 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 -~--~~~~--~~--~--~---
Bug in unchecked operations?
This follows from the recent micro-benchmarking discussion, though as it concerns a potential bug, I'm starting a new thread. With this (very inefficient) implementation of fib, (defn fib [n] (if (<= n 1) 1 (+ (fib (dec n)) (fib (- n 2) computing (fib 40) takes, give or take, 12 seconds on a Core 2 (2 GHz). Substituting unchecked-{add,dec,subtract} for +, dec and -, I've not been able to complete (fib 40). For (fib 20), the original takes 63 ms whereas the unchecked version takes 2215 ms. Que pasa? -- Michel --~--~-~--~~~---~--~~ 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 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: DISCUSS: replace (rand)
On 14.12.2008, at 08:19, Mark H. wrote: > So I'm going to stop pretending like I'm an expert and actually post > some Clojure code. Be constructively critical 'cause I'm a n00b in > that regard ;-) This is a pseudorandom number generator for the > Gaussian (0,1) distribution. ... Isn't that the standard Box-Muller transform? Anyway, I tried to rewrite your code into a function that takes an input stream of uniformly distributed random numbers and transforms it into a stream of Gaussian random numbers. The advantage is that there is no need to keep track explicitly of the state of the calculation. In the following, I construct my input stream by repeatedly calling Clojure's (rand), but you could easily substitute any other source, including java.Util.Random. Konrad. (defn rng-uniform "Return an infinite lazy sequence of random numbers" [] (drop 1 (iterate (fn [_] (rand)) nil))) (defn transform-to-gaussian "Transform a sequence of uniform random number in the interval [0, 1) into a sequence of Gaussian random numbers." [uniform-seq] (let [[U1 U2 & uniform-rest] uniform-seq V1 (- (* 2.0 U1) 1.0) V2 (- (* 2.0 U2) 1.0) S (+ (* V1 V1) (* V2 V2)) LS (. Math sqrt (/ (* -2.0 (. Math log S)) S)) X1 (* V1 LS) X2 (* V2 LS)] (if (or (>= S 1) (= S 0)) (recur uniform-rest) (lazy-cons X1 (lazy-cons X2 (transform-to-gaussian uniform- rest)) ; Get 10 Gaussian random numbers (take 10 (rng-gaussian)) --~--~-~--~~~---~--~~ 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 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: performance question
Nice code chouser, always nice to see a succinct functional example. On Dec 13, 10:15 am, Chouser wrote: > On Sat, Dec 13, 2008 at 10:41 AM, Dmitri wrote: > > > I wrote a simple word counter described herehttp://ptrace.fefe.de/wp/ > > it reads stdin and counts the occurrences of words, however I notice > > that it runs significantly slower than the java version in the link. > > There are several differences that could be factors. For example, the > Java version uses StreamTokenizer, while your Clojure version uses > String.split with a regex that gets recompiled for each line read. > > > I've also noticed that there is a significant speed difference between > > conj and assoc, why is that? > > If I understand correctly both should only create the delta of the new > > elements and the old structure, however assoc appears to perform much > > better. > > user=> (let [c 100 p [1 1]] (time (reduce #(conj % [%2 %2]) {} > (range c))) (time (reduce #(assoc % %2 %2) {} (range c))) nil) > "Elapsed time: 1544.180472 msecs" > "Elapsed time: 1894.318809 msecs" > nil > user=> (let [c 100 p [1 1]] (time (reduce #(conj % [%2 %2]) {} > (range c))) (time (reduce #(assoc % %2 %2) {} (range c))) nil) > "Elapsed time: 1549.159812 msecs" > "Elapsed time: 1594.18912 msecs" > > That's a million items added to a hash-map each way in about 1.5 > seconds -- not too shabby. And the speeds for conj vs. assoc seem > very close, though I'm actually seeing a slight advantage for conj. > > And I'm sorry for what follows -- it's like a compulsion for me, and I > hope it doesn't put you off. Each of these functions takes the same > input and produces the same output as your original code, but each is > implemented a bit more succinctly: > > (import '(java.io BufferedReader InputStreamReader)) > > (defn inc-count [words word] > (if (seq word) > (assoc words word (inc (words word 0))) > words)) > > (defn sort-words [words] > (reverse (sort (map (fn [[k v]] [v k]) words > > (defn print-words [words] > (doseq [head words] > (println head))) > > (defn read-words [words line] > (reduce inc-count words line)) > > (defn read-input [] > (with-open [buf (BufferedReader. (InputStreamReader. System/in))] > (let [words (for [line (line-seq buf)] (.split line " "))] > (print-words (sort-words (reduce read-words {} words)) > > (time (read-input)) > > --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 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: Fibonacci: Clojure vs the World
On Dec 14, 12:08 pm, James Reeves wrote: > On Dec 14, 2:01 pm, Mike Perham wrote: > > > Hi, I'm just learning Clojure but I thought I would do a little > > experiment to see where Clojure sits performance-wise compared to a > > number of other languages on the old Fibonacci sequence. I think it > > handles itself quite well. > > Interesting, but because your tests use a very inefficient algorithm, > this is more a test of recursion than general performance. I find it > quite intriguing that Java came out on top of GCC; I guess that must > be Hotspot performing some optimizations. > Mike did not give any compiler settings -- with gcc 4.3.2 and -O3 on 64-bit Linux, I get these results: [mic...@erdos fib]$ time ./a.out 165580141 real0m0.670s user0m0.668s sys 0m0.001s [mic...@erdos fib]$ time ./a.out 165580141 real0m0.677s user0m0.675s sys 0m0.001s [mic...@erdos fib]$ time ./a.out 165580141 real0m0.673s user0m0.669s sys 0m0.001s And with Java, [mic...@erdos fib]$ java Fib time taken: 1279, res=165580141 [mic...@erdos fib]$ java Fib time taken: 1369, res=165580141 [mic...@erdos fib]$ java Fib time taken: 1276, res=165580141 And to demonstrate that Java is not the only fast JVM language: [mic...@erdos bin]$ scala testing.Fib time taken: 1292, res=165580141 [mic...@erdos bin]$ scala testing.Fib time taken: 1246, res=165580141 [mic...@erdos bin]$ scala testing.Fib time taken: 1264, res=165580141 -- Michel --~--~-~--~~~---~--~~ 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 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: Functional programming newbie question
On Sunday 14 December 2008 09:00, harrison clarke wrote: > yep. a function f(n) is O(n) if there are constants c and n0 such > that f(n) <= c * n for all n >= n0. > > sometimes you do care about the c and the n0, though. To be sure. And there can be times that, for the problem size you know you need to handle, an algorithm with better asymptotic behavior is beat by one with worse asymptotic behavior just because of the constant factors in the execution of the "inferior" algorithm. But overall, there are distinctly fewer cases where you don't care about the asymptotic order of the algorithm: linear vs. polynomial; polynomial of degree n vs. polynomial of degree m > n; polynomial vs. exponential; and so on. I seem to recall hearing of a polynomial-time factoring algorithm that was discovered a few years ago. But the degree of the polynomial was something insane: many tens, if I remember correctly. Randall Schulz --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Proxy mappings now use strings for keys - deliberate?
I've notice that the latest builds of Clojure now use strings for keys in proxy mappings, whilst in the past they used to use symbols. Was this change deliberate? - James --~--~-~--~~~---~--~~ 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 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: Proxy mappings now use strings for keys - deliberate?
On Sunday 14 December 2008 10:40, James Reeves wrote: > I've notice that the latest builds of Clojure now use strings for > keys in proxy mappings, whilst in the past they used to use symbols. > Was this change deliberate? Yes. Rich pointed this out in the SVN commit commentary for 1159: "proxy perf tweaks Note breaking change if you are using the proxy interface other than the proxy macro itself - proxy maps are now maps of (preferably interned) strings to fns, not symbols to fns, and if you construct a proxy manually you must establish initial map with init-proxy" (Thanks to mehrheit on #clojure for the help with clojurebot's syntax for looking SVN commit messages.) > - James Randall Schulz --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Emtpy (filter ...) Result Yields nil; Could / Should It Be An Empty List?
Hi, I ran into a special case that I'd like to avoid. When (filter ...) is either applied to an empty collection or the filter predicate returns false for all the elements in the supplied collection, filter returns nil. Would it be acceptable and desirable for it to return and empty list in this case? Randall Schulz --~--~-~--~~~---~--~~ 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 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 interop question
work> (.getName (.getClass 0)) "java.lang.Integer" work> (.getName java.lang.Integer) ; Evaluation aborted. Why does the second expression fail? --~--~-~--~~~---~--~~ 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 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: Emtpy (filter ...) Result Yields nil; Could / Should It Be An Empty List?
On Sunday 14 December 2008 11:08, Randall R Schulz wrote: > Hi, > > I ran into a special case that I'd like to avoid. When (filter ...) > is either applied to an empty collection or the filter predicate > returns false for all the elements in the supplied collection, filter > returns nil. > > Would it be acceptable and desirable for it to return and empty list > in this case? To make the case concrete and possibly get a suggestion of a better way to deal with the situation I encountered, here the function that ran into the "nil return from (filter ...)" condition. It uses (flatten ...) from clojure.contrib.seq-utils: This was my original function. It return [nil] when no matching slots are found: (defn- gather-slot-values "Extract all the values paired with the specified key; returns a vector of flattened values" [slot-key c-pairs] (into [] (flatten (map #(second %) (filter #(= (first %) slot-key) c-pairs ) Here's how I modified it so it returns [] in that case: (defn- gather-slot-values "Extract all the values paired with the specified key; returns a vector of flattened values" [slot-key c-pairs] (let [filtered (filter #(= (first %) slot-key) c-pairs)] (if filtered (into [] (flatten (map #(second %) filtered))) [])) ) --~--~-~--~~~---~--~~ 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 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 interop question
--- On Sun, 12/14/08, David wrote: > work> (.getName java.lang.Integer) > ; Evaluation aborted. > > Why does the second expression fail? Would that work in Java? 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 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: Emtpy (filter ...) Result Yields nil; Could / Should It Be An Empty List?
On Dec 14, 2:08 pm, Randall R Schulz wrote: > Hi, > > I ran into a special case that I'd like to avoid. When (filter ...) is > either applied to an empty collection or the filter predicate returns > false for all the elements in the supplied collection, filter returns > nil. > > Would it be acceptable and desirable for it to return and empty list in > this case? > No. The seq protocol says either there is a sequence of at least one thing, or no sequence - nil. There is no such thing as an empty seq, and no reason sequence functions should start returning empty collections of any type. 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 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: Fibonacci: Clojure vs the World
More detail: I'm on a MBP with 2.2Ghz Core 2 Duo. I used Apple's standard GCC 4.0.1 to compile with no settings (gcc fib.c -o fib). The same code with Apple's GCC 4.2 produced the same time, I didn't think to use an optimization flag as I haven't written C in a decade. It looks like Michael's results with O3 and gcc 4.3 are pretty impressive. As noted in the comments for my blog post, type hints and unchecked math operations shave about 40% off the runtime. mike On Dec 14, 11:08 am, James Reeves wrote: > On Dec 14, 2:01 pm, Mike Perham wrote: > > > Hi, I'm just learning Clojure but I thought I would do a little > > experiment to see where Clojure sits performance-wise compared to a > > number of other languages on the old Fibonacci sequence. I think it > > handles itself quite well. > > Interesting, but because your tests use a very inefficient algorithm, > this is more a test of recursion than general performance. I find it > quite intriguing that Java came out on top of GCC; I guess that must > be Hotspot performing some optimizations. > > - James --~--~-~--~~~---~--~~ 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 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 interop question
On Dec 14, 2:26 pm, David wrote: > work> (.getName (.getClass 0)) > "java.lang.Integer" > > work> (.getName java.lang.Integer) > ; Evaluation aborted. > > Why does the second expression fail? There used to be a long answer as to why: http://groups.google.com/group/clojure/msg/8fc6f0e9a5800e4b Now there is a short one - it does work! (.getName java.lang.Integer) -> "java.lang.Integer" As of Revision #1158 Committed by rhickey at 12/12/08 9:37:12 PM force instance member interpretation of (.method ClassName), e.g. (.getMethods String) works 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 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: Emtpy (filter ...) Result Yields nil; Could / Should It Be An Empty List?
When IS an appropriate time to use '()? It's in the language, so I assume there must be at least one good use case. Recently, I was writing a function that yields a sequence of all the subsequences of a given sequence, e.g., (subseqs '(1 2 3)) -> (nil (1) (2) (3) (1 2) (1 3) (2 3) (1 2 3)) I had a very hard time deciding whether nil or '() belonged there (eventually I decided on nil). --~--~-~--~~~---~--~~ 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 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 interop question
Sneaky, but I bet I'll get confused by the extra functionality at some point. --- On Sun, 12/14/08, Rich Hickey wrote: > There used to be a long answer as to why: > > http://groups.google.com/group/clojure/msg/8fc6f0e9a5800e4b > > Now there is a short one - it does work! --~--~-~--~~~---~--~~ 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 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: Emtpy (filter ...) Result Yields nil; Could / Should It Be An Empty List?
On Sunday 14 December 2008 11:08, Randall R Schulz wrote: > ... It turns out that flatten (from clojure.contrib.seq-utils) is really where I go wrong with my simple version of gather-slot-values. Does this makes sense (specifically the last one)? user=> (flatten []) nil user=> (flatten ()) nil user=> (flatten nil) (nil) Randall Schulz --~--~-~--~~~---~--~~ 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 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: Bug in unchecked operations?
My mistake; unchecked operations work just fine if their arguments (including constants) are given type hints. What happens if unchecked- add/sub/... is given an argument of unknown type, though? It still seems to work, though slowly. On Dec 14, 12:35 pm, Michel Salim wrote: > This follows from the recent micro-benchmarking discussion, though as > it concerns a potential bug, I'm starting a new thread. > > With this (very inefficient) implementation of fib, > > (defn fib [n] > (if (<= n 1) > 1 > (+ (fib (dec n)) (fib (- n 2) > > computing (fib 40) takes, give or take, 12 seconds on a Core 2 (2 > GHz). > > Substituting unchecked-{add,dec,subtract} for +, dec and -, I've not > been able to complete (fib 40). For (fib 20), the original takes 63 ms > whereas the unchecked version takes 2215 ms. > > Que pasa? > > -- > Michel --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Move to Eclipse Public License
I've moved the codebase to the Eclipse Public License as of SVN 1160: http://opensource.org/licenses/eclipse-1.0.php EPL is the successor to CPL, and acceptable to Google Code and others. It allows all the same usages as did CPL, is commercial friendly etc. Contrib should move over ASAP. Thanks, 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 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: Proxy mappings now use strings for keys - deliberate?
On Dec 14, 6:57 pm, Randall R Schulz wrote: > Yes. Rich pointed this out in the SVN commit commentary for 1159: Ah, somehow I managed to miss that message! I should really pay closer attention. - James --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Set union weirdness
So I have some code that looks somewhat like: (update-in node [:index :x] set/union #{:y}) This seems fine as long as there's already a set in the desired spot. However, since update-in will kindly build the map structure for you if it doesn't already exist, I figured it would be nice not to have to check for nils and replace them with empty sets. So I tried this: => (set/union nil #{:foo}) (:foo) Huh? I checked its class, and it is indeed a list. So I tried: => (set/union '(1 2 3 a) '(a b c)) (c b a 1 2 3 a) => (set/union [0 1 2 3] [0]) [0 1 2 3 0] Looking at the source explains this: (defn union "Returns a set that is the union of the two sets." [xset yset] (reduce conj xset yset)) I don't know if this (and any similar weirdness in the rest of the set namespace) should be fixed since you aren't really supposed to throw non-sets in there, but I do think a special case for nil might be nice here. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
learning about AOT
I'm trying AOT compilation for the first time. Here's what I did. - created the directory com/ociweb below my current directory - created the source file math.clj with the following content (ns com.ociweb.math) (defn fib [n] (reduce * (range 2 (inc n - started a REPL in the current directory - entered (load "com/ociweb/math") - entered (com.ociweb.math/fib 5) to verify that it works - tried to compile it with (compile 'com.ociweb.math), but got java.lang.RuntimeException: java.lang.ClassNotFoundException: com.ociweb.math$fib__193 (NO_SOURCE_FILE:0) I have . in my classpath. Any idea what I'm doing wrong? -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Multimethod dispatch on one or more specific arguments
How to dispatch on specific argument(s) of a function? example: (defmulti group ) (defmethod group ??? [xs n] (loop [acc nil x xs] (if (not x) (reverse acc) (recur (cons (take n x) acc) (drop n x) Here I want to dispatch on the class of the first argument xs. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Problems with "gen-and-load-class" (defn user-exception-test [] (try (throw (new user.UserException "msg: user exception was here!!")) (catch user.UserException e (prn "caught excep
Hello. I am having problems with "gen-and-load-class". I have a file with an example from the wiki book: (gen-and-load-class 'user.UserException :extends Exception) (defn user-exception-test [] (try (throw (new user.UserException "msg: user exception was here!!")) (catch user.UserException e (prn "caught exception" e)) (finally (prn "finally clause invoked!!!" But when I load it, I get the message "java.lang.Exception: Unable to resolve symbol: gen-and-load-class in this context (throwException.clj: 1)". I have tried to load the file "clojure-path/classes/clojure/ genclass.clj" but I still cannot use "gen-and-load-class". Can anyone help? - Tommy --~--~-~--~~~---~--~~ 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 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: learning about AOT
Mark Volkmann wrote: > I'm trying AOT compilation for the first time. Here's what I did. > > - created the directory com/ociweb below my current directory > - created the source file math.clj with the following content > > (ns com.ociweb.math) > (defn fib [n] (reduce * (range 2 (inc n > > - started a REPL in the current directory > - entered (load "com/ociweb/math") > - entered (com.ociweb.math/fib 5) to verify that it works > - tried to compile it with (compile 'com.ociweb.math), but got > java.lang.RuntimeException: java.lang.ClassNotFoundException: > com.ociweb.math$fib__193 (NO_SOURCE_FILE:0) > > I have . in my classpath. Any idea what I'm doing wrong? > Your classpath does not contain the folder to the .clj file. See this example, with detailed explanations on classpath for compiling and then running gen-class generated classes: http://pacific.mpi-cbg.de/wiki/index.php/Clojure_Scripting#Generating_java_classes_in_.class_files_from_clojure_code Albert -- Albert Cardona http://albert.rierol.net --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Clojure classes graph (was chart.png)
I've updated the Clojure classes graph (thanks for the push, R. Schulz!) The new version includes the newest classes as well as Java interfaces that are applicable. These latter are shown inside diamonds. A couple different .svg and .png versions are available here, along with the code used to create them: http://github.com/Chouser/clojure-classes/tree/master For a quick link to the main graphic, you can use: http://tinyurl.com/clojure-classes I won't be maintaining the chart.png in the file upload area of this group, since it's much easier to just push new versions to the github repo. There you can also find older versions, other formats, etc. --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 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: Multimethod dispatch on one or more specific arguments
I had some trouble understanding this at first too. "Here I want to dispatch on the class of the first argument xs. " on the first aargument, ie xs, or on the first argument of xs? This should work: (defmulti group (fn [xs n] (class xs))) (defmulti group (fn [xs n] (class (first xs (defmethod group dispatch-type [xs 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 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: Patch: precompiling Clojure core sources in Ant build script
Hi, Looks like patch is already applied, but i now i get following error after "M-." java.lang.IllegalArgumentException: No matching field found: separator for class java.lang.Class (NO_SOURCE_FILE:0) [Thrown class clojure.lang.Compiler$CompilerException] I updated everything clojure related - clojure itself, swank-clojure, clojure-mode, slime, clojure-contrib, but i still get that error. Before update "M-." did work. Kunnar On Dec 11, 7:04 am, "Bill Clementson" wrote: > Hi Matt, > > FYI - Jeffrey Chu just sent me an email and the patch has now been > applied to swank-clojure. > > - Bill > > On Wed, Dec 10, 2008 at 1:09 PM, Bill Clementson wrote: > > Hi Matt, > > > On Wed, Dec 10, 2008 at 12:47 PM, MattyDub wrote: > > >> I can confirm that that patch fixed my problem - I can now M-. to > >> render-place. Thanks, Bill! > > > Good to hear that the patch fixes the issue for you. > > >> What paths doesslime-edit-definitionsearch for the definitions? > >> It's not finding the clojure macros/functions (like defn, dosync, > >> etc.), so I must not have that path configured correctly. > >> -Matt > > > Basically, it searches a bunch of standard Java locations plus the > > locations you specified in your classpath. If you want to see what > > will be searched, enter the following 2 statements in your Clojure > > REPL: > > (in-ns 'swank.commands.basic) > > (slime-search-paths) > > > Note: the function "slime-search-paths" isn't public > > > If M-. isn't working on standard Clojure symbols, it could be for a > > number of reasons: > > 1. You're using an old version of Clojure > > 2. You've built Clojure excluding source from the jar file > > 3. The Clojure source isn't in your classpath (only necessary if #2 is true) > > > - Bill > > --~--~-~--~~~---~--~~ 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 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: (con)current confusion
Ok.. seems like the short lifespan of the agent-threads makes it hard for the program to actually start using its (in this case 2) multiple cpu's. The next program has no problem filling both cpu's together for 199% (top, linux), whilst the simulation has trouble getting above 110%, but occasionally jumps higher to up to 199%. I'll go and build a version in which the agents are kept alive and useful longer. (defn fib [n] (reduce * (range 2 (inc n (defn doublesend [] (do (def myagent (agent 10)) (def myagent2 (agent 10)) (send-off myagent fib) (send-off myagent2 fib) )) (doublesend) On Dec 14, 3:07 pm, bOR_ wrote: > The order doesn't matter, and a somewhat mixed order would even be a > welcome side-effect of the whole concurrency bit. > > What does worry me is that the agents are very short-lived. The > longest of these tasks takes 0.5msec (any evolution event), so I am > not sure if spawning all these agents is worth the overhead. > > There are several other possibilities: I could have each place in the > world be a single agent, which just continuously cycles through the > events, even if there is > no host occupying the place. I could also tie hosts to agents (which I > think is somewhat like ant.clj does). Will look into it. > > On Dec 14, 2:55 pm, Chouser wrote: > > > On Sun, Dec 14, 2008 at 8:49 AM, bOR_ wrote: > > > > Thanks! Needed only a small change then :) > > > > (time > > > (do > > > (dotimes i popsize > > > (doseq a [birth death infect infect evolve evolve evolve > > > evolve evolve] > > > (send-off (agent i) a))) > > > (dosync (commute year inc > > > (report) > > > Note that you've now got popsize*9 agents, and the actions in your > > vector are not guaranteed to happen in order for any given 'i' -- I > > don't know if that matters to you or not. > > > --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 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: The return of the monads: lessons learned about macros
Konrad, I did some more work from the paper the parser combinator is based on. From that I built what I think is a state monad transformer: (defn stateT [m] (monad [m-result (fn [v] (fn [s] ((:m-result m) (list v s m-bind (fn [stm f] (fn [s] ((:m-bind m) (stm s) (fn [[v ss]] ((f v) ss) m-zero (when (:m-zero m) (fn [s] (:m-zero m))) m-plus (when (:m-plus m) (fn [& stms] (fn [s] (apply (:m-plus m) (map #(% s) stms) ])) This function takes a monad and wraps it inside a state monad, producing a new monad with a combination of characteristics from both. I also rewrote the maybe monad as: (defmonad maybe "Monad describing computations with possible failures. Failure is represented by an empty vector, success by a vector with a single element, the resulting value." [m-zero [] m-result (fn [v] [v]) m-bind (fn [vs f] (into [] (mapcat f vs))) m-plus (fn [& mvs] (let [first-valid (first (drop-while empty? mvs))] (if (nil? first-valid) m-zero first-valid))) ]) (notice the change to the bind function). This let me write the parser monad as: (def parser-m (stateT maybe)) If that stateT function isn't actually a monad transformer, it still is a slick way of combining the two monads. 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 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: The return of the monads: lessons learned about macros
Also, I came across set-state and fetch-state being implemented in terms of update-state. (defn set-state [s] (update-state (fn [x] s))) (defn fetch-state [] (update-state identity)) 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 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: Patch: precompiling Clojure core sources in Ant build script
This is due to the change in clojure svn 1158. (.method ClassName ...) syntax has been changed to call java.lang.Class method for ClassName, not static field/method any more. Use namespace syntax instead. diff --git a/swank/commands/basic.clj b/swank/commands/basic.clj index ac0736f..4705cd5 100644 --- a/swank/commands/basic.clj +++ b/swank/commands/basic.clj @@ -273,7 +273,7 @@ (when-let [meta (and sym-var (meta sym-var))] (if-let [path (or (slime-find-file-in-paths (:file meta) (slime- search-paths)) (slime-find-file-in-paths (str (namespace-to- path (:ns meta)) - (.separator File) + File/separator (:file meta)) (slime-search-paths)) `((~(str "(defn " (:name meta) ")") (:location diff --git a/swank/util/io.clj b/swank/util/io.clj index 56b037e..48fd5b8 100644 --- a/swank/util/io.clj +++ b/swank/util/io.clj @@ -28,7 +28,7 @@ (dothread (thread-set-name "Call-on-write Stream") (continuously - (.sleep Thread 200) + (Thread/sleep 200) (when-not @closed? (.flush stream On Dec 14, 4:41 pm, kunnar wrote: > Hi, > > Looks like patch is already applied, but i now i get following error > after "M-." > > java.lang.IllegalArgumentException: No matching field found: separator > for class java.lang.Class (NO_SOURCE_FILE:0) > [Thrown class clojure.lang.Compiler$CompilerException] > > I updated everything clojure related - clojure itself, swank-clojure, > clojure-mode, slime, clojure-contrib, but i still get that error. > Before update "M-." did work. > > Kunnar > > On Dec 11, 7:04 am, "Bill Clementson" wrote: > > > Hi Matt, > > > FYI - Jeffrey Chu just sent me an email and the patch has now been > > applied to swank-clojure. > > > - Bill > > > On Wed, Dec 10, 2008 at 1:09 PM, Bill Clementson wrote: > > > Hi Matt, > > > > On Wed, Dec 10, 2008 at 12:47 PM, MattyDub wrote: > > > >> I can confirm that that patch fixed my problem - I can now M-. to > > >> render-place. Thanks, Bill! > > > > Good to hear that the patch fixes the issue for you. > > > >> What paths doesslime-edit-definitionsearch for the definitions? > > >> It's not finding the clojure macros/functions (like defn, dosync, > > >> etc.), so I must not have that path configured correctly. > > >> -Matt > > > > Basically, it searches a bunch of standard Java locations plus the > > > locations you specified in your classpath. If you want to see what > > > will be searched, enter the following 2 statements in your Clojure > > > REPL: > > > (in-ns 'swank.commands.basic) > > > (slime-search-paths) > > > > Note: the function "slime-search-paths" isn't public > > > > If M-. isn't working on standard Clojure symbols, it could be for a > > > number of reasons: > > > 1. You're using an old version of Clojure > > > 2. You've built Clojure excluding source from the jar file > > > 3. The Clojure source isn't in your classpath (only necessary if #2 is > > > true) > > > > - Bill --~--~-~--~~~---~--~~ 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 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: learning about AOT
On Sun, Dec 14, 2008 at 3:45 PM, Albert Cardona wrote: > > Mark Volkmann wrote: >> I'm trying AOT compilation for the first time. Here's what I did. >> >> - created the directory com/ociweb below my current directory >> - created the source file math.clj with the following content >> >> (ns com.ociweb.math) >> (defn fib [n] (reduce * (range 2 (inc n >> >> - started a REPL in the current directory >> - entered (load "com/ociweb/math") >> - entered (com.ociweb.math/fib 5) to verify that it works >> - tried to compile it with (compile 'com.ociweb.math), but got >> java.lang.RuntimeException: java.lang.ClassNotFoundException: >> com.ociweb.math$fib__193 (NO_SOURCE_FILE:0) >> >> I have . in my classpath. Any idea what I'm doing wrong? >> > > > Your classpath does not contain the folder to the .clj file. > > See this example, with detailed explanations on classpath for compiling > and then running gen-class generated classes: > > http://pacific.mpi-cbg.de/wiki/index.php/Clojure_Scripting#Generating_java_classes_in_.class_files_from_clojure_code Wow, that's a lot of things that have to be in the classpath! In your example the namespace is fj.tests.process. You say the classpath must contain: 1) the "fj" directory 2) the "process" directory 3) the "classes" directory where the .class files will be written I would have guessed I'd only need the directory that contains the fj directory in the classpath and that it would find the fj and process directories from there. I understand why I'd need the classes directory in the classpath when I'm ready to use the .class file, but why do I need it when I'm only compiling the .clj source file? -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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 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: DISCUSS: replace (rand)
On Dec 14, 6:09 am, Randall R Schulz wrote: > On Saturday 13 December 2008 23:19, Mark H. wrote: > > > So I'm going to stop pretending like I'm an expert and actually post > > some Clojure code. Be constructively critical 'cause I'm a n00b in > > that regard ;-) This is a pseudorandom number generator for the > > Gaussian (0,1) distribution. > > > ... [ lots of unreadable stuff ] ... > > Why don't you send it as an attachment? Haha, wow, it is completely unreadable ;-) Konrad's solution is way more elegant than mine so I'll omit attaching the whole thing. The test might be useful though. mfh --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Best Choice of Java Class For *out*
Hi, I have quite a bit of Java code with I/O capabilities that generally support both PrintStream and PrintWriter. I was a bit perplexed when I tried to apply one of these methods to *out* and was rebuffed thusly: java.lang.IllegalArgumentException: No matching method found: printMessage for class rrs.util.ErrorRecord As Rich then pointed out to me on #clojure, the problem is that the concrete type of *out* is: user=> (class *out*) java.io.OutputStreamWriter This leaves almost all of my system's I/O primitives high and dry. What might be the issues or consequences of making the root binding of *out* a PrintWriter? Randall Schulz --~--~-~--~~~---~--~~ 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 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: DISCUSS: replace (rand)
On Dec 14, 9:40 am, Konrad Hinsen wrote: > Isn't that the standard Box-Muller transform? Ah, yes, now I know what to call it ;-) Yes, it's a particular implementation of the Box-Muller transform that is designed to avoid trig functions. http://en.wikipedia.org/wiki/Marsaglia_polar_method > (defn transform-to-gaussian > "Transform a sequence of uniform random number in the interval [0, 1) > into a sequence of Gaussian random numbers." > [uniform-seq] > (let [[U1 U2 & uniform-rest] uniform-seq Yes, much better ;-) > (lazy-cons X1 (lazy-cons X2 (transform-to-gaussian uniform- > rest)) Also much better -- the structs were ugly. Thanks for the nice revision! Do you think type hints on the double-floats could give some performance benefit? I'm curious where the type hints would go but too lazy to try the "add them everywhere and remove one by one until performance decreases" approach. mfh --~--~-~--~~~---~--~~ 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 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: test-is source
On Sun, Dec 14, 2008 at 9:18 AM, Mark Volkmann wrote: > > I see that the file clojure/contrib/test_clojure.clj does a "use" on > clojure.contrib.test-is. > That source file doesn't "use" anything else. > Is the soure file clojure/contrib/test_is/test_is.clj used by anything > or is it obsolete code? It's obsolete and has been removed from the latest version of clojure-contrib. See clojure/contrib/test_is.clj for the latest version of that lib. --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 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: Emtpy (filter ...) Result Yields nil; Could / Should It Be An Empty List?
On Dec 14, 3:16 pm, Randall R Schulz wrote: > Does this makes sense (specifically the last one)? > > user=> (flatten []) > nil > > user=> (flatten ()) > nil > Yes; the empty sequence is just nil. > user=> (flatten nil) > (nil) > That does look like a bug. -- Michel --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Acceptable Arguments to Two-Argument (symbol ...)
Hi, The doc text for symbol is: user=> (doc symbol) - clojure.core/symbol ([name] [ns name]) Returns a Symbol with the given namespace and name. However, the "ns" argument must be a String, not a namespace. Would it be reasonable to allow an actual namespace as the ns argument to (symbol ns name)? If not, the doc string should at least emphasize that two String arguments are required. Randall Schulz --~--~-~--~~~---~--~~ 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 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: DISCUSS: replace (rand)
On 14.12.2008, at 18:40, Konrad Hinsen wrote: > (defn rng-uniform >"Return an infinite lazy sequence of random numbers" >[] >(drop 1 (iterate (fn [_] (rand)) nil))) > > (defn transform-to-gaussian >"Transform a sequence of uniform random number in the interval > [0, 1) > into a sequence of Gaussian random numbers." >[uniform-seq] >(let [[U1 U2 & uniform-rest] uniform-seq > V1 (- (* 2.0 U1) 1.0) > V2 (- (* 2.0 U2) 1.0) > S (+ (* V1 V1) (* V2 V2)) > LS (. Math sqrt (/ (* -2.0 (. Math log S)) S)) > X1 (* V1 LS) > X2 (* V2 LS)] > (if (or (>= S 1) (= S 0)) >(recur uniform-rest) >(lazy-cons X1 (lazy-cons X2 (transform-to-gaussian uniform- > rest)) I forgot to copy one part: (defn rng-gaussian [] (transform-to-gaussian (rng-uniform))) > ; Get 10 Gaussian random numbers > (take 10 (rng-gaussian)) --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
On Lisp - porting problem
I am porting some examples from Paul Graham's "On Lisp" book. I have a problem with this one (fig 5. 4 page 67): (defun fif (if then &optional else) #'(lambda (x) (if (funcall if x) (funcall then x) (if else (funcall else x) My implementation: (defn fif [iff then & else] (fn [x] (if (iff x) (then x) (if else ((first else) x) When running: (map #(fif even? (fn [x] (* 2 x))) [3 4]) I got: java.lang.IllegalArgumentException: Wrong number of args passed to: user$eval--5905$fn I don't see where the number of parameters is wrong. --~--~-~--~~~---~--~~ 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 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: On Lisp - porting problem
#(fif even? (fn [x] (* 2 x))) has no % sign in it, so it is a function of zero arguments, which is not something that map can use. --~--~-~--~~~---~--~~ 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 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: Problem with XML attributes and HTML entities
On Sat, Dec 13, 2008 at 10:59 PM, Wayne R wrote: > > I've got an issue where the clojure.xml/parse and /emit functions are > not symmetric with respect to how attributes are read and written. > The parser decodes HTML entities (e.g. & -> &) however the emitter > does not re-encode them: Good catch. I've added a fix to clojure.contrib.lazy-xml (svn 300), but the issue is still open for clojure.xml --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 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: On Lisp - porting problem
> (map #(fif even? (fn [x] (* 2 x))) [3 4]) Your fif returns a function. So probably what you wanted to do was: user=> (map (fif even? (fn [x] (* 2 x))) [3 4]) (nil 8) fif is returning an unnamed function which accepts one argument and can thus be mapped to [3 4] #(...) creates an unnamed function, in your case it was creating a function with no arguments. So to use that syntax correctly you might do: (map #(if (even? %1) (* 2 %1)) [3 4]) The point of fif is to simplify the above, though I guess for this example it actually makes it longer :) You could have written fif as (defn fif [iff then & else] #(if (iff %1) (then %1) (if else ((first else) %1 Regards, Tim. --~--~-~--~~~---~--~~ 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 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: On Lisp - porting problem
Just thought of a better comparison: (map (fif even? #(* 2 %1)) [3 4]) is indeed shorter than: (map #(if (even? %1) (* 2 %1)) [3 4]) Regards, Tim. --~--~-~--~~~---~--~~ 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 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: Emtpy (filter ...) Result Yields nil; Could / Should It Be An Empty List?
> user=> (flatten nil) > (nil) Not a bug. flatten returns a sequence - in this case a sequence containing 'nil. How else would you flatten on nil? In the former cases the flatten returns the seq - nil Can Clojure return an empty sequence otherwise? (def x ()) (first x) => nil (def y x) y => nil user> (def y x) #'user/y user> y nil user> (flatten y) (nil) On Dec 14, 9:16 pm, Michel Salim wrote: > On Dec 14, 3:16 pm, Randall R Schulz wrote: > > > Does this makes sense (specifically the last one)? > > > user=> (flatten []) > > nil > > > user=> (flatten ()) > > nil > > Yes; the empty sequence is just nil. > > > user=> (flatten nil) > > (nil) > > That does look like a bug. > > -- > Michel --~--~-~--~~~---~--~~ 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 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: Emtpy (filter ...) Result Yields nil; Could / Should It Be An Empty List?
> user=> (flatten nil) > (nil) Not a bug. flatten returns a sequence - in this case a sequence containing 'nil. How else would you flatten on nil? In the former cases the flatten returns the seq - nil Can Clojure return an empty sequence otherwise? (def x ()) (first x) => nil (def y x) y => nil user> (def y x) #'user/y user> y nil user> (flatten y) (nil) On Dec 14, 9:16 pm, Michel Salim wrote: > On Dec 14, 3:16 pm, Randall R Schulz wrote: > > > Does this makes sense (specifically the last one)? > > > user=> (flatten []) > > nil > > > user=> (flatten ()) > > nil > > Yes; the empty sequence is just nil. > > > user=> (flatten nil) > > (nil) > > That does look like a bug. > > -- > Michel --~--~-~--~~~---~--~~ 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 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: Running out of memory when using filter?
On Sat, Dec 13, 2008 at 5:51 AM, Rich Hickey wrote: > No you can't, for the same reasons you can't for Iterator or > Enumeration seqs. Again it comes down to abstractions, and the > abstraction for (seq x) is one on persistent collections. It presumes > that (seq x) is referentially transparent, which it isn't for > ephemeral sources - i.e. streams aren't colls. It would become quite > fragile if people had to adopt call-once-only semantics for seq - > ephemerality would pollute the world. That said, there are a growing > number of these ephemeral-source-seq functions which could be folded > into one multimethod. Okay, so you've got one abstraction (seq) for persistent collections (and therefore caches to guarantee persistence), and one abstraction (streams) that is for ephemeral sources, and you want to build a barrier between them (so the user has to explicitly call seq-stream to make the conversion). But don't forget that there are collections which are persistent (and therefore, it would be intuitive to use the first/rest sequence abstraction with them), yet too big to cache (e.g., sequence of all permutations of an 11 item list), and/or so cheap to compute that it makes no sense to cache (e.g., (range 100)). I am particularly interested to see what happens with these "persistent streams" for which a sequence abstraction DOES make sense. Perhaps one avenue is to annotate certain streams as being from non-ephemeral sources, and therefore they can automatically be passed to seq-based functions, and remain uncached through various transformations like rest/map/filter/etc. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---