Re: Do I need to add dosync when I read the ref in this case
On 21 February 2010 09:24, ataggart alex.tagg...@gmail.com wrote: On Feb 20, 6:07 am, Jack Fang jack.fang1...@gmail.com wrote: Suppose the transfer-money and print-info are run in different thread. With the current Clojure STM, is it possible that print-info prints the old source-account information and modified dest-account information? Yes. Do I need to add a dosync to the print-info function? I read the Programming Clojure. It says do not have side-effect on a transaction. If you want consistent results between refs, you'll need to be in a transaction, thus dosync. You might also need to use ensure, but I'm not certain. The reason side-effects are discouraged (not forbidden) is because a transaction may be run multiple times, thus you might get multiple printouts. If I add dosync to the print-info, do I need to use agent Agents are desgned to be used for side-effects in a transaction. That's why sends to an agent are held and only actually happen if the tx commits. It mIght be overkill for your examle, but yes send ensured/altered values to an agent from inside a dosync block. to print the info? But surely in this case you could do: (defn print-info [] (let [[src dst] (dosync [...@source-account @dest-account])] (println src) (println dst))) or maybe: (defn print-info [] (let [[src dst] (dosync (ensure source-account) (ensure dest-account) [...@source-account @dest-account])] (println src) (println dst))) I suspect the ensures are necessary, but I would appreciate it if someone could explain why they are (or are not) necessary in this case. Thanks. -- Michael Wood esiot...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Do I need to add dosync when I read the ref in this case
But surely in this case you could do: (defn print-info [] (let [[src dst] (dosync [...@source-account @dest-account])] (println src) (println dst))) or maybe: (defn print-info [] (let [[src dst] (dosync (ensure source-account) (ensure dest-account) [...@source-account @dest-account])] (println src) (println dst))) I suspect the ensures are necessary, but I would appreciate it if someone could explain why they are (or are not) necessary in this case. As far as I know, dosync guarantees that the derefs are consistent with each other. That is, no other transaction can affect the return value of the deref while the transaction is running. However, deref doesn't guarantee that the values read are still current when the transaction finishes. Some other transaction might have been committed first. If you absolutely need the most recent values, not just consistent ones, you need to use ensure. -- 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: Do I need to add dosync when I read the ref in this case
On 21 February 2010 09:37, Michael Wood esiot...@gmail.com wrote: (defn print-info [] (let [[src dst] (dosync (ensure source-account) (ensure dest-account) �...@source-account @dest-account])] (println src) (println dst))) This can be simplified to (defn print-info [] (let [[src dst] (dosync [(ensure source-account) (ensure dest-account)])] (println src) (println dst))) ensure returns the in-trasaction value of the ref. There's no guarantee that the refs won't be changed a split second after the transaction, of course... To demonstrate the difference between a simple @r and (ensure r) in a transaction, define the following ref function at the REPL: (def r (ref 1)) (defn funk [r] (dosync (let [v (ensure r)] (println v) (Thread/sleep 5000) (println v Now launch it in a separate thread: (.start (Thread. #(funk r))) It'll print a 1 straight away, but you'll have a moment to type in another expression before it proceeds with the second println. So, do this: (dosync (ref-set r 5)) Notice that this blocks until the second println happens, then resets the value of the ref afterwards. With (ensure r) replaced by @r in the definition of funk, the (dosync (ref-set r 5)) would succeed and the funky transaction would retry, thus performing three printlns in total. Thus using ensure may actually make in-transaction side-effects safe at the cost of some lost concurrency. Sincerely, Michał -- 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 on Go
Hi people! Clojure could be compiled over another language, using another base library. This could be the litmut test for Clojure independence. I guess Clojure-CLR is an step towards such target. For now, Clojure consumes two library classes and VM: Java and .NET. It's good, IMO, to have such two implementations. When Clojure will stabilized in both, it will be more clear what part of the language is: - Clojure-pure - VM-oriented - Base Library-oriented If someone want to implement Clojure over another OO VM + Library Class, he/she should rewrite the dot notation, and map PersistenceList, etc... to the underlying class library. If someone want to implement Clojure over a language, I guess he/she should write some interface to native DLLs, and ways to insert code written in the underlying language in the middle of a function, and write the supporting classes for Clojure structures. Having the two kind implementations: - Clojure over VM+Class Library (Java, CLR) - Clojure over Language (?) will be enlightning about what is the core, base, and technicalities of any Clojure port. I'm playing porting Clojure to .NET as interpreter (I don't know enough DLR to write a compiler or contribute to Clojure-CLR, I hope this state of affairs will change this year). Angel Java Lopez http://www.ajlopez.com http://twitter.com/ajlopez On Sat, Feb 20, 2010 at 6:15 PM, Chouser chou...@gmail.com wrote: On Sat, Feb 20, 2010 at 3:59 PM, Joop Kiefte iko...@gmail.com wrote: I read this part... http://www.reddit.com/r/programming/comments/b3sb1/golisp_a_lisp_interpreter_in_go/ and thought, would someone be able to do that for clojure? (the Clojure in Clojure stuff might make this easier :)) Is this a weird idea? Clojure supports compilation, so might as go all the way and have add a golang target to complie Clojure code directly to golang code. Not a weird idea at all. :-) I like a lot of ideas in go, and it's speed, but Clojure is just some bits nicer. When we have clojure on go, we can have compiled clojure without java runtime and fast, can't we? I don't know if you'll get better runtime speed out of golang or not, but I bet you'd get much better startup speed, and for some use cases that's highly desirable. It sure has advantages, and as a toy project it might be cool. And most of Clojure's code is in clojure anyway, so that eases porting I guess. Here I'm afraid you may be disappointed. Currently all of Clojure's reader, compiler, persistent data structures (vector, list, maps, queues, and sets), reference types (refs, agents, vars, etc.), and much of the support code (STM, namespaces, etc.) are all written almost entirely in Java. This is already beginning to change (see Rich's recent work on cells and generic vectors), but there's quite a ways to go yet. When that work is done, compiling Clojure to golang might indeed be a fun project. --Chouser http://joyofclojure.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.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Do I need to add dosync when I read the ref in this case
On 21 February 2010 12:55, Jarkko Oranen chous...@gmail.com wrote: But surely in this case you could do: (defn print-info [] (let [[src dst] (dosync [...@source-account @dest-account])] (println src) (println dst))) or maybe: (defn print-info [] (let [[src dst] (dosync (ensure source-account) (ensure dest-account) [...@source-account @dest-account])] (println src) (println dst))) I suspect the ensures are necessary, but I would appreciate it if someone could explain why they are (or are not) necessary in this case. As far as I know, dosync guarantees that the derefs are consistent with each other. That is, no other transaction can affect the return value of the deref while the transaction is running. However, deref doesn't guarantee that the values read are still current when the transaction finishes. Some other transaction might have been committed first. If you absolutely need the most recent values, not just consistent ones, you need to use ensure. OK, so ensure is not necessary in this case. Thanks. -- Michael Wood esiot...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Do I need to add dosync when I read the ref in this case
On 21 February 2010 13:47, Michał Marczyk michal.marc...@gmail.com wrote: On 21 February 2010 09:37, Michael Wood esiot...@gmail.com wrote: (defn print-info [] (let [[src dst] (dosync (ensure source-account) (ensure dest-account) �...@source-account @dest-account])] (println src) (println dst))) This can be simplified to (defn print-info [] (let [[src dst] (dosync [(ensure source-account) (ensure dest-account)])] (println src) (println dst))) ensure returns the in-trasaction value of the ref. Ah, thanks. There's no guarantee that the refs won't be changed a split second after the transaction, of course... Of course. To demonstrate the difference between a simple @r and (ensure r) in a transaction, define the following ref function at the REPL: (def r (ref 1)) (defn funk [r] (dosync (let [v (ensure r)] (println v) (Thread/sleep 5000) (println v Now launch it in a separate thread: (.start (Thread. #(funk r))) It'll print a 1 straight away, but you'll have a moment to type in another expression before it proceeds with the second println. So, do this: (dosync (ref-set r 5)) Notice that this blocks until the second println happens, then resets the value of the ref afterwards. With (ensure r) replaced by @r in the definition of funk, the (dosync (ref-set r 5)) would succeed and the funky transaction would retry, thus performing three printlns in total. That does demonstrate the difference (or a difference), but I don't get 3 printlns. I modified the printlns to distinguish between the two: (defn funk [r] (dosync (let [v @r] (println Start: v) (Thread/sleep 5000) (println End: v I assume you were expecting something like: user= (.start (Thread. #(funk r))) Start: 1 nil user= (dosync (ref-set r 5)) 5 user= Start: 5 End: 5 ? What I see is: user= (.start (Thread. #(funk r))) Start: 1 nil user= (dosync (ref-set r 5)) 5 user= End: 1 This is with Clojure 1.2.0-master-SNAPSHOT (2855e34106b2cacd4614f2b7e31f1536b4b849bc) Thus using ensure may actually make in-transaction side-effects safe at the cost of some lost concurrency. -- Michael Wood esiot...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Do I need to add dosync when I read the ref in this case
On 21 February 2010 14:13, Michael Wood esiot...@gmail.com wrote: That does demonstrate the difference (or a difference), but I don't get 3 printlns. Ouch, I actually posted the wrong version of the function. Here's an improvement in the context of a REPL interaction: 1. ensure version: user (defn funk [r] (dosync (println (ensure r)) (Thread/sleep 5000) (println (ensure r #'user/funk user (def r (ref 1)) #'user/r user (.start (Thread. #(funk r))) 1 nil user (dosync (ref-set r 5)) 1 5 2. deref version: user (defn funk [r] (dosync (println @r) (Thread/sleep 5000) (println @r))) #'user/funk user (def r (ref 1)) #'user/r user (.start (Thread. #(funk r))) 1 nil user (dosync (ref-set r 5)) 5 5 5 Note how the deref version prints more lines (because it retries the transaction). I'm using a newer commit (49a7d6b8e14050a45df5332e768ba6647752215d), but this shouldn't make any difference. Sincerely, Michał -- 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: Do I need to add dosync when I read the ref in this case
You do not have to. Everything inside your dosync-block will happen atomically, meaning print-info will either see the values of source-account and dest-account before your transaction happened or after it's done his work. -- Ph. Siegmantel 2010/2/20 Jack Fang jack.fang1...@gmail.com Hi,all I am new to clojure. Now I hava a problem about read transcation. Suppose now I write some code about bank transfer. So this is the source-account and destination-account //The code (def source-account (ref 1000)) (def dest-account (ref 0)) And I have a function to do the account transfer. //The code (defn take-money [account num] (- account num)) (defn despoite [account num] (+ account num)) (defn transfer-money [num] (dosync (alter source-account take-money num) (alter dest-account despoite num))) And I have a another function to print the source account and dest acoount information. //The code (defn print-info [] (do (println @source-account) (println @dest-account))) Suppose the transfer-money and print-info are run in different thread. With the current Clojure STM, is it possible that print-info prints the old source-account information and modified dest-account information? Do I need to add a dosync to the print-info function? I read the Programming Clojure. It says do not have side-effect on a transaction. If I add dosync to the print-info, do I need to use agent to print the info? Hope somebody can help me. Thank. Jack -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
generalize distinct
Hi, Clojure is great! The gain in productivity from more low level languages like Java, but also more functional languages like Ruby and Common LISP etc. amazes me every day. Like how adding a simple map in front of the count here: (count colls) changes the code from counting the number of collections to enumerating the number of items in those collections. It's all these little things that take one minute or 5 in Java, but only 5 seconds in Clojure (in case you are a slow typer) that make you so much more efficient. With clojure, I spend most of my time thinking about problems at a conceptual level, rather than at the implementation level (Java: int[] vs. IterableInteger vs. ListInteger vs. Integer[] etc. - arrg!). Thanks Rich! That said, every now and then I come across a function in clojure.core that could be vastly improved in its range of applicability by just adding one or more optional parameters, defaulting to the currently hard-coded values (like the often implicit 'identity' function). Take 'distinct'. I'd like to be able to specify the keyfn, that's an important one for me, and while we're at it, I'd like to pass in the set that that function builds up incrementally, and normally starts with an empty set, so that I can pre-initialize it, say with #{ nil }, so that it also filters out nils. This 2nd point is not that important, and I'm not sure if it is that great an idea in terms of orthogonality of the functions, as we have filter. But you'd get rid off one level of indirection. distinct basically gives us a filter for free. But the 1st point I think certainly makes sense, and we have a couple of other fns in clojure that have a variant with a keyfn parameter, like sort-by etc. I guess they normally get a different name. I'm not so sure about what the best order of parameters is in clojure, and named parameters would make this a no brainer, but this is what I currently use, the first parameter being coll, at least in the variant with only one parameter that makes it a drop-in replacement candidate for distinct: (defn distinkt Returns a lazy sequence of the elements of coll with duplicates removed ([coll] (distinkt coll identity)) ([coll keyfn] (distinkt coll keyfn #{})) ([coll keyfn seen-items] (let [step (fn step [xs seen] (lazy-seq ((fn [[f :as xs] seen] (when-let [s (seq xs)] (let [key (keyfn f)] (if (contains? seen key) (recur (rest s) seen) (cons f (step (rest s) (conj seen key))) xs seen)))] (step coll seen-items I don't mind writing - or better - copy-and-pasting this code and keeping it in my project, but I think it could be useful for others, so I wouldn't mind at all if this makes it into clojure.core... :) Or is the reason for hard coding an (implicit) 'identity' performance? Or did I miss some other way to achieve the same goal? Eugen -- 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
Major changes in ClojureX
I hope these mails don't annoy people, but from mails and Twitter I know that quite a few people actually seem to be using ClojureX, so I also wanted to post the information here: http://citizen428.net/archives/415-Major-changes-in-ClojureX.html Cheers, Michael -- 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: Simplenote Desktop App in Clojure
On Feb 20, 10:02 pm, Kasim ktu...@gmail.com wrote: Hi, I am a web developer and would like to write a small Desktop UI application in Clojure for the popular Simplenote app.http://simplenoteapp.com/ I was wondering what UI framework I should use. Anyone out there care to suggest one that works best with Clojure? Swing is certainly the default, most commonly used and well supported (see swing-utils and miglayout at http://richhickey.github.com/clojure-contrib/). That said, people seem to have used SWT and even Qt Jambi in Clojure with some success. Best Regards, Joonas -- 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: Do I need to add dosync when I read the ref in this case
I try my code on my machine. 1. deref version (defn funk [r] (dosync (println Start: @r) (Thread/sleep 1) (println End: @r))) user (.start (Thread. #(funk r))) Start: 1 nil user (dosync (ref-set r 5)) Start: 5 End: 5 5 Actually, when I type in (dosync (ref-set r 5)), I got 5 soon. After a few seconds, it prints out the Start: 5. And after another few seconds, print out End: 5. So yes, the funk transcation is redone. 2. Ensure version (defn funk [r] (dosync (println Start: (ensure r)) (Thread/sleep 1) (println End: (ensure r user (.start (Thread. #(funk r))) Start: 1 nil useruser (dosync (ref-set r 5)) End: 1 5 When I type in the (dosync (ref-set r 5)), that transcation was blocked. So it is run after the funk finished. So I can guess that, If you use deref, there can be multipule transcation running at once. But sometimes transcation must be rerun. If you use ensure, only one transcation is run. Others are blocked. Is it true? Thanks for all your help! Sincerely, Jack On 2月21日, 下午10时26分, Michał Marczyk michal.marc...@gmail.com wrote: On 21 February 2010 14:13, Michael Wood esiot...@gmail.com wrote: That does demonstrate the difference (or a difference), but I don't get 3 printlns. Ouch, I actually posted the wrong version of the function. Here's an improvement in the context of a REPL interaction: 1. ensure version: user (defn funk [r] (dosync (println (ensure r)) (Thread/sleep 5000) (println (ensure r #'user/funk user (def r (ref 1)) #'user/r user (.start (Thread. #(funk r))) 1 nil user (dosync (ref-set r 5)) 1 5 2. deref version: user (defn funk [r] (dosync (println @r) (Thread/sleep 5000) (println @r))) #'user/funk user (def r (ref 1)) #'user/r user (.start (Thread. #(funk r))) 1 nil user (dosync (ref-set r 5)) 5 5 5 Note how the deref version prints more lines (because it retries the transaction). I'm using a newer commit (49a7d6b8e14050a45df5332e768ba6647752215d), but this shouldn't make any difference. Sincerely, Michał -- 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: Do I need to add dosync when I read the ref in this case
Thanks for you all On 2月21日, 下午10时26分, Michał Marczyk michal.marc...@gmail.com wrote: On 21 February 2010 14:13, Michael Wood esiot...@gmail.com wrote: That does demonstrate the difference (or a difference), but I don't get 3 printlns. Ouch, I actually posted the wrong version of the function. Here's an improvement in the context of a REPL interaction: 1. ensure version: user (defn funk [r] (dosync (println (ensure r)) (Thread/sleep 5000) (println (ensure r #'user/funk user (def r (ref 1)) #'user/r user (.start (Thread. #(funk r))) 1 nil user (dosync (ref-set r 5)) 1 5 2. deref version: user (defn funk [r] (dosync (println @r) (Thread/sleep 5000) (println @r))) #'user/funk user (def r (ref 1)) #'user/r user (.start (Thread. #(funk r))) 1 nil user (dosync (ref-set r 5)) 5 5 5 Note how the deref version prints more lines (because it retries the transaction). I'm using a newer commit (49a7d6b8e14050a45df5332e768ba6647752215d), but this shouldn't make any difference. Sincerely, Michał -- 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: Major changes in ClojureX
Michael Kohl wrote: I hope these mails don't annoy people, but from mails and Twitter I know that quite a few people actually seem to be using ClojureX, so I also wanted to post the information here: http://citizen428.net/archives/415-Major-changes-in-ClojureX.html Cheers, Michael Hi, I tried running ClojureX scripts under cygwin, but this what I get: $ bin/create_symlink Creating symlink /usr/local/bin/clj... bin/create_symlink: line 13: syntax error: unexpected end of file br...@wynn6266448332 /cygdrive/c/clojure/clojurex/clojurex $ ./clj ./clj: line 11: $'\r': command not found ./clj: line 13: syntax error near unexpected token `$'{\r'' '/clj: line 13: `avail() { Thanks Brian -- 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
Montreal Clojure User Group
Would Montreal Clojurians be interested in starting a Clojure group? Or do you all piggyback on the Montreal/Scheme Lisp User Group? -- 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
Need advice on best concurrency model
Hi everyone, I've fiddled with making something concurrent and noticed I horribly failed. It gets 2-3 times slower when trying to work using pmap instead of map. What I want to do: I am working on a game, I have units, and a map fields (x,y coordinates). Now in every game turn each unit is allowed to act (move, update itself's status or interact with another unit). Doing this non parallel isn't a problem and works quite well. The concurrency model I chose is: Each unit is in a ref: (so if a unit updates itself and another unit is interacting with it the transaction fails and is redone - can't happen that a unit interacts with a unit and uses a wrong state of the unit). This seems to be quite OK. The more challenging part is the map. My first attempt was to put the entire map in one big ref and represent it by a hashmap. As this looked quite risky in terms of rerun (if two units move at the same time, there is a rerun if I am not mistaken, even if they are not interacting at all). My second attempt was to put the map in a ref, then put each row in another ref (add them dynamically as needed) and the in there put each field in a ref. So if a unit moves from (0,0) to (0,1) for the first time the map is changed and a new row added to this row a new column is added. If it them moves back from (0,1) (0,0) only this two refs are changed and I hoped that no other units (that don't want to interact with (0,0) or (0,1) have to rerun) - sadly this got even slower. Now I'm slowly getting desperate and would like to ask what I am doing wrong. A few outlines: * I use pmap in to run units in parallel. * pmap is partitioned in 200 unit chunks (of 1k units total) * one turn for al 1k units takes with pmap 30s, without 10s * There can't be two units on the same field (so consistency and order of the moves on the map are important) * The units have their position stored, so if they interact they don't need the map to tell them they moved (redo when a concurrency problem occurs should be caused by the unit ref not the map ref) I'd be very thankful if I could get some advice here, sicne I am running out of ideas. Best regards and thanks an advance, Heinz. -- 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: Do I need to add dosync when I read the ref in this case
On 21 February 2010 15:26, Michał Marczyk michal.marc...@gmail.com wrote: On 21 February 2010 14:13, Michael Wood esiot...@gmail.com wrote: That does demonstrate the difference (or a difference), but I don't get 3 printlns. Ouch, I actually posted the wrong version of the function. Here's an improvement in the context of a REPL interaction: 1. ensure version: user (defn funk [r] (dosync (println (ensure r)) (Thread/sleep 5000) (println (ensure r #'user/funk user (def r (ref 1)) #'user/r user (.start (Thread. #(funk r))) 1 nil user (dosync (ref-set r 5)) 1 5 2. deref version: user (defn funk [r] (dosync (println @r) (Thread/sleep 5000) (println @r))) #'user/funk user (def r (ref 1)) #'user/r user (.start (Thread. #(funk r))) 1 nil user (dosync (ref-set r 5)) 5 5 5 Note how the deref version prints more lines (because it retries the transaction). Ah yes, that makes more sense :) Thanks again. I'm using a newer commit (49a7d6b8e14050a45df5332e768ba6647752215d), but this shouldn't make any difference. No, I only mentioned the commit I was using since I wasn't seeing what you said you saw. I wouldn't expect there to be a difference in how it works between versions 1.0, 1.1 and 1.2. -- Michael Wood esiot...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Major changes in ClojureX
On 21 February 2010 19:23, Brian Wolf brw...@gmail.com wrote: Michael Kohl wrote: I hope these mails don't annoy people, but from mails and Twitter I know that quite a few people actually seem to be using ClojureX, so I also wanted to post the information here: http://citizen428.net/archives/415-Major-changes-in-ClojureX.html Hi, I tried running ClojureX scripts under cygwin, but this what I get: $ bin/create_symlink Creating symlink /usr/local/bin/clj... bin/create_symlink: line 13: syntax error: unexpected end of file br...@wynn6266448332 /cygdrive/c/clojure/clojurex/clojurex $ ./clj ./clj: line 11: $'\r': command not found ./clj: line 13: syntax error near unexpected token `$'{\r'' '/clj: line 13: `avail() { Just a guess, but check the EOL characters in the script(s). -- Michael Wood esiot...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Newbie suggestion for an implementation - rosettacode pythagorean means
Hi everyone, being a newb to clojure, my ability to contribute to is still limited. However, I thought I'll try starting with something simple. http://rosettacode.org/wiki/Averages/Pythagorean_means seems straightforward enough, but since it's a comparative site, and implementations should be as idiomatic as possible, I would not post this implementation before some seasoned clojure programmers have a look. so here it is: (10 LOC only) http://github.com/lxmonk/pastes/blob/master/Pythagorean-means.clj obviously, ANY comments will be great (including: this is all wrong - don't post it). Thanks, Aviad -- 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: equality comparisons of finite and infinite collections?
false, of course. :-) What would the post-patch result be of that operation? On Feb 20, 10:25 am, Stuart Halloway stuart.hallo...@gmail.com wrote: Current results vary based on arg order: (def xes (iterate #(str % x) x)) = #'user/xes ; infinite first ok (= xes [x xx]) = false ; finite first boom (= [x xx] xes) = java.lang.OutOfMemoryError: Java heap space (NO_SOURCE_FILE:0) It looks as if this particular case could be fixed by checking for the clojure.lang.Counted interface in APersistentVector.doEquiv. Would a patch be welcome? 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 -- 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: Newbie suggestion for an implementation - rosettacode pythagorean means
On Sun, Feb 21, 2010 at 9:41 PM, Aviad Reich avi@gmail.com wrote: ANY comments will be great (including: this is all wrong - don't post it). FWIW since I'm not exactly an expert on idiomatic Clojure either, I'd write h-mean like this: (defn h-mean [coll] (/ (count coll) (apply + (map #(/ 1 %) coll Michael -- 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 Conference Dates
Have dates and location for the Clojure conference been picked? -- 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: Newbie suggestion for an implementation - rosettacode pythagorean means
I'm really new to Clojure, but I'm under the impression that reduce would be better than apply, since I assume that apply would reify the entire sequence at once, whereas reduce would consume the sequence one by one. Could someone more familiar with the implementation weigh in on this? On Feb 21, 2010, at 4:25 PM, Michael Kohl wrote: On Sun, Feb 21, 2010 at 9:41 PM, Aviad Reich avi@gmail.com wrote: ANY comments will be great (including: this is all wrong - don't post it). FWIW since I'm not exactly an expert on idiomatic Clojure either, I'd write h-mean like this: (defn h-mean [coll] (/ (count coll) (apply + (map #(/ 1 %) coll Michael -- 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: Need advice on best concurrency model
I'd be very thankful if I could get some advice here, sicne I am running out of ideas. You might be doing something wrong with the way you're arranging refs. I'll let others comment on that. One observation, though: parallelization doesn't always help. pmap runs your tasks on several threads. If your tasks are compute-bound and modifying a shared resource, you'll probably see a net slowdown thanks to coordination overhead, cache trampling, and contention. Imagine the worst case, where you have 1 or 2 processors (and thus pmap uses three or four threads), and each of the four threads takes a turn, contends for the same ref, maybe swaps out, makes a conflicting change and causes a transaction rerun, swaps out... Running serially removes both the risk of contention and the coordination overhead. In general: use pmap if you have a lot of processors that you want to use, or you're doing tasks that spend a lot of time waiting around (e.g., web crawling). For pure computation on small datasets and desktop quantities of processors -- like munging game state -- it's probably not worthwhile. -- 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: Newbie suggestion for an implementation - rosettacode pythagorean means
On Mon, Feb 22, 2010 at 12:18 AM, Johnny Kwan johnny.c.k...@gmail.com wrote: I'm really new to Clojure, but I'm under the impression that reduce would be better than apply, since I assume that apply would reify the entire sequence at once, whereas reduce would consume the sequence one by one. I was going by this: For certain functions, such as addition, they are the same, but that is because the addition function (+) itself 'reduces' its arguments. http://osdir.com/ml/java.clojure.user/2008-07/msg00237.htm The thread is somewhat older, but looking at the source for + it seems like this is still valid: user= (source +) (defn + Returns the sum of nums. (+) returns 0. {:inline (fn [x y] `(. clojure.lang.Numbers (add ~x ~y))) :inline-arities #{2}} ([] 0) ([x] (cast Number x)) ([x y] (. clojure.lang.Numbers (add x y))) ([x y more] (reduce + (+ x y) more))) Michael -- 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: generalize distinct
Any reason why you can't use distinct? http://richhickey.github.com/clojure/clojure.core-api.html#clojure.core/distinct On Feb 21, 2010 10:24 AM, Eugen Dueck eu...@dueck.org wrote: Hi, Clojure is great! The gain in productivity from more low level languages like Java, but also more functional languages like Ruby and Common LISP etc. amazes me every day. Like how adding a simple map in front of the count here: (count colls) changes the code from counting the number of collections to enumerating the number of items in those collections. It's all these little things that take one minute or 5 in Java, but only 5 seconds in Clojure (in case you are a slow typer) that make you so much more efficient. With clojure, I spend most of my time thinking about problems at a conceptual level, rather than at the implementation level (Java: int[] vs. IterableInteger vs. ListInteger vs. Integer[] etc. - arrg!). Thanks Rich! That said, every now and then I come across a function in clojure.core that could be vastly improved in its range of applicability by just adding one or more optional parameters, defaulting to the currently hard-coded values (like the often implicit 'identity' function). Take 'distinct'. I'd like to be able to specify the keyfn, that's an important one for me, and while we're at it, I'd like to pass in the set that that function builds up incrementally, and normally starts with an empty set, so that I can pre-initialize it, say with #{ nil }, so that it also filters out nils. This 2nd point is not that important, and I'm not sure if it is that great an idea in terms of orthogonality of the functions, as we have filter. But you'd get rid off one level of indirection. distinct basically gives us a filter for free. But the 1st point I think certainly makes sense, and we have a couple of other fns in clojure that have a variant with a keyfn parameter, like sort-by etc. I guess they normally get a different name. I'm not so sure about what the best order of parameters is in clojure, and named parameters would make this a no brainer, but this is what I currently use, the first parameter being coll, at least in the variant with only one parameter that makes it a drop-in replacement candidate for distinct: (defn distinkt Returns a lazy sequence of the elements of coll with duplicates removed ([coll] (distinkt coll identity)) ([coll keyfn] (distinkt coll keyfn #{})) ([coll keyfn seen-items] (let [step (fn step [xs seen] (lazy-seq ((fn [[f :as xs] seen] (when-let [s (seq xs)] (let [key (keyfn f)] (if (contains? seen key) (recur (rest s) seen) (cons f (step (rest s) (conj seen key))) xs seen)))] (step coll seen-items I don't mind writing - or better - copy-and-pasting this code and keeping it in my project, but I think it could be useful for others, so I wouldn't mind at all if this makes it into clojure.core... :) Or is the reason for hard coding an (implicit) 'identity' performance? Or did I miss some other way to achieve the same goal? Eugen -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Proxy
The code: (def app (proxy [SimpleApplication] [] (simpleInitApp [] (.attachChild (.getRoot this) ball-d) (.setLocalTranslation ground-d (com.g3d.math.Vector3f. 0 0 0)) (.attachChild (.getRoot this) ground-d)) (simpleUpdate [tpf] (println tpf) (flush In SimpleApplication.java: ...@Override public void update() { if (speed == 0) return; super.update(); float tpf = timer.getTimePerFrame(); secondCounter += tpf; int fps = (int) timer.getFrameRate(); if (secondCounter = 1.0f){ fpsText.setText(Frames per second: +fps); secondCounter = 0.0f; } simpleUpdate(tpf); rootNode.updateLogicalState(tpf); guiNode.updateLogicalState(tpf); rootNode.updateGeometricState(); guiNode.updateGeometricState(); renderManager.render(tpf); simpleRender(renderManager); } public abstract void simpleInitApp(); public void simpleUpdate(float tpf){ } ... The error: INFO Node 2:30:56 AM Child (BitmapFont) attached to this node (Gui Node) INFO Node 2:30:56 AM Child (3d-ball) attached to this node (Root Node) INFO Node 2:30:56 AM Child (3d-ground) attached to this node (Root Node) 0.14 java.lang.NullPointerException at com.g3d.renderer.queue.OpaqueComparator.compare(OpaqueComparator.java: 58) at com.g3d.renderer.queue.OpaqueComparator.compare(OpaqueComparator.java: 9) at java.util.Arrays.mergeSort(Arrays.java:1283) at java.util.Arrays.mergeSort(Arrays.java:1294) at java.util.Arrays.mergeSort(Arrays.java:1294) at java.util.Arrays.mergeSort(Arrays.java:1294) at java.util.Arrays.sort(Arrays.java:1223) at com.g3d.renderer.queue.GeometryList.sort(GeometryList.java:73) at com.g3d.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java: 93) at com.g3d.renderer.queue.RenderQueue.renderQueue(RenderQueue.java: 142) at com.g3d.renderer.RenderManager.flushQueue(RenderManager.java:313) at com.g3d.renderer.RenderManager.renderViewPort(RenderManager.java: 415) at com.g3d.renderer.RenderManager.render(RenderManager.java:427) at com.g3d.app.SimpleApplication.update(SimpleApplication.java:148) at user.proxy$com.g3d.app.SimpleApplication$0.update(Unknown Source) at com.g3d.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java: 120) at com.g3d.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java: 171) at java.lang.Thread.run(Thread.java:636) I've tested a similar app in java and it works. What am I doing wrong? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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: generalize distinct
let me expand on my comment. What I meant is, the type of functionality you are adding into distinct, makes it feel less distinct. to me. If I read what you are saying correctly, you want to be also be able to pass a set, so in addition to filter duplicate elements, it also will filter out anything in the set. to me that doesn't feel clojureish. I've always felt that clojure code is about a lot of small functions that does one thing, but does the one thing really well, so you can compose the functions together to do what you want. adding what feels like an unrelated capability to a core function seems odd to me. Just my 2 cents. On Sun, Feb 21, 2010 at 7:25 AM, Eugen Dueck eu...@dueck.org wrote: Hi, Clojure is great! The gain in productivity from more low level languages like Java, but also more functional languages like Ruby and Common LISP etc. amazes me every day. Like how adding a simple map in front of the count here: (count colls) changes the code from counting the number of collections to enumerating the number of items in those collections. It's all these little things that take one minute or 5 in Java, but only 5 seconds in Clojure (in case you are a slow typer) that make you so much more efficient. With clojure, I spend most of my time thinking about problems at a conceptual level, rather than at the implementation level (Java: int[] vs. IterableInteger vs. ListInteger vs. Integer[] etc. - arrg!). Thanks Rich! That said, every now and then I come across a function in clojure.core that could be vastly improved in its range of applicability by just adding one or more optional parameters, defaulting to the currently hard-coded values (like the often implicit 'identity' function). Take 'distinct'. I'd like to be able to specify the keyfn, that's an important one for me, and while we're at it, I'd like to pass in the set that that function builds up incrementally, and normally starts with an empty set, so that I can pre-initialize it, say with #{ nil }, so that it also filters out nils. This 2nd point is not that important, and I'm not sure if it is that great an idea in terms of orthogonality of the functions, as we have filter. But you'd get rid off one level of indirection. distinct basically gives us a filter for free. But the 1st point I think certainly makes sense, and we have a couple of other fns in clojure that have a variant with a keyfn parameter, like sort-by etc. I guess they normally get a different name. I'm not so sure about what the best order of parameters is in clojure, and named parameters would make this a no brainer, but this is what I currently use, the first parameter being coll, at least in the variant with only one parameter that makes it a drop-in replacement candidate for distinct: (defn distinkt Returns a lazy sequence of the elements of coll with duplicates removed ([coll] (distinkt coll identity)) ([coll keyfn] (distinkt coll keyfn #{})) ([coll keyfn seen-items] (let [step (fn step [xs seen] (lazy-seq ((fn [[f :as xs] seen] (when-let [s (seq xs)] (let [key (keyfn f)] (if (contains? seen key) (recur (rest s) seen) (cons f (step (rest s) (conj seen key))) xs seen)))] (step coll seen-items I don't mind writing - or better - copy-and-pasting this code and keeping it in my project, but I think it could be useful for others, so I wouldn't mind at all if this makes it into clojure.core... :) Or is the reason for hard coding an (implicit) 'identity' performance? Or did I miss some other way to achieve the same goal? Eugen -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Omnem crede diem tibi diluxisse supremum. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Map transmogrification functions?
In working through a recent project, I realized that Clojure has a nice collection of functions for working with maps. However, it doesn't seem to have analogues of some of the important sequence tools (filter and map most noticeably, probably others). Given that map will take a map as a collection argument - generating a sequence of entries - it isn't hard to write those analogues. Turning them back into maps is sort of ugly, because there doesn't seem to be a natural way to turn a sequence of entries into a map (someone correct me?), but still not hard. There are some issues with doing this in general - do you use keys, values or entries from the map? If you're modifying instead of filtering, do you modify the key, value or entry? Rolling your own, you can decide what you need when you write it, but trying to generalize them all might get ugly. The nasty part of all this is that I seem to have to specify the resulting map type in the function that turns the sequence of entries back into keys. I.e. - if I want to run the same filter over both a hash-map and a sorted-map and need to preserve the sortedness, I either need two map filter functions, or have to turn the hash-map into a sorted-map after filtering it. Hmm - there doesn't even seem to be an easy way to convert between the two map types. So, the questions: what have I missed in clojure contrib: Is there a function that accepts a sequence of [key value] vectors and creates a map of some sort? Is there a sane way to say please give me a creator of the type of this object? How about a function that accepts a hash-map as an argument and returns a sorted-map of the entries? Thanks, mike -- Mike Meyer m...@mired.org http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. O ascii ribbon campaign - stop html mail - www.asciiribbon.org -- 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: Map transmogrification functions?
Actually, a combination of into empty does the trick amazingly well... http://fulldisclojure.blogspot.com/2010/01/12-fn-proposal-same-multisame.html On Feb 21, 10:56 pm, Mike Meyer mwm-keyword-googlegroups. 620...@mired.org wrote: In working through a recent project, I realized that Clojure has a nice collection of functions for working with maps. However, it doesn't seem to have analogues of some of the important sequence tools (filter and map most noticeably, probably others). Given that map will take a map as a collection argument - generating a sequence of entries - it isn't hard to write those analogues. Turning them back into maps is sort of ugly, because there doesn't seem to be a natural way to turn a sequence of entries into a map (someone correct me?), but still not hard. There are some issues with doing this in general - do you use keys, values or entries from the map? If you're modifying instead of filtering, do you modify the key, value or entry? Rolling your own, you can decide what you need when you write it, but trying to generalize them all might get ugly. The nasty part of all this is that I seem to have to specify the resulting map type in the function that turns the sequence of entries back into keys. I.e. - if I want to run the same filter over both a hash-map and a sorted-map and need to preserve the sortedness, I either need two map filter functions, or have to turn the hash-map into a sorted-map after filtering it. Hmm - there doesn't even seem to be an easy way to convert between the two map types. So, the questions: what have I missed in clojure contrib: Is there a function that accepts a sequence of [key value] vectors and creates a map of some sort? Is there a sane way to say please give me a creator of the type of this object? How about a function that accepts a hash-map as an argument and returns a sorted-map of the entries? Thanks, mike -- Mike Meyer m...@mired.org http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. O ascii ribbon campaign - stop html mail -www.asciiribbon.org -- 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: Montreal Clojure User Group
On Feb 21, 12:55 pm, Jeff Heon jfh...@gmail.com wrote: Would Montreal Clojurians be interested in starting a Clojure group? Or do you all piggyback on the Montreal/Scheme Lisp User Group? That's a great idea, I'm in! I'd say that the Montreal Scheme/Lisp User Group doesn't seems to be quite active. I wonder how many of us are in Montreal or the surrounding region? -- 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: Montreal Clojure User Group
I'm in. Should we go for a coffee to meet each other or something? On Sun, Feb 21, 2010 at 11:15 PM, Nicolas Buduroi nbudu...@gmail.comwrote: On Feb 21, 12:55 pm, Jeff Heon jfh...@gmail.com wrote: Would Montreal Clojurians be interested in starting a Clojure group? Or do you all piggyback on the Montreal/Scheme Lisp User Group? That's a great idea, I'm in! I'd say that the Montreal Scheme/Lisp User Group doesn't seems to be quite active. I wonder how many of us are in Montreal or the surrounding region? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Testing Private Functions
Hi All, I'm trying to test some private functions using the Clojure convention of placing tests in a separate test- namespace. Of course, you can't reference private vars from other namespaces (please correct me if I'm wrong). Not knowing anything at all about how stuff is interned in Clojure, I found this blog post: http://formpluslogic.blogspot.com/2009/08/clojure-unit-testing-part-1.html. Using ns-resolve works. I'm trying to generalize it into a macro named use-private (defmacro #^{:private true} use-private [ns sym] `(def #^{:private true} ~sym (ns-resolve ~ns ~sym))) This, however, doesn't work. The first ~sym macroexpands to (quote sym), which cannot be passed as a name to def. An exception is thrown saying that the first argument must be a symbol, and this is because, I assume, that the quote form is a form. So... Is there a better way the community has found to test private functions? Is there a way to reference private functions from a test- namespace? Is there some proposal floating around to allow this? Is there a better approach than my ghetto macro, outside of extending the core language and libraries? In my ghetto macro, how do I get the sym arg to macroexpand to just the sym and not a quote form? Thanks, Johnny -- 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
Floyd-Warshall's APSP (All-Pairs-Shortest-Path) Algorithm
Hi, In case of need, here[1] is an optimized version of Floyd-Warshall's APSP (All-Pairs-Shortest-Path) algorithm in Clojure. Regards. [1] http://paste.lisp.org/display/95370 -- 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: Newbie suggestion for an implementation - rosettacode pythagorean means
Aviad, Nice job! One nitpick is that won't work for infinite sequences, since reduce isn't lazy. If you wanted your definitions to work for arbitrary indexes of infinite sequences (like the Fibonacci numbers), you could provide sequences providing successive results for the input sequences. I did an example at http://gist.github.com/310668 To use my a-mean-seq with the given example (numbers 1 - 10), you'd do something like: (nth (a-mean-seq (range 1 11)) 10) but you could also get the arithmetic mean of the first 1000 Fibonacci numbers (assuming a fibs function to generate them): (nth (a-mean-seq (fibs)) 1000) I do have a feeling I'm missing something really obvious that would make my example simpler, so if anybody has any tips I'd be much obliged! - Colin On Feb 21, 2:41 pm, Aviad Reich avi@gmail.com wrote: Hi everyone, being a newb to clojure, my ability to contribute to is still limited. However, I thought I'll try starting with something simple. http://rosettacode.org/wiki/Averages/Pythagorean_meansseems straightforward enough, but since it's a comparative site, and implementations should be as idiomatic as possible, I would not post this implementation before some seasoned clojure programmers have a look. so here it is: (10 LOC only)http://github.com/lxmonk/pastes/blob/master/Pythagorean-means.clj obviously, ANY comments will be great (including: this is all wrong - don't post it). Thanks, Aviad -- 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: Common Lisp's append
On Feb 19, 6:23 am, Chouser chou...@gmail.com wrote: In Clojure, if you could use conj on a vector but instead use concat on a list, you'll end up with code that is both non-idiomatic and runs slower than necessary. I found the exercise of doing the equivalent with Clojure vectors pretty challenging. Given the following use case for CL append: CL-USER (append '(a) '() '(b (c)) '(d)) (A B (C) D) The best I could do with Clojure vectors is this: (defn join-vecs [v1 v2] (let [v2len (count v2)] (cond (zero? v2len) v1 (= v2len 1) (conj v1 (first v2)) true (recur (conj v1 (first v2)) (rest v2) (defn append [ vecs] (reduce join-vecs [] vecs)) user (append '[a] '[] '[b [c]] '[d]) [a b [c] d] Is there a better / more idiomatic / more efficient way? Thanks, Mike P.S. I recently got the MEAP of The Joy of Clojure and, aside from a few rough edges in the copy editing, think the content is excellent! Looking forward to learning more. -- 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: Common Lisp's append
Thanks, I ended up using Allegro via Lispbox here. http://www.gigamonkeys.com/lispbox/#download Mike -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Common Lisp's append
Hi, On Feb 22, 7:22 am, Mike K mbk.li...@gmail.com wrote: (defn join-vecs [v1 v2] (let [v2len (count v2)] (cond (zero? v2len) v1 (= v2len 1) (conj v1 (first v2)) true (recur (conj v1 (first v2)) (rest v2) (defn append [ vecs] (reduce join-vecs [] vecs)) user (append '[a] '[] '[b [c]] '[d]) [a b [c] d] Is there a better / more idiomatic / more efficient way? (defn append [ vecs] (reduce into vecs)) user= (append [:a] [] [:b [:c]] [:d]) [:a :b [:c] :d] 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: Newbie suggestion for an implementation - rosettacode pythagorean means
Hi, On Feb 22, 12:18 am, Johnny Kwan johnny.c.k...@gmail.com wrote: I'm really new to Clojure, but I'm under the impression that reduce would be better than apply, since I assume that apply would reify the entire sequence at once, whereas reduce would consume the sequence one by one. Could someone more familiar with the implementation weigh in on this? apply is lazy. user= (defn test-apply [ xs] (prn (take 10 xs))) #'user/test-apply user= (apply test-apply (iterate inc 0)) (0 1 2 3 4 5 6 7 8 9) nil 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: Newbie suggestion for an implementation - rosettacode pythagorean means
Hi, On Feb 22, 2:30 am, trptcolin trptco...@gmail.com wrote: I do have a feeling I'm missing something really obvious that would make my example simpler, so if anybody has any tips I'd be much obliged! Using OP's code: (let [numbers (take 1000 (fibs))] (println (a-mean numbers) = (g-mean numbers) = (h-mean numbers)) (= (a-mean numbers) (g-mean numbers) (h-mean numbers))) Limiting the input correctly is most of the times easier. However you might need the sequence of results. Then you have to come up with something like you did. 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: Testing Private Functions
Hi, On Feb 22, 5:40 am, Johnny Kwan johnny.c.k...@gmail.com wrote: I'm trying to generalize it into a macro named use-private (defmacro #^{:private true} use-private [ns sym] `(def #^{:private true} ~sym (ns-resolve ~ns ~sym))) First some fixes: (defmacro #^{:private true} use-private [ns sym] `(def ~(with-meta sym {:private true}) @(ns-resolve '~ns '~sym))) user= (use-private clojure.core spread) #'user/spread user= (type spread) clojure.core$spread__3429 user= (macroexpand-1 '(use-private clojure.core spread)) (def spread (clojure.core/deref (clojure.core/ns-resolve (quote clojure.core) (q uote spread This, however, doesn't work. The first ~sym macroexpands to (quote sym), which cannot be passed as a name to def. An exception is thrown saying that the first argument must be a symbol, and this is because, I assume, that the quote form is a form. So... This only expands to (quote sym) because you put in (quote sym). You haven't shown the invocation of your macro, but that's most likely the cause. Is there a better way the community has found to test private functions? Is there a way to reference private functions from a test- namespace? Is there some proposal floating around to allow this? Is there a better approach than my ghetto macro, outside of extending the core language and libraries? In my ghetto macro, how do I get the sym arg to macroexpand to just the sym and not a quote form? Use @#'foo.bar/private-fn. Or... My approach to this is to get rid of private function entirely. Everything is public. Put private functions of the namespace foo.bar in the namespace foo.bar.internal. Then simply :use the internal namespace in foo.bar. Make it clear that users using foo.bar.internal have to face eternal doom in the hottest corners of hell. This makes some things really easy: testing private functions is suddenly not a problem anymore. You don't have shout (@#') at private functions in macros. 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
Literature or examples about practical functional program structure, architecture
Hi all, I've been playing around with Clojure off and on for a while now. I like it enough that I'm considering using it to implement an admin interface to MongoDB (a rather serious itch which I've been aching to scratch for a while now). Question is: how to tackle a program of considerable size? I've enough experience with functional languages to grasp the core functional practices (declarative programming style, functional data structures, recursion etc etc). However, that is not the same as getting functional programming for systems of a larger size. I am therefore unsure about the proven practices regarding program structure, patterns or even architecture (dare I use the word). A rather pleasant attempt at this is made in the book Functional Programming for the Real Word (Manning) but in the end it does seem to loose itself in the details of C# and F# instead of focusing on the larger design aspects of functional programs. My question therefore: where can I find literature about this topic? Or perhaps there are good examples to be found ? (For example, I've heard that xmonad is supposed to be a nice example of correct, even beautiful functional program design.) Regards, Iwan -- 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