Re: Light Table - a new IDE concept
On Saturday, 14 April 2012 04:34:54 UTC+10, looselytyped wrote: This is an awesome implementation of Brett Victors Inventing On Principle [http://vimeo.com/36579366] using Clojure and Noir by Chris Granger (who also wrote Noir). Figured I would share it with the group. http://www.chris-granger.com/2012/04/12/light-table---a-new-ide-concept/ Raju Super cool, probably the coolest thing I've seen all year. I wonder if the compiler can be (or is) clojurescript compiled to js, then the whole thing could be hosted remotely, without that latency of sending the code to some sort of compile/interpret service. I'm really looking forward to trying it -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
How Do I Install New Version Of Clojure?
I want to install clojure version 1.3, which I guess is the latest. I tried sudo apt-get install clojure which installs clojure 1.1 by default. I use Ubuntu 10.10 Thanks in advance. -- 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: How Do I Install New Version Of Clojure?
I advice you download the clojure package from clojure.org, and unzip it. Then you can put it to any where you want. Finally, write a shell script named clojure, and put the script to $PATH #! /bin/sh java -cp /path/to/your/downloaded/clojure.jar clojure.main On Sun, Apr 15, 2012 at 1:45 PM, Anto anto.aravinth@gmail.com wrote: I want to install clojure version 1.3, which I guess is the latest. I tried sudo apt-get install clojure which installs clojure 1.1 by default. I use Ubuntu 10.10 Thanks in advance. -- 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: How Do I Install New Version Of Clojure?
Thanks for your reply! Will look into it! -- 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: How Do I Install New Version Of Clojure?
On 15 April 2012 15:35, Anto anto.aravinth@gmail.com wrote: Thanks for your reply! Will look into it! You'll likely want to use Clojure via Leiningen, rather than use the raw jar: https://github.com/technomancy/leiningen - James -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
How does this code works.
I'm very new to Clojure. And I was pretty much interested to learn about vectors, list . maps in clojure. I have a code like this : (defn factorial-1 [number] computes the factorial of a positive integer in a way that doesn't consume stack space (loop [n number factorial 1] (if (zero? n) factorial (recur (dec n) (* factorial n) (println (time (factorial-1 5))) which argues that it does tail recursion optimization. I found this code on net. Can anyone explain me what does the last three lines does: (loop [n number factorial 1] (if (zero? n) factorial (recur (dec n) (* factorial n Thanks in advance. -- 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: How does this code works.
if (n == 0) return the factorial, else go to the loop label and recur with the two parameters (n--) and (factorial * n). Go on until n-- reaches 0. In a Java-like translation we could have: int n = number; factorial = 1; while(n 0){ factorial *= n--; } return factorial; On Sun, Apr 15, 2012 at 5:37 PM, Anto anto.aravinth@gmail.com wrote: Can anyone explain me what does the last three lines does: (loop [n number factorial 1] (if (zero? n) factorial (recur (dec n) (* factorial n Thanks in advance. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: == is not always transitive
I must agree that the behaviour of == is not correct here. The problem is in this method in Numbers.java: public boolean equiv(Number x, Number y){ return toBigDecimal(x).equals(toBigDecimal(y)); } The behaviour we currently have is: user= (let [ones [1 1.0 1N 1M 1.0M 1.00M] ] (doseq [a ones b ones] (println a == b \tab (== a b) ))) 1 == 1 true 1 == 1.0 true 1 == 1N true 1 == 1M true 1 == 1.0M false 1 == 1.00M false 1.0 == 1 true 1.0 == 1.0 true 1.0 == 1N true 1.0 == 1M true 1.0 == 1.0M true 1.0 == 1.00M true 1N == 1 true 1N == 1.0 true 1N == 1N true 1N == 1M true 1N == 1.0M false 1N == 1.00M false 1M == 1 true 1M == 1.0 true 1M == 1N true 1M == 1M true 1M == 1.0M false 1M == 1.00M false 1.0M == 1 false 1.0M == 1.0 true 1.0M == 1N false 1.0M == 1M false 1.0M == 1.0M true 1.0M == 1.00M false 1.00M == 1 false 1.00M == 1.0 true 1.00M == 1N false 1.00M == 1M false 1.00M == 1.0M false 1.00M == 1.00M true I propose we change the method to be: public boolean equiv(Number x, Number y){ return toBigDecimal(x).compareTo(toBigDecimal(y)) == 0; } This makes the previous expression return all true, and == should also be transitive. In particular, (== 1.0M 1.00M) will be true rather than false, which is much more in the spirit of ==. The difference between 1.0M and 1.00M should be checked by calling the scale() method, which makes sense because it is quite an unusual thing to do. I also noticed in test_clojure/numbers.clj the lines: ; TODO: ; == ; and more... So I thought of also adding the test: (deftest equality (are [x y] (== x y) 4242 4242.0 4242N 4242M 4242.0M 4242.00M 42.0 42 42.0 42.0 42.0 42N 42.0 42M 42.0 42.0M 42.0 42.00M 42N 42 42N 42.0 42N 42N 42N 42M 42N 42.0M 42N 42.00M 42M 42 42M 42.0 42M 42N 42M 42M 42M 42.0M 42M 42.00M 42.0M 42 42.0M 42.0 42.0M 42N 42.0M 42M 42.0M 42.0M 42.0M 42.00M 1.23 1.23 1.23 1.23M 1.23M 1.23 1.23M 1.23M ) (are [x y] (not (== x y)) 12 12.1 1.23 123 34 3.4 1.23 1.234 123N 345N 123 345N 123N 345 12.34M 456N 12.34M 4.56 12.34 4.56M 12 4.56M 12M 4.56 12.34M 1.234M )) I think it would be really nice to get this fixed before the 1.4 release. The changes above can be found at https://github.com/andrea-chiavazza/clojure/tree/BigDecimal-equiv-fix Can anybody defend the current behaviour against the one I propose ? -- 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: [ANN] Leiningen 2.0.0-preview3
lein new error under Windows 7 x64: lein version Leiningen 2.0.0-preview3 on Java 1.6.0_31 Java HotSpot(TM) 64-Bit Server VM lein new quiltest Generating a project called quiltest based on the 'default' template. java.lang.IllegalArgumentException: No implementation of method: :make-reader of protocol: #'clojure.java.io/IOFactory found for class: nil at clojure.core$_cache_protocol_fn.invoke(core_deftype.clj:495) at clojure.java.io$fn__7795$G__7790__7802.invoke(io.clj:63) at clojure.java.io$reader.doInvoke(io.clj:96) at clojure.lang.RestFn.invoke(RestFn.java:410) at leiningen.new.templates$slurp_resource.invoke(templates.clj:29) at leiningen.new.templates$renderer$fn__713.doInvoke(templates.clj:79) at clojure.lang.RestFn.invoke(RestFn.java:423) at leiningen.new.default$default.invoke(default.clj:15) at clojure.lang.Var.invoke(Var.java:401) at clojure.lang.AFn.applyToHelper(AFn.java:161) at clojure.lang.Var.applyTo(Var.java:518) at clojure.core$apply.invoke(core.clj:602) at leiningen.new$create.doInvoke(new.clj:54) at clojure.lang.RestFn.invoke(RestFn.java:425) at leiningen.new$create.invoke(new.clj:47) at clojure.lang.AFn.applyToHelper(AFn.java:161) at clojure.lang.RestFn.applyTo(RestFn.java:132) at clojure.core$apply.invoke(core.clj:600) at leiningen.new$new.doInvoke(new.clj:101) at clojure.lang.RestFn.invoke(RestFn.java:421) at clojure.lang.Var.invoke(Var.java:405) at clojure.lang.AFn.applyToHelper(AFn.java:163) at clojure.lang.Var.applyTo(Var.java:518) at clojure.core$apply.invoke(core.clj:602) at leiningen.core.main$resolve_task$fn__699.doInvoke(main.clj:66) at clojure.lang.RestFn.applyTo(RestFn.java:139) at clojure.lang.AFunction$1.doInvoke(AFunction.java:29) at clojure.lang.RestFn.applyTo(RestFn.java:137) at clojure.core$apply.invoke(core.clj:602) at leiningen.core.main$apply_task.invoke(main.clj:88) at leiningen.core.main$_main$fn__731.invoke(main.clj:140) at leiningen.core.main$_main.doInvoke(main.clj:140) at clojure.lang.RestFn.invoke(RestFn.java:421) at clojure.lang.Var.invoke(Var.java:405) at clojure.lang.AFn.applyToHelper(AFn.java:163) at clojure.lang.Var.applyTo(Var.java:518) at clojure.core$apply.invoke(core.clj:600) at clojure.main$main_opt.invoke(main.clj:323) at clojure.main$main.doInvoke(main.clj:426) at clojure.lang.RestFn.invoke(RestFn.java:457) at clojure.lang.Var.invoke(Var.java:413) at clojure.lang.AFn.applyToHelper(AFn.java:172) at clojure.lang.Var.applyTo(Var.java:518) at clojure.main.main(main.java:37) Op donderdag 12 april 2012 19:39:28 UTC+2 schreef Phil Hagelberg het volgende: Hello folks. I'm happy to announce the release of the third preview of Leiningen 2.0.0. Highlights include the ability to show a full dependency tree a la mvn dependency:tree, a host of repl improvements, better offline support, and the ability to load lein new templates on-demand. * Add HTTP nREPL support for repl task via :connect option. (Chas Emerick, Phil Hagelberg) * Improve repl startup time, output consistency, Windows support. (Lee Hinman, Colin Jones) * Stop using numeric exit codes for task failures. * Dynamically resolve unknown templates in new task. * Automatically activate offline profile when needed. * Honor $http_proxy environment variable. (Juergen Hoetzel) * Allow arbitrary :filespecs to be included in jars. * Let custom :prep-tasks be specified in project.clj. * Include :java-source-paths and dev/test deps in pom. (Nelson Morris) * Add offline profile. * Prevent project JVMs from outlasting Leiningen's process. (Colin Jones) * Update lein.bat to work with version 2. (Andrew Kondratovich) * Show a dependency tree in deps task. (Chas Emerick, Nelson Morris) * Support connecting to nrepl server in repl task. (Chas Emerick, Colin Jones) * Pretty-print pom.xml. (Nelson Morris) * Display task aliases in help task. (Michael S. Klishin) * Only compile stale java source files. (Stephen C. Gilardi) * Respect :java-cmd in project.clj. (Michael S. Klishin) * Show progress when downloading search indices. (Justin Kramer) If you have an earlier preview version, you can pull this in via lein upgrade. If you only have Leiningen 1.x installed, you will have to download preview3 by hand: https://raw.github.com/technomancy/leiningen/preview/bin/lein Note that this does not conflict in any way with Leiningen 1.x; you can keep the two of them installed side-by-side. It's common to save the above script as lein2 to differentiate between the two of them if you have projects that don't yet work with Leiningen 2. So far we've found the preview2 release to be quite stable, so now would be a great time
Re: How does this code works.
I'm new to clojure as well, so someone please correct me if the following explanation is wrong, but I'll give it a shot :). The JVM does not natively support TCO; clojure uses the recur form to accomplish what is effectively the same thing despite that shortcoming of its host. The recur form works by jumping back to either the loop (or, if there is no loop form, the defn/fn), and rebinding those scoped variables to the value of the recur's arguments. In your example: (loop [n number factorial 1];; This will be the target of the recur (if (zero? n) ;; If n is zero, factorial ;; return the value of factorial (recur (dec n) (* factorial n;; otherwise, jump to the loop, rebinding n to (dec n) and factorial to (* factorial n) I hope that this made sense :). On Sunday, April 15, 2012 11:37:35 AM UTC-4, Anto wrote: I'm very new to Clojure. And I was pretty much interested to learn about vectors, list . maps in clojure. I have a code like this : (defn factorial-1 [number] computes the factorial of a positive integer in a way that doesn't consume stack space (loop [n number factorial 1] (if (zero? n) factorial (recur (dec n) (* factorial n) (println (time (factorial-1 5))) which argues that it does tail recursion optimization. I found this code on net. Can anyone explain me what does the last three lines does: (loop [n number factorial 1] (if (zero? n) factorial (recur (dec n) (* factorial n Thanks in advance. -- 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: compile dynamic ns ?
Hi Olle, gen-class only operates when *compile-files* is true, which happens when you call `compile`, which in turn calls `require`, which looks for .clj files on disk. Clojure doesn't currently support generating Java classes dynamically, but you could hack the compiler to allow it. -Stuart Sierra -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: compile dynamic ns ?
Stuart Sierra the.stuart.sie...@gmail.com writes: Clojure doesn't currently support generating Java classes dynamically, but you could hack the compiler to allow it. And if you don't feel like doing it yourself, check out shady and `shady.gen-class/gen-class`: https://github.com/llasram/shady/blob/master/src/shady/gen_class.clj#L25 -Marshall -- 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
ClojureScript multitouch support!
Hello folks, I work on primarily on multitouch installations for clients. Historically these are built in processing, flash, openframeworks, etc., but a simple full-screen browser is becoming a more and more viable platform due to WebGL, WebSockets, and hardware-accelerated performance. However, while tablet and smartphone screens generate proper touchstart/move/end events, most larger touchscreens and touchscreen overlays don't. So I'm pleased to announce the release of cljs-multitouch, a (very) small ClojureScript project that works in concert with a browser plugin to solve that problem. cljs-multitouch allows you to get up and running quickly with multitouch ClojureScript apps on even the largest overlays and screens. check it out here: https://github.com/jhickner/cljs-multitouch Thanks! - Jason http://www.varywell.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
Tornado-like async (web) server framework?
There is a lovely little web server for Python called Tornado. Tornado is an async server that also includes an async http client that plugs right in the server's event loop. This makes it really simple to build scalable web services that call other web services, which is what I mostly use it for. I would love to do the same in Clojure but I have no idea where to start. Ideally I would use an async server or framework in the style of Tornado or Twisted. But since Java has excellent thread support I guess I could also use an http lib that allows me to run requests in parallel. Who has some hints or pointers? 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: Tornado-like async (web) server framework?
https://github.com/ztellman/aleph On Sun, Apr 15, 2012 at 9:51 PM, Stefan Arentz ste...@arentz.ca wrote: There is a lovely little web server for Python called Tornado. Tornado is an async server that also includes an async http client that plugs right in the server's event loop. This makes it really simple to build scalable web services that call other web services, which is what I mostly use it for. I would love to do the same in Clojure but I have no idea where to start. Ideally I would use an async server or framework in the style of Tornado or Twisted. But since Java has excellent thread support I guess I could also use an http lib that allows me to run requests in parallel. Who has some hints or pointers? 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 -- 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:Tornado-like async (web) server framework?
Take a look at Aleph http://github.com/ztellman/aleph Regards, BG Sent from phone, please excuse brevity. On Apr 16, 2012 7:21 AM, Stefan Arentz ste...@arentz.ca wrote: There is a lovely little web server for Python called Tornado. Tornado is an async server that also includes an async http client that plugs right in the server's event loop. This makes it really simple to build scalable web services that call other web services, which is what I mostly use it for. I would love to do the same in Clojure but I have no idea where to start. Ideally I would use an async server or framework in the style of Tornado or Twisted. But since Java has excellent thread support I guess I could also use an http lib that allows me to run requests in parallel. Who has some hints or pointers? 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 -- 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
Should I better use a state monad (and how)?
I'm working on a turn-based game and I'm looking for a good way to manage states. In the game each turn is composed of multiple phases. I started by using atoms for the phases field (this is a sequence of functions) in a record and realized that it wouldn't be ideal to keep track of states in the case where I'd need to keep a snapshot of every phases. Here's the original code I had: (defrecord Game [phases] (next-phase [this] (stop-timer) (swap! phases #(conj (vec (rest %)) (first %))) (log :info change phase to %s (key (first @phases))) (start-phase this)) I then started to think that this would be a good opportunity to use a state monad. I've tried to reimplement the above code using the algo.monads library but the result was less than satisfactory (probably due to my own shortcoming), here's the monadic version: (defrecord Game [phases] (next-phase [this] (- ((domonad state-m [_ (fn [s] (stop-timer) [s s]) _ (update-state (fn [s] (update-in s [:phases] #(conj (vec (rest %)) (first %) _ (fn [s] (log :info change phase to %s (key (first (:phases s [s s])] nil) state) second start-phase)) As my code probably doesn't need the full power of the state monad, I tried to write a lighter-weight version using the following macro: (defmacro [ state-and-forms] (reduce #(list (if ('#{fn fn*} (first %2)) %2 `(fn [s#] ~%2 s#)) %) state-and-forms)) Which let me write: (next-phase [state] ( state (stop-timer) (fn [s] (update-in s [:phases] #(conj (vec (rest %)) (first % #(do (log :info change phase to %s (key (first (:phases % %) #(start-phase %))) With some more helper macro this version looks promising. In the end I wonder if there's some Clojure feature I'm overlooking or if I should rethink the whole solution? Is there a better way to accomplish this? -- 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: Should I better use a state monad (and how)?
You can try using the in-memory version of Datomic. Besides keeping track of the state at every point, it can help with the reasoning about what should happen next for each state change. On Sun, Apr 15, 2012 at 11:25 PM, Nicolas Buduroi nbudu...@gmail.com wrote: I'm working on a turn-based game and I'm looking for a good way to manage states. In the game each turn is composed of multiple phases. I started by using atoms for the phases field (this is a sequence of functions) in a record and realized that it wouldn't be ideal to keep track of states in the case where I'd need to keep a snapshot of every phases. Here's the original code I had: (defrecord Game [phases] (next-phase [this] (stop-timer) (swap! phases #(conj (vec (rest %)) (first %))) (log :info change phase to %s (key (first @phases))) (start-phase this)) I then started to think that this would be a good opportunity to use a state monad. I've tried to reimplement the above code using the algo.monads library but the result was less than satisfactory (probably due to my own shortcoming), here's the monadic version: (defrecord Game [phases] (next-phase [this] (- ((domonad state-m [_ (fn [s] (stop-timer) [s s]) _ (update-state (fn [s] (update-in s [:phases] #(conj (vec (rest %)) (first %) _ (fn [s] (log :info change phase to %s (key (first (:phases s [s s])] nil) state) second start-phase)) As my code probably doesn't need the full power of the state monad, I tried to write a lighter-weight version using the following macro: (defmacro [ state-and-forms] (reduce #(list (if ('#{fn fn*} (first %2)) %2 `(fn [s#] ~%2 s#)) %) state-and-forms)) Which let me write: (next-phase [state] ( state (stop-timer) (fn [s] (update-in s [:phases] #(conj (vec (rest %)) (first % #(do (log :info change phase to %s (key (first (:phases % %) #(start-phase %))) With some more helper macro this version looks promising. In the end I wonder if there's some Clojure feature I'm overlooking or if I should rethink the whole solution? Is there a better way to accomplish this? -- 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: Should I better use a state monad (and how)?
On Monday, April 16, 2012 12:08:30 AM UTC-4, kovasb wrote: You can try using the in-memory version of Datomic. Besides keeping track of the state at every point, it can help with the reasoning about what should happen next for each state change. Hum, I hadn't though about using a service like Datomic at all, but I'm not sure it fill the bill has it looks like a very heavyweight solution. I'm not even sure where to start to understand what Datomic is! -- 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: Tornado-like async (web) server framework?
Stefan Arentz: Who has some hints or pointers? github.com/momentumclj/momentum is another option. It is still evolving rapidly but I've had very good experience with it. MK -- 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: Should I better use a state monad (and how)?
I couldn't resist writing some more macros! (defmacro [k-or-ks f] `(fn [state#] (update-in state# ~(if (vector? k-or-ks) k-or-ks (vector k-or-ks)) ~f))) (defn * [state form] (condp = (first form) ' `(fn [~state] ~@(rest form) ~state) ' `(fn [~state] ~@(rest form)) form)) (defmacro [state forms] (reduce #(list (if (#{' 'fn 'fn* 'clojure.core/fn 'clojure.core/fn*} (first %2)) %2 `(fn [s#] ~%2 s#)) %) (conj (map (partial * state) forms) state))) With those the resulting code looks pretty clean and remain purely functional: (next-phase [state] ( state (stop-timer) ( :phases #(conj (vec (rest %)) (first %))) ( (log :info change phase to %s (- state :phases first key))) ( (start-phase state Now, I'd need to find better names! On Sunday, April 15, 2012 11:25:21 PM UTC-4, Nicolas Buduroi wrote: I'm working on a turn-based game and I'm looking for a good way to manage states. In the game each turn is composed of multiple phases. I started by using atoms for the phases field (this is a sequence of functions) in a record and realized that it wouldn't be ideal to keep track of states in the case where I'd need to keep a snapshot of every phases. Here's the original code I had: (defrecord Game [phases] (next-phase [this] (stop-timer) (swap! phases #(conj (vec (rest %)) (first %))) (log :info change phase to %s (key (first @phases))) (start-phase this)) I then started to think that this would be a good opportunity to use a state monad. I've tried to reimplement the above code using the algo.monads library but the result was less than satisfactory (probably due to my own shortcoming), here's the monadic version: (defrecord Game [phases] (next-phase [this] (- ((domonad state-m [_ (fn [s] (stop-timer) [s s]) _ (update-state (fn [s] (update-in s [:phases] #(conj (vec (rest %)) (first %) _ (fn [s] (log :info change phase to %s (key (first (:phases s [s s])] nil) state) second start-phase)) As my code probably doesn't need the full power of the state monad, I tried to write a lighter-weight version using the following macro: (defmacro [ state-and-forms] (reduce #(list (if ('#{fn fn*} (first %2)) %2 `(fn [s#] ~%2 s#)) %) state-and-forms)) Which let me write: (next-phase [state] ( state (stop-timer) (fn [s] (update-in s [:phases] #(conj (vec (rest %)) (first % #(do (log :info change phase to %s (key (first (:phases % %) #(start-phase %))) With some more helper macro this version looks promising. In the end I wonder if there's some Clojure feature I'm overlooking or if I should rethink the whole solution? Is there a better way to accomplish this? -- 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: Should I better use a state monad (and how)?
Its just a library with some functions; if you can understand macros and the STM I'm confident you can understand it too. On Mon, Apr 16, 2012 at 12:34 AM, Nicolas Buduroi nbudu...@gmail.com wrote: On Monday, April 16, 2012 12:08:30 AM UTC-4, kovasb wrote: You can try using the in-memory version of Datomic. Besides keeping track of the state at every point, it can help with the reasoning about what should happen next for each state change. Hum, I hadn't though about using a service like Datomic at all, but I'm not sure it fill the bill has it looks like a very heavyweight solution. I'm not even sure where to start to understand what Datomic is! -- 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