Contributor Agreement forms came back unclaimed
Hello, In two separate instances, the contributor agreement forms sent by the Bangalore Clojure group and another one sent by me (from Bangalore) have come back unclaimed. Is there something I am missing? The following address was used in both cases: Rich Hickey P.O. Box 316 Pleasantville, NY 10570-0316 United States of America Regards, Shantanu -- 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: with-timeout... ?
In Overtone we have the same situation, where we return a promise representing a server response and sometimes we want to timeout if the response never arrives. This is what we use: (defn await-promise! ([prom] (await-promise prom REPLY-TIMEOUT)) ([prom timeout] (.get (future @prom) timeout TimeUnit/MILLISECONDS))) (We have another version without the exclamation mark that returns :timeout rather than throwing an exception when timed out.) I agree with you though, that something along these lines should be built-in. I was surprised to find that there was no way to block on a promise with a timeout, as it seems like such a typical requirement for almost anything you might be promised. -Jeff On Mar 9, 1:12 pm, Sean Allen s...@monkeysnatchbanana.com wrote: Yesterday I was writing a bit of code that needs to wait for an external event to happen but if it doesn't happen with X amount of time, to timeout with an error. Is there a library to handle this? I know you can do it with a future and if you google the general idea, there are a few blog posts, stack overflow questions etc that all have the same basic solution. It seems like such a common thing to do that there would be a standard function/macro out there for it rather than everyone rolling their own. I couldn't however find one. Does one exist? If yes, pointer in the right direction. Thanks, Sean -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: borneo - Clojure wrapper for Neo4j, a graph database.
Out of curiosity, why did you go with Neo4j rather than using jiraph? (https://github.com/ninjudd/jiraph) I used neo4j in the past, and if I remember right my main annoyance was that edges had to be traversed based on the type of the edge instance object, which felt annoying from a language like clojure where I rarely want to think about Java types in this way, especially since they are all implementing the Relationship interface. Instead with Jiraph you can traverse edges by inspecting arbitrary edge properties. It's also a native clojure lib so the API is quite easy to work with. It would be interesting to see a performance comparison... Cheers, Jeff On Mar 9, 2:50 pm, Jozef Wagner jozef.wag...@gmail.com wrote: Hello, I've released a Clojure wrapper for Neo4j called borneo. Purpose of this library is to provide intiutive access to commonly used Neo4j operations. It uses official Neo4j Java bindings. It does not use Blueprints interface. Project page, examples:http://github.com/wagjo/borneo API:http://wagjo.github.com/borneo Install: Libs available through clojars, include dependency [borneo 0.1.0] in your project.clj. Best, Jozef -- 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: Monad Lessons
Definitely free. :) I feel like there are already a ton of resources for reading/watching to learn monads, and yet people still have trouble getting over the hump. So my thought was that this would be different because there would be chance for interaction. So I probably wouldn't record it. The talk at CodePaLOUsa was recorded and will be on InfoQ eventually. I'll try to get the slides posted in the not too distant future, though they should be posted on the CodePaLOUsa website soon. Jim -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
setup and propagation of config-params
hi clojure-users, i have a question regarding the setup and propagation of config-params. to configure a clojure-based web-app, i use a global var *opts* that is setup like this: (defn get-opts [environment] (condp = environment :development { :webapp-context /mywebapp :webapp-dir src/main/webapp :authentication true :show-sql true} :test { :webapp-context /mywebapp :webapp-dir src/main/webapp :authentication false :show-sql true} :production { :webapp-context /mywebapp :webapp-dir /appserver/tomcat/apache-tomcat-5.5.25/webapps/ mywebapp :authentication true :show-sql false} (throw (IllegalArgumentException. (str unexpected environment: environment) (def ^:dynamic *opts* (get-opts :development)) i run tests like this: (binding [*opts* (get-opts :test)] (run-tests))) references to *opts* are scattered all over my clojure-code so that many of the functions are impure. this seems like a smell to me and there are probably cleaner ways to propagate config-params (keep functions pure) ... what are they ? thanks -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Clojure Meetup at Pycon
Hey guys, I'm pretty new to Clojure and loving it. I'm going to be at Pycon (the Python conference in Atlanta) this weekend. Any other clojurers going to be there? Want to meet and chat about our two favorite languages? Alex -- 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: Monad Lessons
I'd love to assit too (I like the fact that it'd be interactive). Just to let you know I'm on GMT (for when you schedule things). Cheers, U -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Monad Lessons
I'd be interested as well; sounds awesome :) Thanks for your offer, ~Adam~ -- 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: overriding keyword behavior?
That was basically my question, protocols are designed for this but ILookup isn't a protocol. Is it possible to make ILookup into a protocol? I haven't looked at the java code much at all, but I might take a stab at creating a patch it that seems possible. Converting java.util.Properties into a map isn't hard, but converting java objects to native maps is extreamly common (bean, reflect, ring, etc...) and perhaps unnecessary in many situations if one could just extend an existing java type with ILookup so that if it looks like a duck, its a duck. - Kurt On Mar 8, 3:34 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote: Oh yeah, you can't extend an interface to a new class. So it won't work. This is why protocols exist, in fact. Silly me. -S -- 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: Monad Lessons
Jim, i assume you are familiar with haskell (monads - haskell :)) So my question is, can you describe the difference in working with monads in dynamic language (clojure) with working with monads in haskell. From my own experience i would say that without a firm help from typing system i would struggle with monads in clojure. Heck i struggle with them even in haskell :) On Mar 9, 11:15 am, jim jim.d...@gmail.com wrote: I gave a talk at CodePaLOUsa on monads and got some favorable feedback. So I thought I'd offer to do a live training session on monads using pretty much the same material, but at a shared REPL rather than with slides. How it would work is I would start a Skype conference for 5 to 10 people. We would also all log in to a tmux session where I would show the examples and their results. So, my question is how many would be interested in such a session? This would be a basic introduction to monads. Future session could be about more advanced monad topics, if there was a demand for that. Jim -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Can this function be simpler?
Hi I wrote a function to transform a variable number of arguments into embedded maps. Here is what it does: (enmap 1 2) {1 2} (enmap 1 2 3) {1 {2 3}} (enmap 1 2 3 4) {1 {2 {3 4}}} (enmap 1 2 3 4 {5 6 7 8}) {1 {2 {3 {4 {5 6, 7 8} Here is my implementation: (defn enmap [arg args] (if-let [more (butlast args)] (let [k (last more), v (last args)] (if-let [even-more (butlast more)] (apply enmap arg (concat even-more (list (hash-map k v (enmap arg (hash-map k v (apply hash-map arg args))) Two things bother me: - Is there a way to make this function less complicated? without recursion maybe? - Is there something simpler than (concat even-more (list (hash-map k v)) to append an element at the end of a sequence? Thanks -- Damien -- 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 this function be simpler?
(let [[tail more] ((juxt last (comp reverse butlast)) [1 2 3 4 {5 6 7 8}])] (reduce #(hash-map %2 %1) tail more)) {1 {2 {3 {4 {5 6, 7 8} On Mar 10, 9:46 am, Damien Lepage damienlep...@gmail.com wrote: Hi I wrote a function to transform a variable number of arguments into embedded maps. Here is what it does: (enmap 1 2) {1 2} (enmap 1 2 3) {1 {2 3}} (enmap 1 2 3 4) {1 {2 {3 4}}} (enmap 1 2 3 4 {5 6 7 8}) {1 {2 {3 {4 {5 6, 7 8} Here is my implementation: (defn enmap [arg args] (if-let [more (butlast args)] (let [k (last more), v (last args)] (if-let [even-more (butlast more)] (apply enmap arg (concat even-more (list (hash-map k v (enmap arg (hash-map k v (apply hash-map arg args))) Two things bother me: - Is there a way to make this function less complicated? without recursion maybe? - Is there something simpler than (concat even-more (list (hash-map k v)) to append an element at the end of a sequence? Thanks -- Damien -- 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 this function be simpler?
On Thu, Mar 10, 2011 at 12:46 PM, Damien Lepage damienlep...@gmail.com wrote: Hi I wrote a function to transform a variable number of arguments into embedded maps. Here is what it does: (enmap 1 2) {1 2} (enmap 1 2 3) {1 {2 3}} (enmap 1 2 3 4) {1 {2 {3 4}}} (enmap 1 2 3 4 {5 6 7 8}) {1 {2 {3 {4 {5 6, 7 8} Here is my implementation: (defn enmap [arg args] (if-let [more (butlast args)] (let [k (last more), v (last args)] (if-let [even-more (butlast more)] (apply enmap arg (concat even-more (list (hash-map k v (enmap arg (hash-map k v (apply hash-map arg args))) Two things bother me: Is there a way to make this function less complicated? without recursion maybe? Is there something simpler than (concat even-more (list (hash-map k v)) to append an element at the end of a sequence? When I see a pattern like this of repeatedly doing something to a collection, I immediately think of reduce. For fun, let's see what happens when I try it: user= (reduce hash-map [1 2 3 4 5]) 1 2} 3} 4} 5} Close, but backwards. I know reduce is equivalent to a left-fold, so to get the opposite I want a right-fold. Clojure doesn't have that built-in, but one way to define it: user=(defn foldr [f coll] (reduce #(f %2 %1) (reverse coll))) Now, we can: user=(foldr hash-map [1 2 3 4 5]) {1 {2 {3 {4 5 -- 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 this function be simpler?
On Mar 10, 12:46 pm, Damien Lepage damienlep...@gmail.com wrote: Hi I wrote a function to transform a variable number of arguments into embedded maps. Here is what it does: (enmap 1 2) {1 2} (enmap 1 2 3) {1 {2 3}} (enmap 1 2 3 4) {1 {2 {3 4}}} (enmap 1 2 3 4 {5 6 7 8}) {1 {2 {3 {4 {5 6, 7 8} Here is my implementation: (defn enmap [arg args] (if-let [more (butlast args)] (let [k (last more), v (last args)] (if-let [even-more (butlast more)] (apply enmap arg (concat even-more (list (hash-map k v (enmap arg (hash-map k v (apply hash-map arg args))) Two things bother me: - Is there a way to make this function less complicated? without recursion maybe? - Is there something simpler than (concat even-more (list (hash-map k v)) to append an element at the end of a sequence? I sure hope so, because I don't even understand how that works ;-) How about this: (defn enmap [arg more] (if more {arg (apply enmap more)} arg)) - Chris -- 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 this function be simpler?
On Mar 10, 10:05 am, Aaron Cohen aa...@assonance.org wrote: On Thu, Mar 10, 2011 at 12:46 PM, Damien Lepage damienlep...@gmail.com wrote: Hi I wrote a function to transform a variable number of arguments into embedded maps. Here is what it does: (enmap 1 2) {1 2} (enmap 1 2 3) {1 {2 3}} (enmap 1 2 3 4) {1 {2 {3 4}}} (enmap 1 2 3 4 {5 6 7 8}) {1 {2 {3 {4 {5 6, 7 8} Here is my implementation: (defn enmap [arg args] (if-let [more (butlast args)] (let [k (last more), v (last args)] (if-let [even-more (butlast more)] (apply enmap arg (concat even-more (list (hash-map k v (enmap arg (hash-map k v (apply hash-map arg args))) Two things bother me: Is there a way to make this function less complicated? without recursion maybe? Is there something simpler than (concat even-more (list (hash-map k v)) to append an element at the end of a sequence? When I see a pattern like this of repeatedly doing something to a collection, I immediately think of reduce. For fun, let's see what happens when I try it: user= (reduce hash-map [1 2 3 4 5]) 1 2} 3} 4} 5} Close, but backwards. I know reduce is equivalent to a left-fold, so to get the opposite I want a right-fold. Clojure doesn't have that built-in, but one way to define it: user=(defn foldr [f coll] (reduce #(f %2 %1) (reverse coll))) Now, we can: user=(foldr hash-map [1 2 3 4 5]) {1 {2 {3 {4 5 Ah, this is nicer than mine. Also see https://github.com/amalloy/hot-potato, which has a reorder HOF so that you could write a perhaps-clearer (reduce (reorder f) (reverse coll)). -- 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 this function be simpler?
On Thu, Mar 10, 2011 at 12:46 PM, Damien Lepage damienlep...@gmail.com wrote: Hi (apply enmap arg (concat even-more (list (hash-map k v Is there something simpler than (concat even-more (list (hash-map k v)) to append an element at the end of a sequence? To answer your second question, I think this is the same as: (apply enmap arg (conj even-more {k v}) -- 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 this function be simpler?
- Is there a way to make this function less complicated? without recursion maybe? Looks like you're covered on this one. - Is there something simpler than (concat even-more (list (hash-map k v)) to append an element at the end of a sequence? Clojure is opinionated in this sense. Appending to the end of a general sequence is O(n), so it's intentionally clunky to do so. If you had to do it, you'd use (concat even-more [(hash-map k v)]) -- explicit calls to list are rare in idiomatic code -- but the preferred way is generally to use a vector, with conj or into, which has O(log n) performance: user (conj [1 2 3] 4) [1 2 3 4] user (into [1 2 3] [5 6]) [1 2 3 5 6] -Jason -- 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 this function be simpler?
Interesting. Here is my attempt. (defn enmap [args] (let [[fs res] (reverse args)] (reduce (fn [v k] (hash-map k v)) fs res))) (enmap [1 2 3 4 {5 6 7 8}]) = {1 {2 {3 {4 {5 6, 7 8} (let [[tail more] ((juxt last (comp reverse butlast)) [1 2 3 4 {5 6 7 8}])] (reduce #(hash-map %2 %1) tail more)) I still cannot understand what is going on in this code. juxt always make my head crashed. Thanks. 2011/3/11 Damien Lepage damienlep...@gmail.com: Hi I wrote a function to transform a variable number of arguments into embedded maps. Here is what it does: (enmap 1 2) {1 2} (enmap 1 2 3) {1 {2 3}} (enmap 1 2 3 4) {1 {2 {3 4}}} (enmap 1 2 3 4 {5 6 7 8}) {1 {2 {3 {4 {5 6, 7 8} Here is my implementation: (defn enmap [arg args] (if-let [more (butlast args)] (let [k (last more), v (last args)] (if-let [even-more (butlast more)] (apply enmap arg (concat even-more (list (hash-map k v (enmap arg (hash-map k v (apply hash-map arg args))) Two things bother me: Is there a way to make this function less complicated? without recursion maybe? Is there something simpler than (concat even-more (list (hash-map k v)) to append an element at the end of a sequence? Thanks -- Damien -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
[ANN] Rummage v0.0.1 – a Clojure client library for Amazon’s SimpleDB (SDB)
I've now pushed v0.0.1 of Rummage to github and maven central. This is my massive refactoring / rewrite of Rich's original SDB client implementation: https://github.com/cemerick/rummage It addresses all of the issues I note in the quoted google doc, and hopefully pushes things forward some w.r.t. data encoding issues and such. Feedback and suggestions most welcome. Thanks, - Chas On Feb 26, 2011, at 3:38 PM, Chas Emerick wrote: FYI and FWIW, I've jotted down some notes detailing how I'd like to see the library change: https://docs.google.com/document/d/1K5p2RRVtvYxBNLEJuWGNf1iZak2ri8cI73joWu9K1W0/edit?hl=enauthkey=CMDR_6AF If you have feedback, questions, thoughts, whatever, do let me know. Thanks, - Chas On Feb 24, 3:36 pm, Chas Emerick cemer...@snowtide.com wrote: Is anyone using the sdb (AWS SimpleDB) client library, originally written by Rich Hickey in 2009, and then tweaked in various ways by a couple of others since? Github repo network here:https://github.com/richhickey/sdb/network I ask because I have some ideas for some changes and enhancements to the library, some of which would be breaking (potentially from both an API and data format standpoint). It seems like having a dialogue with anyone that is actively using it would be productive, if only to ensure that I'm not headed towards the weeds. Beyond that, a collective attempt to coordinate the direction of the project would be good (rather than simply letting off-by-one forks of it proliferate on github). Cheers, - Chas -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Can this function be simpler?
more concise: (defn enmap [args] (reduce #(hash-map %2 %1) (reverse args))) 2011/3/11 Takahiro fat...@googlemail.com: Interesting. Here is my attempt. (defn enmap [args] (let [[fs res] (reverse args)] (reduce (fn [v k] (hash-map k v)) fs res))) (enmap [1 2 3 4 {5 6 7 8}]) = {1 {2 {3 {4 {5 6, 7 8} (let [[tail more] ((juxt last (comp reverse butlast)) [1 2 3 4 {5 6 7 8}])] (reduce #(hash-map %2 %1) tail more)) I still cannot understand what is going on in this code. juxt always make my head crashed. Thanks. 2011/3/11 Damien Lepage damienlep...@gmail.com: Hi I wrote a function to transform a variable number of arguments into embedded maps. Here is what it does: (enmap 1 2) {1 2} (enmap 1 2 3) {1 {2 3}} (enmap 1 2 3 4) {1 {2 {3 4}}} (enmap 1 2 3 4 {5 6 7 8}) {1 {2 {3 {4 {5 6, 7 8} Here is my implementation: (defn enmap [arg args] (if-let [more (butlast args)] (let [k (last more), v (last args)] (if-let [even-more (butlast more)] (apply enmap arg (concat even-more (list (hash-map k v (enmap arg (hash-map k v (apply hash-map arg args))) Two things bother me: Is there a way to make this function less complicated? without recursion maybe? Is there something simpler than (concat even-more (list (hash-map k v)) to append an element at the end of a sequence? Thanks -- Damien -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Clojure Meetup at Pycon
Hi Alex, great to hear that there are more clojurians going pycon :). I'm currently attending the pycon tutorial sessions and I'm staying until sunday the 13th. Just let me know when you're here and where to meet. Are the more clojurians wanting to join? Cheers, Erik On Mar 10, 2:26 pm, Alex Robbins alexander.j.robb...@gmail.com wrote: Hey guys, I'm pretty new to Clojure and loving it. I'm going to be at Pycon (the Python conference in Atlanta) this weekend. Any other clojurers going to be there? Want to meet and chat about our two favorite languages? Alex -- 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 this function be simpler?
Thanks a lot for your help, there's an awesome community here. Sorry for the dumb questions, I'll try no to be too noisy on this list. BTW, shouldn't it be better to create a separate mailing list for beginners? Well, we would still need some experienced clojurers to answer the questions though ... Or maybe beginners like me should rather be encouraged to post their questions on StackOverflow? That would also give more visibility to the language (there are just about 2 or 3 questions a day about Clojure there). What do you think? Where do you want to see my next stupid trivial question? Damien 2011/3/10 Takahiro fat...@googlemail.com more concise: (defn enmap [args] (reduce #(hash-map %2 %1) (reverse args))) 2011/3/11 Takahiro fat...@googlemail.com: Interesting. Here is my attempt. (defn enmap [args] (let [[fs res] (reverse args)] (reduce (fn [v k] (hash-map k v)) fs res))) (enmap [1 2 3 4 {5 6 7 8}]) = {1 {2 {3 {4 {5 6, 7 8} (let [[tail more] ((juxt last (comp reverse butlast)) [1 2 3 4 {5 6 7 8}])] (reduce #(hash-map %2 %1) tail more)) I still cannot understand what is going on in this code. juxt always make my head crashed. Thanks. 2011/3/11 Damien Lepage damienlep...@gmail.com: Hi I wrote a function to transform a variable number of arguments into embedded maps. Here is what it does: (enmap 1 2) {1 2} (enmap 1 2 3) {1 {2 3}} (enmap 1 2 3 4) {1 {2 {3 4}}} (enmap 1 2 3 4 {5 6 7 8}) {1 {2 {3 {4 {5 6, 7 8} Here is my implementation: (defn enmap [arg args] (if-let [more (butlast args)] (let [k (last more), v (last args)] (if-let [even-more (butlast more)] (apply enmap arg (concat even-more (list (hash-map k v (enmap arg (hash-map k v (apply hash-map arg args))) Two things bother me: Is there a way to make this function less complicated? without recursion maybe? Is there something simpler than (concat even-more (list (hash-map k v)) to append an element at the end of a sequence? Thanks -- Damien -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Damien Lepage http://damienlepage.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Monad Lessons
On Thu, Mar 10, 2011 at 11:55 AM, Vagif Verdi vagif.ve...@gmail.com wrote: Jim, i assume you are familiar with haskell (monads - haskell :)) So my question is, can you describe the difference in working with monads in dynamic language (clojure) with working with monads in haskell. From my own experience i would say that without a firm help from typing system i would struggle with monads in clojure. Heck i struggle with them even in haskell :) I recently came across this A Schemer's View of Monadshttp://www.cs.indiana.edu/cgi-pub/c311/lib/exe/fetch.php?media=manymonads.pdf, by none other than Daniel P. Friedman (Little Schemer, Essentials of Programming Languages, etc) David -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Can this function be simpler?
Ah, thanks. I think the pulling-apart of last and butlast was a remnant of my trying to do this with foldl instead of foldr :P. On Mar 10, 10:38 am, Takahiro fat...@googlemail.com wrote: more concise: (defn enmap [args] (reduce #(hash-map %2 %1) (reverse args))) 2011/3/11 Takahiro fat...@googlemail.com: Interesting. Here is my attempt. (defn enmap [args] (let [[fs res] (reverse args)] (reduce (fn [v k] (hash-map k v)) fs res))) (enmap [1 2 3 4 {5 6 7 8}]) = {1 {2 {3 {4 {5 6, 7 8} (let [[tail more] ((juxt last (comp reverse butlast)) [1 2 3 4 {5 6 7 8}])] (reduce #(hash-map %2 %1) tail more)) I still cannot understand what is going on in this code. juxt always make my head crashed. Thanks. 2011/3/11 Damien Lepage damienlep...@gmail.com: Hi I wrote a function to transform a variable number of arguments into embedded maps. Here is what it does: (enmap 1 2) {1 2} (enmap 1 2 3) {1 {2 3}} (enmap 1 2 3 4) {1 {2 {3 4}}} (enmap 1 2 3 4 {5 6 7 8}) {1 {2 {3 {4 {5 6, 7 8} Here is my implementation: (defn enmap [arg args] (if-let [more (butlast args)] (let [k (last more), v (last args)] (if-let [even-more (butlast more)] (apply enmap arg (concat even-more (list (hash-map k v (enmap arg (hash-map k v (apply hash-map arg args))) Two things bother me: Is there a way to make this function less complicated? without recursion maybe? Is there something simpler than (concat even-more (list (hash-map k v)) to append an element at the end of a sequence? Thanks -- Damien -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Can this function be simpler?
Thanks a lot for your help, there's an awesome community here. Sorry for the dumb questions, I'll try no to be too noisy on this list. BTW, shouldn't it be better to create a separate mailing list for beginners? Well, we would still need some experienced clojurers to answer the questions though ... Downvote this idea. There's already a clojure-dev list for people who want to hack on the language itself; if you just want access to the community, this is a fine place for beginners and experts alike. Or maybe beginners like me should rather be encouraged to post their questions on StackOverflow? That would also give more visibility to the language (there are just about 2 or 3 questions a day about Clojure there). What do you think? Where do you want to see my next stupid trivial question? I like SO, personally, but there's a lot to be said for having a separate mailing list like this. I doubt anyone would mind if you cross-posted to SO; the best SO answers could be cross-posted back here. Disclaimer: this may be a terrible idea and I'm happy to have people disagree. You can also pop into #clojure on freenode. -- 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 this function be simpler?
On Mar 10, 7:48 pm, Damien Lepage damienlep...@gmail.com wrote: Sorry for the dumb questions, I'll try no to be too noisy on this list. I found this thread useful. Please keep asking questions. Saul -- 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: setup and propagation of config-params
On Thu, Mar 10, 2011 at 9:51 AM, faenvie faen...@googlemail.com wrote: references to *opts* are scattered all over my clojure-code so that many of the functions are impure. this seems like a smell to me and there are probably cleaner ways to propagate config-params (keep functions pure) ... what are they ? There is only one; the only way to get information into a pure function is in its parameters. So you'd have to pass the *opts* object down the call chain to every function that needs it. On the other hand, function purity can be scoped, in a sense. If *opts* is set once, at startup, and does not change after that, then otherwise-pure functions that depend on it are pure within the context of a single run of the program, since they will not change their behavior (or change the behavior of anything else) during that run, consistently returning the same value when called with the same arguments. If *opts* is different from one run to the next, it's as though one set of pure functions were used in the one run, and another set of pure functions in the next run. The reason impure functions can be trouble is because they can suffer long-range interactions that screw things up in difficult-to-debug ways. But if *opts* is unchanging after startup there shouldn't be any long-range interactions to trouble you. Of course, the program may misbehave if *opts* is set wrong, but the same would be true if it got passed everywhere as a parameter. Just keep in mind that *opts*, or rather the code that sets it up during startup and whatever influences it (e.g. the set of command-line args), is one more place to check for the causes of bugs. -- 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
Idiomatic way to handle name shadowing?...
Hi, This is a newb question so apologies in advance if I haven't read enough Clojure code yet to see the answer. Suppose I need mathematical 2D vector functions: (ns geometry.vector) (defstruct vector :x :y) (defn + Add vectors v and w, yielding a vector [ v w ] (...)) Which leads to the core vector function being shadowed by my struct and the core + function shadowed by my function. What is the idiomatic Clojure approach for handling this situation? Is it through careful use of :require and :import parts of a (ns ...) form? I've also seen instances of naming changes to avoid the problem, e.g. (defstruct vector ...) and (defn vector+ ...) but not sure if that's making best use of Clojure namespaces? Any advice much appreciated, Stu -- 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 this function be simpler?
Real nice and short. Doing [ args] avoids the vector: user= (enmap 1 2 3 4 {5 6 7 8}) {1 {2 {3 {4 {5 6, 7 8} On Mar 10, 10:38 am, Takahiro fat...@googlemail.com wrote: more concise: (defn enmap [args] (reduce #(hash-map %2 %1) (reverse args))) 2011/3/11 Takahiro fat...@googlemail.com: Interesting. Here is my attempt. (defn enmap [args] (let [[fs res] (reverse args)] (reduce (fn [v k] (hash-map k v)) fs res))) (enmap [1 2 3 4 {5 6 7 8}]) = {1 {2 {3 {4 {5 6, 7 8} (let [[tail more] ((juxt last (comp reverse butlast)) [1 2 3 4 {5 6 7 8}])] (reduce #(hash-map %2 %1) tail more)) I still cannot understand what is going on in this code. juxt always make my head crashed. Thanks. 2011/3/11 Damien Lepage damienlep...@gmail.com: Hi I wrote a function to transform a variable number of arguments into embedded maps. Here is what it does: (enmap 1 2) {1 2} (enmap 1 2 3) {1 {2 3}} (enmap 1 2 3 4) {1 {2 {3 4}}} (enmap 1 2 3 4 {5 6 7 8}) {1 {2 {3 {4 {5 6, 7 8} Here is my implementation: (defn enmap [arg args] (if-let [more (butlast args)] (let [k (last more), v (last args)] (if-let [even-more (butlast more)] (apply enmap arg (concat even-more (list (hash-map k v (enmap arg (hash-map k v (apply hash-map arg args))) Two things bother me: Is there a way to make this function less complicated? without recursion maybe? Is there something simpler than (concat even-more (list (hash-map k v)) to append an element at the end of a sequence? Thanks -- Damien -- 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- Hide quoted text - - Show quoted text - -- 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: Idiomatic way to handle name shadowing?...
On Mar 10, 12:48 pm, stu stuart.hungerf...@gmail.com wrote: Hi, This is a newb question so apologies in advance if I haven't read enough Clojure code yet to see the answer. Suppose I need mathematical 2D vector functions: (ns geometry.vector) (defstruct vector :x :y) (defn + Add vectors v and w, yielding a vector [ v w ] (...)) Which leads to the core vector function being shadowed by my struct and the core + function shadowed by my function. What is the idiomatic Clojure approach for handling this situation? Is it through careful use of :require and :import parts of a (ns ...) form? I've also seen instances of naming changes to avoid the problem, e.g. (defstruct vector ...) and (defn vector+ ...) but not sure if that's making best use of Clojure namespaces? Any advice much appreciated, Stu user= (ns math (:refer-clojure :rename {vector cvector})) nil math= vector java.lang.Exception: Unable to resolve symbol: vector in this context (NO_SOURCE_FILE:0) math= (def vector identity) #'math/vector math= (vector 10) 10 math= (cvector 10) [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
Re: setup and propagation of config-params
thanks ken for the answer. more(?) functional using closures: (defn get-config [environment] (let [env (condp = environment :development { :whoami development} :test { :whoami test} :production { :whoami production} (throw (IllegalArgumentException. (str unexpected environment: environment] (fn [keyword] (get env keyword (def config (get-config :development)) (binding [config (get-config :test)] (println (config :whoami))) -- 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 this function be simpler?
Hi, here something different. But also using the ugly butlast and last. user= (defn enmap [ args] (assoc-in {} (butlast args) (last args))) #'user/enmap user= (enmap 1 2 3 4 {5 6 7 8}) {1 {2 {3 {4 {5 6, 7 8} Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: setup and propagation of config-params
Dynamic binding is more useful when your function expect the *var* to change during the program. And sometimes you can't pass arguments through, like in (run-tests). How about a simple API with this usage: (set-opt :development) ; this is what you want ... (get-opt :show-sql) ; need this flag This is like getting a sys property: it is what it is and your function is pure with regard to the args and the global state: (System/ getenv HOME) ; c:/ On Mar 10, 2:07 pm, faenvie faen...@googlemail.com wrote: thanks ken for the answer. more(?) functional using closures: (defn get-config [environment] (let [env (condp = environment :development { :whoami development} :test { :whoami test} :production { :whoami production} (throw (IllegalArgumentException. (str unexpected environment: environment] (fn [keyword] (get env keyword (def config (get-config :development)) (binding [config (get-config :test)] (println (config :whoami))) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Why does this break memoization?
Hi all, I'm struggeling with some really strange problem. I have a function `p-apply', which can be used find all reachable vertices in a graph matching a regular expression modeled as nested vector of functions, to which the results are chained through. Here's an example call: (p-apply v1 [p-seq -- -- [p-alt -- [p-+ [-- :cls 'Foo) That means, starting from v1 you first have to traverse 2 outgoing edges, and then you may either traverse an aggregation from part to whole side, or you may iterate one or many outgoing edges of type Foo. Sometimes, memoization can bring a performance win, so I use a global var with a macro to dispatch to internal p-apply functions. Here's the relevant parts of the code. You can basically jump to the last function. --8---cut here---start-8--- (def ^{:private true} *memoize-path-eval* false) (defn- p-apply-normal [v p] (cond ;; funs -- (fn? p) (p v) ;; funs with params [-- :cls 'Foo] (coll? p) (apply (first p) v (next p)) ;; adjacences / role names (or (string? p) (keyword? p) (symbol? p)) (let [vs (into-oset v)] (apply into-oset (map #(adjacences % p) vs))) :else (throw (RuntimeException. (format Don't know how to apply %s. p) (def ^{:private true} p-apply-memoized (memoize p-apply-normal)) (defmacro with-path-eval-memoization [ body] `(binding [*memoize-path-eval* true] ~@body)) (defn- p-apply-internal [v p] (if *memoize-path-eval* (let [vs (into-oset v) r (map #(p-apply-memoized % p) vs)] (if (seq r) (apply into-oset r) (ordered-set))) (p-apply-normal v p))) (defn p-apply [v p] (let [counter (atom -1)] (p-apply-internal v ;;; Using p with metadata somehow makes things SLOW ;(clojure.walk/postwalk #(if (fn? %) ; (with-meta % {:state (swap! counter inc)}) ; %) p) ;;; using just p is FAST p ))) --8---cut here---end---8--- Because I'd like to extend the search to collect also the shortest paths to all reachable vertices that conform the given regular expression, I wanted to put metadata on the function symbols that are given to `p-apply'. But as soon as I comment `p' and uncomment the `postwalk' call returning `p' with metadata on the function symbols, memoization seems to stop working. With the code above (`p' passed to `p-apply-internal'), I get these timings with memoization turned on: With memoization cbo-q-sequential Elapsed time: 6805.37119 msecs cbo-q-parallel Elapsed time: 212.276041 msecs With memoization 2 == cbo-q-sequential Elapsed time: 178.102362 msecs cbo-q-parallel Elapsed time: 172.027562 msecs So the first function, which in effect fills the memoization cache and doesn't much benefit from it itself runs ~7 secs, but repeating the queries is lightning fast. If I comment `p' and pass it first through `postwalk' to put metadata on the functions, then the timings are these: With memoization cbo-q-sequential Elapsed time: 8247.753366 msecs cbo-q-parallel Elapsed time: 8962.930698 msecs With memoization 2 == cbo-q-sequential Elapsed time: 11010.302911 msecs cbo-q-parallel Elapsed time: 9098.196259 msecs What's the matter? Why does it get that slow only because of metadata? Bye, Tassilo -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Why does this break memoization?
Adding metadata to an object produces a new object, rather than altering the existing object. Every time you increment the counter for a function in p it becomes different, and the memoize treats it as new. That is, p-apply-memoized takes parameters p and v. Your post-walk over p replacing functions with copies with changed metadata changes p: user= (def q (fn [x] (inc x))) #'user/q user= (= q (with-meta q {:foo true})) false Since functions have object identity for =, and adding metadata changes object identity, the function is not = to its meta-added self -- and that means a collection containing the function also is not = to a copy produced using post-walk and meta-izing functions in the collection, and that means a data structure built of collections and containing functions and post-walked to meta-ize the functions is not = to its un-metaized self. So, each time p-apply-memoized gets called with the same p, because all the counters have been bumped, it's not actually the same p as far as memoize is concerned, and so you don't get the benefits of memoization anymore. Solution: don't mess with the function metadata. Instead, use a global map from fns to counts, or something. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Why does this break memoization?
Functions can only be compared by identity, not value, eg (not= (constantly 1) (constantly 1)). When you attach metadata to a function, you cause it to no longer be = to other non-meta instances of that function, so memoize can no longer use previous values. user= (def mp (memoize println)) #'user/mp user= (def x (constantly 1)) #'user/x user= (mp x) #core$constantly$fn__3551 clojure.core$constantly$fn__3551@11e31ea nil user= (mp x) nil user= (mp (with-meta x {:x 1})) #core$constantly$fn__3551 clojure.core$constantly$fn__3551@507369 nil user= (mp (with-meta x {:x 1})) #core$constantly$fn__3551 clojure.core$constantly$fn__3551@1d71e34 nil user= (mp (with-meta x {:x 1})) #core$constantly$fn__3551 clojure.core$constantly$fn__3551@1fac733 nil Note that the printed representation of the function is changing, too: it has a different @address because it is a new object with different metadata. On Mar 10, 3:33 pm, Tassilo Horn tass...@member.fsf.org wrote: Hi all, I'm struggeling with some really strange problem. I have a function `p-apply', which can be used find all reachable vertices in a graph matching a regular expression modeled as nested vector of functions, to which the results are chained through. Here's an example call: (p-apply v1 [p-seq -- -- [p-alt -- [p-+ [-- :cls 'Foo) That means, starting from v1 you first have to traverse 2 outgoing edges, and then you may either traverse an aggregation from part to whole side, or you may iterate one or many outgoing edges of type Foo. Sometimes, memoization can bring a performance win, so I use a global var with a macro to dispatch to internal p-apply functions. Here's the relevant parts of the code. You can basically jump to the last function. --8---cut here---start-8--- (def ^{:private true} *memoize-path-eval* false) (defn- p-apply-normal [v p] (cond ;; funs -- (fn? p) (p v) ;; funs with params [-- :cls 'Foo] (coll? p) (apply (first p) v (next p)) ;; adjacences / role names (or (string? p) (keyword? p) (symbol? p)) (let [vs (into-oset v)] (apply into-oset (map #(adjacences % p) vs))) :else (throw (RuntimeException. (format Don't know how to apply %s. p) (def ^{:private true} p-apply-memoized (memoize p-apply-normal)) (defmacro with-path-eval-memoization [ body] `(binding [*memoize-path-eval* true] ~@body)) (defn- p-apply-internal [v p] (if *memoize-path-eval* (let [vs (into-oset v) r (map #(p-apply-memoized % p) vs)] (if (seq r) (apply into-oset r) (ordered-set))) (p-apply-normal v p))) (defn p-apply [v p] (let [counter (atom -1)] (p-apply-internal v ;;; Using p with metadata somehow makes things SLOW ;(clojure.walk/postwalk #(if (fn? %) ; (with-meta % {:state (swap! counter inc)}) ; %) p) ;;; using just p is FAST p ))) --8---cut here---end---8--- Because I'd like to extend the search to collect also the shortest paths to all reachable vertices that conform the given regular expression, I wanted to put metadata on the function symbols that are given to `p-apply'. But as soon as I comment `p' and uncomment the `postwalk' call returning `p' with metadata on the function symbols, memoization seems to stop working. With the code above (`p' passed to `p-apply-internal'), I get these timings with memoization turned on: With memoization cbo-q-sequential Elapsed time: 6805.37119 msecs cbo-q-parallel Elapsed time: 212.276041 msecs With memoization 2 == cbo-q-sequential Elapsed time: 178.102362 msecs cbo-q-parallel Elapsed time: 172.027562 msecs So the first function, which in effect fills the memoization cache and doesn't much benefit from it itself runs ~7 secs, but repeating the queries is lightning fast. If I comment `p' and pass it first through `postwalk' to put metadata on the functions, then the timings are these: With memoization cbo-q-sequential Elapsed time: 8247.753366 msecs cbo-q-parallel Elapsed time: 8962.930698 msecs With memoization 2 == cbo-q-sequential Elapsed time: 11010.302911 msecs cbo-q-parallel Elapsed time: 9098.196259 msecs What's the matter? Why does it get that slow only because of metadata? Bye, Tassilo -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at
clojure.string/replace-first return nil when not matched
Hi, I have two questions about clojure.string/replace-first. 1. Is this expected behavior of replace-first? (require '[clojure.string :as str]) (str/replace-first abc def #ghi (fn [a] (str a a))) = nil I don't think so, because string / string argument version returns original string when mismatched. (str/replace-first abc def ghi jkl) = abc def 2. Is it difficult that replace-first support argument of string / function besides regex / function (i.e. without using Pattern/quote)? (str/replace-first abc def def (fn [a] (str a a))) = abc defdef The reason why I'd like to avoid using Pattern/quote is that ,I think, to replace string with string should be more lightweight than with regex. Thanks. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Comparing clojure speed to java speed
I've been benchmarking java and clojure programs and wanted to make sure I was doing this right. I made two fairly similar programs that manipulated Vec2 objects from the JBox2D library. At first clojure was performing pretty poorly, then I tried compiling my clojure script, and then replacing the inner doseq with a loop. But java is still 5x faster and I hear that clojure should be able to run as fast as java and I wondered if there's any options in clojure I'm not using Java: package test; import org.jbox2d.common.Vec2; public class Main { static long w = 0; public static void main(String[] args) { for(int q = 0;q 5;q++){ Vec2 a = new Vec2(1, 2), b = new Vec2(3, 4); long start = System.currentTimeMillis(); for(int d = 0;d 1e9;d++){ a.addLocal(b); } long stop = System.currentTimeMillis(); System.out.println((stop - start)/1000.0); } } } Clojure: (ns hello.test (import org.jbox2d.common.Vec2) (:gen-class)) (defn -main [ args] (doseq [q (range 5)] (let [a (Vec2. 1 2) b (Vec2. 3 4)] (time (loop [x (int 0)] (when ( x 1e9) (.addLocal a b) (recur (unchecked-inc x Vec2(if anyone cares): http://code.google.com/p/jbox2d/source/browse/trunk/jbox2d/src/org/jbox2d/common/Vec2.java -- 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: Comparing clojure speed to java speed
I should readjust my 5x statement, it's more like 2.25x. On Mar 10, 8:39 pm, Jarl Haggerty jarlhagge...@gmail.com wrote: I've been benchmarking java and clojure programs and wanted to make sure I was doing this right. I made two fairly similar programs that manipulated Vec2 objects from the JBox2D library. At first clojure was performing pretty poorly, then I tried compiling my clojure script, and then replacing the inner doseq with a loop. But java is still 5x faster and I hear that clojure should be able to run as fast as java and I wondered if there's any options in clojure I'm not using Java: package test; import org.jbox2d.common.Vec2; public class Main { static long w = 0; public static void main(String[] args) { for(int q = 0;q 5;q++){ Vec2 a = new Vec2(1, 2), b = new Vec2(3, 4); long start = System.currentTimeMillis(); for(int d = 0;d 1e9;d++){ a.addLocal(b); } long stop = System.currentTimeMillis(); System.out.println((stop - start)/1000.0); } } } Clojure: (ns hello.test (import org.jbox2d.common.Vec2) (:gen-class)) (defn -main [ args] (doseq [q (range 5)] (let [a (Vec2. 1 2) b (Vec2. 3 4)] (time (loop [x (int 0)] (when ( x 1e9) (.addLocal a b) (recur (unchecked-inc x Vec2(if anyone cares): http://code.google.com/p/jbox2d/source/browse/trunk/jbox2d/src/org/jb... -- 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: Comparing clojure speed to java speed
Try typehinting the a and b in the let. -- 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: Idiomatic way to handle name shadowing?...
On Mar 11, 8:35 am, Alan a...@malloys.org wrote: Suppose I need mathematical 2D vector functions: (ns geometry.vector) (defstruct vector :x :y) (defn + Add vectors v and w, yielding a vector [ v w ] (...)) Which leads to the core vector function being shadowed by my struct and the core + function shadowed by my function. What is the idiomatic Clojure approach for handling this situation? Is it through careful use of :require and :import parts of a (ns ...) form? user= (ns math (:refer-clojure :rename {vector cvector})) nil math= vector java.lang.Exception: Unable to resolve symbol: vector in this context (NO_SOURCE_FILE:0) math= (def vector identity) #'math/vector math= (vector 10) 10 math= (cvector 10) [10] Thanks for that -- please bear with me on this: does that mean that given the flexible options available in the (ns...) form as shown here, Clojure developers don't need to choose non-shadowed names like vector or (defn vector+), but rather use the more natural forms and use (ns...) clauses to make everything clear as needed? Thanks, Stu -- 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: Comparing clojure speed to java speed
On Thu, Mar 10, 2011 at 10:39 PM, Jarl Haggerty jarlhagge...@gmail.comwrote: I've been benchmarking java and clojure programs and wanted to make sure I was doing this right. I made two fairly similar programs that manipulated Vec2 objects from the JBox2D library. At first clojure was performing pretty poorly, then I tried compiling my clojure script, and then replacing the inner doseq with a loop. But java is still 5x faster and I hear that clojure should be able to run as fast as java and I wondered if there's any options in clojure I'm not using Try replacing doseq w/ dotimes. You need to cast 1e9 to int, just like you do w/ 0 if you're using Clojure = 1.2.0. How long is it taking for you in Clojure and Java? David -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Comparing clojure speed to java speed
On Thu, Mar 10, 2011 at 10:39 PM, Jarl Haggerty jarlhagge...@gmail.comwrote: I've been benchmarking java and clojure programs and wanted to make sure I was doing this right. I made two fairly similar programs that manipulated Vec2 objects from the JBox2D library. At first clojure was performing pretty poorly, then I tried compiling my clojure script, and then replacing the inner doseq with a loop. But java is still 5x faster and I hear that clojure should be able to run as fast as java and I wondered if there's any options in clojure I'm not using Try: (ns box2d.core (import org.jbox2d.common.Vec2) (:gen-class)) (defn -main [ args] (dotimes [_ 5] (let [a (Vec2. 1 2) b (Vec2. 3 4)] (time (dotimes [x 1e9] (.addLocal a b)) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: clojure.string/replace-first return nil when not matched
1. The Clojure wrapper put the last two calls inside the if, unlike Matcher#replaceFirst(), thus the nil. public String replaceFirst(String replacement) { if (replacement == null) throw new NullPointerException(replacement); StringBuffer sb = new StringBuffer(); reset(); if (find()) appendReplacement(sb, replacement); appendTail(sb); return sb.toString(); } (defn- replace-first-by [^CharSequence s ^Pattern re f] (let [m (re-matcher re s)] (let [buffer (StringBuffer. (.length s))] (if (.find m) (let [rep (f (re-groups m))] (.appendReplacement m buffer rep) (.appendTail m buffer) (str buffer)) On Mar 10, 4:39 pm, Takahiro Hozumi fat...@googlemail.com wrote: Hi, I have two questions about clojure.string/replace-first. 1. Is this expected behavior of replace-first? (require '[clojure.string :as str]) (str/replace-first abc def #ghi (fn [a] (str a a))) = nil I don't think so, because string / string argument version returns original string when mismatched. (str/replace-first abc def ghi jkl) = abc def 2. Is it difficult that replace-first support argument of string / function besides regex / function (i.e. without using Pattern/quote)? (str/replace-first abc def def (fn [a] (str a a))) = abc defdef The reason why I'd like to avoid using Pattern/quote is that ,I think, to replace string with string should be more lightweight than with regex. Thanks. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Comparing clojure speed to java speed
Hmm, I should have thought of that. New Clojure: (ns hello.test (import org.jbox2d.common.Vec2) (:gen-class)) (defn -main [ args] (dotimes [q 5] (let [#^Vec2 a (Vec2. 1 2) #^Vec2 b (Vec2. 3 4)] (time (loop [x (int 0)] (when ( x (int 1e9)) (.addLocal a b) (recur (unchecked-inc x Old Clojure Output: Elapsed time: 11437.687558 msecs Elapsed time: 10863.527399 msecs Elapsed time: 11863.44317 msecs Elapsed time: 11861.23116 msecs Elapsed time: 11870.92791 msecs New Clojure Output: Elapsed time: 2492.033705 msecs Elapsed time: 1489.316185 msecs Elapsed time: 1484.606724 msecs Elapsed time: 1480.983085 msecs Elapsed time: 1486.435446 msecs This is the result of the Java code I posted, Java Output: 2.263 4.471 4.484 4.452 4.409 I thought it was strange that the first iteration ran so fast, so I changed 1e9 to (int)1e9 and the speed got better, but I still wonder why the first iteration before was so fast, the JIT is supposed to make it faster isn't it? Old Java Output: 1.513 1.495 1.96 1.47 1.475 On Mar 10, 9:04 pm, David Nolen dnolen.li...@gmail.com wrote: On Thu, Mar 10, 2011 at 10:39 PM, Jarl Haggerty jarlhagge...@gmail.comwrote: I've been benchmarking java and clojure programs and wanted to make sure I was doing this right. I made two fairly similar programs that manipulated Vec2 objects from the JBox2D library. At first clojure was performing pretty poorly, then I tried compiling my clojure script, and then replacing the inner doseq with a loop. But java is still 5x faster and I hear that clojure should be able to run as fast as java and I wondered if there's any options in clojure I'm not using Try replacing doseq w/ dotimes. You need to cast 1e9 to int, just like you do w/ 0 if you're using Clojure = 1.2.0. How long is it taking for you in Clojure and Java? David -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Idiomatic way to handle name shadowing?...
On Mar 10, 8:04 pm, stu stuart.hungerf...@gmail.com wrote: On Mar 11, 8:35 am, Alan a...@malloys.org wrote: Suppose I need mathematical 2D vector functions: (ns geometry.vector) (defstruct vector :x :y) (defn + Add vectors v and w, yielding a vector [ v w ] (...)) Which leads to the core vector function being shadowed by my struct and the core + function shadowed by my function. What is the idiomatic Clojure approach for handling this situation? Is it through careful use of :require and :import parts of a (ns ...) form? user= (ns math (:refer-clojure :rename {vector cvector})) nil math= vector java.lang.Exception: Unable to resolve symbol: vector in this context (NO_SOURCE_FILE:0) math= (def vector identity) #'math/vector math= (vector 10) 10 math= (cvector 10) [10] Thanks for that -- please bear with me on this: does that mean that given the flexible options available in the (ns...) form as shown here, Clojure developers don't need to choose non-shadowed names like vector or (defn vector+), but rather use the more natural forms and use (ns...) clauses to make everything clear as needed? Thanks, Stu You can write whichever will make your library easier to use and understand. But do realize if you define something called +, and someone needs to use your library as well as clojure.core, you are forcing every user of your library to make a decision about how to handle the renaming. Arguably this is better than naming it mathy- vector; that would mean clients don't have to deal with renames, but it also means it would be harder for them to use your library, or read code someone *else* wrote using your library with different renames. It's all a tradeoff, just like everything: the best we can do is tell you what tools and options you have and let you decide. -- 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