Re: Bug in count for hash-maps with nil values
On Fri, Sep 25, 2009 at 1:46 AM, Richard Newman holyg...@gmail.com wrote: I guess this is already ticketed. I should have searched first, sorry for the noise. It's not already ticketed, even if the root cause might be the same. As I pointed out in my message, these are not hash maps, they're array maps. It's the same root cause, and it has to do with hash maps. When the 9-item hash map is built the bug causes its count to drop to zero (but calling seq on it reveal there are 9 key-value pairs in it). But, the compiler optimizes literal maps whose count is zero into the empty array map. So, really, it's not a bug in PersistentArrayMap and the patch against PersistentHashMap attached to #192 fixes this behaviour. I'm sorry to have introduced this bug. Christophe --~--~-~--~~~---~--~~ 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: Can anyone here give a comparison between Clojure and Erlang on concurrent programming?
2009/9/24 wmacgyver wmacgy...@gmail.com: Excellent summary of each language's sweet spot. I'd like to suggest a different book for Erlang though. For learning Erlang, I'd suggest Erlang Programming by Francesco Cesarini Simon Thompson, published by O'Reilly Yes, this is definitely the best book currently available on Erlang. It's amazing how well it seems to hit both the introductory and more advanced ends of Erlang and its environment. Joe's book was good (but a little shallow), this is indepth yet accessible. Having had the pleasure of spending a good couple of hours with both the authors I can say that not only do they really know their stuff, but that they're both excellent at explaining things... With Francesco being CTO of Erlang Training Consultants (one of the oldest (and probably the oldest) Erlang consultancy companies - outside of Erricson) and Simon being a long established academic authority on functional programming as well as author of what is regarded by many as the best text on Haskell, they have a talent for explaining things simply. The other thing I find striking about this book, is that it's very much a practical book geared at people using Erlang to solve real world problems. There is little talk from ivory towers here, just the nitty gritty details of Erlang, concurrency and high-availability engineering. Anyway, I'm just glad that we now have two practical (real-world) functional languages available to us, Erlang and Clojure. As others have said, Erlang is a more specialist language than Clojure and in its niche it is undisputed king... However Clojure, being built on the JVM is more suited to a wider variety of problems (think everything that Java was used for + everything lisp or scheme is great at with some bonus points for combining these worlds so well). R. --~--~-~--~~~---~--~~ 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: Namespace/class visibility in eval
On 23 Sep., 15:33, John Harrop jharrop...@gmail.com wrote: On Wed, Sep 23, 2009 at 8:50 AM, Philipp Meier phme...@gmail.com wrote: Remember that clojure runs in the JVM and a JVM can have a SecurityManager which can be configured to allow or deny at most any dangeroues operatíon. A java policy file will to the trick, I think. That plausibly helps against malicious I/O and changing the JVM settings (System.setProperty() etc.) but I don't see it doing much about a simple memory-and/or-CPU-exhaustion loop. You're right. For threads not hanging you could monitor the execution time of a evaluation thread and suspend a hangung thread using the java debugger interface (http://java.sun.com/j2se/1.5.0/docs/guide/ jpda/jdi/). Perhaps VisualVM can throw in some technology to monitor actual runtime of the thread and and memory consumption. However this is a rather fragile topic for java. Spawning some additional jvms will probably do better. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Getting REPL transcript
I'm still learning, myself, so I could be wrong, but you might be able to use clojure.contrib.server-socket and tweak it's binding for *in*, *out*, and *err*, like another PushbackInputStream for *in* and copy the lines to a file before sending it into the repl. Or use a pipe perhaps? -- John --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Getting REPL transcript
Thanks I will look into that. But more information on 'pipe' please? So we have two Newman{Rich, John}, so I will say thanks to Newmen. Regards, Emeka On Fri, Sep 25, 2009 at 10:43 AM, John Newman john...@gmail.com wrote: I'm still learning, myself, so I could be wrong, but you might be able to use clojure.contrib.server-socket and tweak it's binding for *in*, *out*, and *err*, like another PushbackInputStream for *in* and copy the lines to a file before sending it into the repl. Or use a pipe perhaps? -- John --~--~-~--~~~---~--~~ 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: Adding Classpaths On The Fly
Hello, maybe this post from Christophe Grand can help : http://clj-me.blogspot.com/2009/01/living-on-bleeding-edge.html regards, -- laurent 2009/9/25 Volkan YAZICI volkan.yaz...@gmail.com Hi, I'm trying to add a classpath to the current Clojure REPL session on the fly. (Particularly, I extracted shcloj-code.tgz of Programming Clojure to /tmp/code directory, and trying to load /tmp/code/examples/snake.clj file.) For this purpose, I tried below two steps with no luck. - (System/setProperty java.class.path (str (System/getProperty java.class.path) :/tmp/code)) - (add-classpath file:///tmp/code) But after both tries Clojure complains that Could not locate examples/snake__init.class or examples/snake.clj on classpath. Am I missing something obvious, or it's not possible to introduce new classpaths on the fly? BTW, after (add-classpath file:///tmp/code) call, (System/getProperty java.class.path) appears to be unchanged. Is that something expected? Regards. --~--~-~--~~~---~--~~ 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: Can anyone here give a comparison between Clojure and Erlang on concurrent programming?
Thanks everyone for your enlightening responses. On Sep 25, 3:35 am, Rick Moynihan rick.moyni...@gmail.com wrote: 2009/9/24 wmacgyver wmacgy...@gmail.com: Excellent summary of each language's sweet spot. I'd like to suggest a different book for Erlang though. For learning Erlang, I'd suggest Erlang Programming by Francesco Cesarini Simon Thompson, published by O'Reilly Yes, this is definitely the best book currently available on Erlang. It's amazing how well it seems to hit both the introductory and more advanced ends of Erlang and its environment. Joe's book was good (but a little shallow), this is indepth yet accessible. Having had the pleasure of spending a good couple of hours with both the authors I can say that not only do they really know their stuff, but that they're both excellent at explaining things... With Francesco being CTO of Erlang Training Consultants (one of the oldest (and probably the oldest) Erlang consultancy companies - outside of Erricson) and Simon being a long established academic authority on functional programming as well as author of what is regarded by many as the best text on Haskell, they have a talent for explaining things simply. The other thing I find striking about this book, is that it's very much a practical book geared at people using Erlang to solve real world problems. There is little talk from ivory towers here, just the nitty gritty details of Erlang, concurrency and high-availability engineering. Anyway, I'm just glad that we now have two practical (real-world) functional languages available to us, Erlang and Clojure. As others have said, Erlang is a more specialist language than Clojure and in its niche it is undisputed king... However Clojure, being built on the JVM is more suited to a wider variety of problems (think everything that Java was used for + everything lisp or scheme is great at with some bonus points for combining these worlds so well). R. --~--~-~--~~~---~--~~ 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 knowing Java a prerequisite for using Clojure?
On Sep 17, 10:01 pm, Hugh Aguilar hugoagui...@rosycrew.com wrote: I want to create a DSL for generating gcode for cnc milling machines Unrelated to Clojure, but on the subject of DSL, the July/August 2009 issue (vol. 26 no. 4) of IEEE Software is dedicated to domain-specific modeling. http://www2.computer.org/portal/web/csdl/magazines/software;jsessionid=196C224E83879BD10B3E67E625C4185A#3 --~--~-~--~~~---~--~~ 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: Adding Classpaths On The Fly
On Fri, Sep 25, 2009 at 3:02 AM, Volkan YAZICI volkan.yaz...@gmail.comwrote: Hi, I'm trying to add a classpath to the current Clojure REPL session on the fly. (Particularly, I extracted shcloj-code.tgz of Programming Clojure to /tmp/code directory, and trying to load /tmp/code/examples/snake.clj file.) For this purpose, I tried below two steps with no luck. - (System/setProperty java.class.path (str (System/getProperty java.class.path) :/tmp/code)) - (add-classpath file:///tmp/code) try (add-classpath file:///tmp/code/examples) But after both tries Clojure complains that Could not locate examples/snake__init.class or examples/snake.clj on classpath. Am I missing something obvious, or it's not possible to introduce new classpaths on the fly? BTW, after (add-classpath file:///tmp/code) call, (System/getProperty java.class.path) appears to be unchanged. Is that something expected? Regards. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Getting REPL transcript
On Sep 23, 1:09 pm, John Harrop jharrop...@gmail.com wrote: Actually, that suggests a more general point: that we can have programmatic access to the REPL's backlog if we modify the REPL process's Java code somewhat. The REPL is written in Clojure, so it's quite easy to modify. Look at src/clj/clojure/main.clj in the recent Clojure sources. -SS --~--~-~--~~~---~--~~ 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: test.clj / test/tap.clj error
On Sep 23, 3:39 pm, MarkSwanson mark.swanson...@gmail.com wrote: I'm trying to use tst/tap.clj but the tap output does not contain the 'not ok' line. I think this is a bug in tap.clj. Here is the small test: You're right, it's a bug. Please file a ticket on Assembla; you can assign it to me. -Stuart Sierra --~--~-~--~~~---~--~~ 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: Schema for data structures
Hi, thanks for the suggestions about writing an alternate defstruct. I tried to turn the wishful thinking from my initial email into code. Results here: http://github.com/mbrezu/beak-check Testing structures with beak-check requires some code, but it allows to test nested structures and testing the type of the structure members. I welcome any thoughts/ideas/critiques. Thanks again, On Thu, Sep 24, 2009 at 7:39 PM, Richard Newman holyg...@gmail.com wrote: Use it just like you use defstruct, e.g.: (defstruct* person :first- name :last-name :age), but it will also create a little type-checker function: is-person? Here are some tests to see how it works: Note that your type checker will give false positives if you're intending to use accessors: an ordinary map with the same keys will match the predicate, but accessor calls will fail. (I also have a defstruct*, but it defines accessors and a struct-map coercion, not a predicate :)) -- Miron Brezuleanu --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Macros, namespaces, and lexical scope
(I asked these questions on #clojure, and the friendly locals suggested I open the question up for a wider audience.) I'm trying to write a macro-writing-macro. My code has a bunch of resources which have -open and -close type of calls, and they could all benefit from with- wrappers. The with- wrappers all have similar structure, and I thought I would be better off defining them with another macro: (defmacro def-with-db-macro [macro-name open-fn close-fn] `(defmacro ~macro-name [[var# open-args#] body#] `(let [~var# (apply ~'~open-fn [...@open-args#])] (try ~...@body# (finally (~'~close-fn ~var#)) Sample use: (def-with-db-macro with-db-env db-env-open db-env-close) (def-with-db-macro with-db db-open db-close) (def-with-db-macro with-db-txn db-txn-begin (fn [txn] (when (= @(txn :status) :open) (db-txn-commit txn This mostly works. It breaks if I try using, e.g., with-db-env in a namespace which does not import db-env-open or db-env-close. Chris Houser has summarized the problem here more succinctly than I can: http://paste.lisp.org/display/87734 While searching for a workaround, I thought maybe I could capture the functions I need during expansion of def-with-db-macro, but kept getting a useless exception. I ended up reducing that problem to this: (let [f1 #(inc %)] (defmacro m1 [x] `(~f1 ~x))) (m1 12) = No message. [Thrown class java.lang.ExceptionInInitializerError] The equivalent works in Common Lisp (Allegro CL and SBCL): (let ((f1 (lambda (y) (1+ y (defmacro m1 (x) `(funcall ,f1 ,x))) (m1 12) = 13 Thoughts on either of these brain teasers? Thanks! PS: To read the IRC discussion, see http://clojure-log.n01se.net/date/2009-09-25.html and scroll down to the discussion starting at 15:16. --~--~-~--~~~---~--~~ 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: test.clj / test/tap.clj error
In case others wonder how do file a ticket on Assembla: 1. sign up for an Assembla account at www.assembla.com 2. Ack the signup email 3. go to : https://www.assembla.com/spaces/clojure-contrib/tickets 4. look for the 'create ticket' button. Then tell me where it is so I can also file a ticket. Heh heh... :-) (I'm guessing it's because I'm not part of the clojure-contrib team) Cheers. P.S. search for 'Clojure' using Assembla search and the only result is: Text Adventure Game in Clojure --~--~-~--~~~---~--~~ 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: Macros, namespaces, and lexical scope
On Fri, Sep 25, 2009 at 4:49 PM, Constantine Vetoshev gepar...@gmail.comwrote: (let [f1 #(inc %)] (defmacro m1 [x] `(~f1 ~x))) (m1 12) = No message. [Thrown class java.lang.ExceptionInInitializerError] The equivalent works in Common Lisp (Allegro CL and SBCL): (let ((f1 (lambda (y) (1+ y (defmacro m1 (x) `(funcall ,f1 ,x))) (m1 12) = 13 Thoughts on either of these brain teasers? I don't think you can use things like defmacro in a let. Macros are used at macroexpansion time and I don't think a let's bindings will exist yet. So you probably need something like (defmacro m1 [x] (let [f1 #(inc %)] `(~f1 ~x))) instead. --~--~-~--~~~---~--~~ 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: Macros, namespaces, and lexical scope
On Sep 25, 6:02 pm, John Harrop jharrop...@gmail.com wrote: I don't think you can use things like defmacro in a let. This works: (let [y 10] (defmacro m1 [] `(list ~y))) (m1) = (10) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
in-smaller-lists
I'm doing some file streaming with a lazy list and I ran into a problem where I had to process a whole chunk at a time, so I wrote this function. Just posting to see if I'm reinventing something or if it might be a good addition to contrib. (defn in-smaller-lists [the-list smaller-list-size] (lazy-seq (let [[fnbr the-rest] (split-at smaller-list-size the-list)] (if (first the-rest) (cons fnbr (in-smaller-lists the-rest smaller-list-size)) (list fnbr)) ))) Example: user= (in-smaller-lists (range 11) 3) ((0 1 2) (3 4 5) (6 7 8) (9 10)) I do database work and this is very useful for processing a csv n rows at a time. Travis --~--~-~--~~~---~--~~ 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: Macros, namespaces, and lexical scope
On Fri, Sep 25, 2009 at 8:48 PM, Constantine Vetoshev gepar...@gmail.comwrote: On Sep 25, 6:02 pm, John Harrop jharrop...@gmail.com wrote: I don't think you can use things like defmacro in a let. This works: (let [y 10] (defmacro m1 [] `(list ~y))) (m1) = (10) Well, that's weirdly inconsistent. It shouldn't work just *some* of the time. Either it should work, or it shouldn't work. According to the language semantics, it should work if let bindings wrapping def forms are in effect during any side effects of the def form, and should fail otherwise. Anyone knowledgeable about clojure internals have any idea why it would work sometimes, but only sometimes? Did you get a detail message or stack trace from the exception you saw? --~--~-~--~~~---~--~~ 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: in-smaller-lists
On Friday 25 September 2009 at 08:46 pm, Travis wrote: I'm doing some file streaming with a lazy list and I ran into a problem where I had to process a whole chunk at a time, so I wrote this function. Just posting to see if I'm reinventing something or if it might be a good addition to contrib. (defn in-smaller-lists [the-list smaller-list-size] ... Example: user= (in-smaller-lists (range 11) 3) ((0 1 2) (3 4 5) (6 7 8) (9 10)) How about: user= (partition 3 3 nil (range 11)) ((0 1 2) (3 4 5) (6 7 8) (9 10)) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
how to understand macro in clojure?
(defn float2 [f a b] (f (float a ) (float b))) (float2 + 1 2) = 3.0 (defmacro mfloat2 [f a b] (f (float a) (float b))) (mfloat2 + 1 2 ) = 2.0 ??? macro expend to last expression in list,right? (defmacro m2float2 [f a b] `(~f (float ~a) (float ~b))) (mfloat2 + 1 2) = 3.0 (defmacro m3float2 [f a b] (list f (float a ) (float b))) (m3float2 + 1 2) = 3.0 functions of macro only not evaluating args ? what's the difference between macro and call by name in other language? gerry --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---