test.check generating hierarchy with relations
Hi I would like to test a function which recursively traverses the nodes in a graph and collects them. For example, (def graph {1 [2 3 4] 2 [5 6 7] 6 [8 9] 10 [11 12 13]} my function is given a starting point say, 1 and should then traverse each node which is reachable and return the set. In this case the result should be: #{3, 4, 5, 7, 8, 9} note: it does not return any elements reachable by 10. I would like to test this using test.check, but I would like to generate test data which will exercise the traversal of the graph. I found a similar thread here: https://groups.google.com/forum/#!topic/clojure/YWeT8BFc8k4 But, I don't think the proposed solution would suit this use case. So, I tried generating a graph with relations using core.logic (defn -maps take the output of run* and convert it into sequence of maps [q] (let [r (- q (partition 2) (map (fn [[k v]] {k (apply vector v)})) (apply merge))] r )) (defn gen-hierarchy generate a related hierarchy [size] (let [vars1 (- (repeatedly 7 lvar) (into [])) vars2 (- (repeatedly 7 lvar) (into [])) vars3 (- (repeatedly 7 lvar) (into []))] (- (run size [q] (fresh [?k1 ?k2 ?k3 ?v1 ?v2 ?v3 ?a] (fd/distinct vars1) (everyg #(fd/in % (fd/interval 1 9)) vars1) (fd/in ?k1 (fd/interval 1 9)) (rembero ?k1 vars1 ?v1) (membero ?k2 ?v1) (fd/distinct vars2) (everyg #(fd/in % (fd/interval 1 9)) vars2) (rembero ?k2 vars2 ?v2) (membero ?k3 ?v2) (fd/distinct vars3) (everyg #(fd/in % (fd/interval 1 9)) vars3) (rembero ?k3 vars3 ?v3) (appendo [?k1 ?v1] [?k2 ?v2] ?a) (appendo ?a [?k3 ?v3] q))) (map -maps Hooking this into test.check. I tried the following: (defn gen-port-hierarchy [] (gen/sized (fn [size] (gen/fmap #(gen-hierarchy %) (gen/return size) (gen/sample (gen/not-empty (gen-port-hierarchy)) 1) Which does produce more or less what I'm after: (({6 [2 3 4 5 7 1], 3 [6 7 1 2 4 5], 1 [3 2 4 5 6 7]}) ({5 [1 2 3 4 6 7], 7 [5 3 4 6 1 2], 1 [7 2 3 4 5 6]})) However, when I try use this in a spec: (prop/for-all [bindings (gen/not-empty (gen-port-hierarchy))] (let [ ks (into #{} (keys bindings))] ...) I seem to be getting back a LazySeq which then leads to a ClassCastException: java.lang.ClassCastException: clojure.lang.PersistentArrayMap cannot be cast to java.util.Map$Entry Am I on the completely wrong path here? Or have I incorrectly hooked this generator up with test.check? Any help would be very appreciated. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: core.async take behaviour
Thanks Alex. Feel silly not to have noticed the partition function. When will transduces be available to use? On Wednesday, 3 September 2014 22:48:20 UTC+2, Alex Miller wrote: I think that's just a partition transducer on the channel? On Wednesday, September 3, 2014 2:24:28 AM UTC-5, Gary Verhaegen wrote: I'd use another channel on which I put vectors of the correct length, with an intermediate loop that takes from the first channel, accumulates until the vector has the right size, and then put the vector on the second channel. There might be a better solution with transducers, though. (Or without.) On Wednesday, 3 September 2014, cig clifford...@gmail.com wrote: Thanks Timothy, that makes sense. A follow on question if you don't mind. I would like to 'take' n items off of a channel, but wait until n items are available rather than eagerly returning the way take does. Do you have any ideas on how I could achieve this? On Tuesday, 2 September 2014 22:23:10 UTC+2, tbc++ wrote: It's because into is pulling items as fast as it can from take. Sure the buffer might get full but then into takes another value allowing take to continue. Timothy On Tue, Sep 2, 2014 at 1:48 PM, cig clifford...@gmail.com wrote: Hi I was expecting the following example to park, waiting for the 'out' channel to be cleared. Could anybody explain why 'take' does not park when the output buffer size is smaller than the number of entries being taken from the input channel? (def from (to-chan [1 2 3 4 5 6 7])) (!! (into [] (take 4 from *2*))) ;; note: the output channel buffer size is 2 (less than 4 items being taken off of the 'from' channel) ;; = [1 2 3 4] -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth) -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: core.async take behaviour
Thanks Timothy, that makes sense. A follow on question if you don't mind. I would like to 'take' n items off of a channel, but wait until n items are available rather than eagerly returning the way take does. Do you have any ideas on how I could achieve this? On Tuesday, 2 September 2014 22:23:10 UTC+2, tbc++ wrote: It's because into is pulling items as fast as it can from take. Sure the buffer might get full but then into takes another value allowing take to continue. Timothy On Tue, Sep 2, 2014 at 1:48 PM, cig clifford...@gmail.com javascript: wrote: Hi I was expecting the following example to park, waiting for the 'out' channel to be cleared. Could anybody explain why 'take' does not park when the output buffer size is smaller than the number of entries being taken from the input channel? (def from (to-chan [1 2 3 4 5 6 7])) (!! (into [] (take 4 from *2*))) ;; note: the output channel buffer size is 2 (less than 4 items being taken off of the 'from' channel) ;; = [1 2 3 4] -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.com javascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com javascript:. For more options, visit https://groups.google.com/d/optout. -- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth) -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
core.async take behaviour
Hi I was expecting the following example to park, waiting for the 'out' channel to be cleared. Could anybody explain why 'take' does not park when the output buffer size is smaller than the number of entries being taken from the input channel? (def from (to-chan [1 2 3 4 5 6 7])) (!! (into [] (take 4 from *2*))) ;; note: the output channel buffer size is 2 (less than 4 items being taken off of the 'from' channel) ;; = [1 2 3 4] -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
clojure.test.check
Hi I have been trying to build a test.check generator for a multi map, without much success. I have a generator which generates ordinary maps: (def ord-gen (gen/fmap (partial zipmap [:port :instr :qty]) (gen/tuple (gen/not-empty gen/string-alpha-numeric) (gen/not-empty gen/string-alpha-numeric) (gen/frequency [[9 gen/pos-int] [1 gen/neg-int]] (gen/sample ord-gen 3) ;; = ({:qty 0, :instr X4, :port re} {:qty 0, :instr v, :port 8} {:qty 1, :instr 3A, :port 7}) However, I would like to merge this sequence of individual maps into a multi-map of the form: {re { X4 {:qty 0, :instr X4, :port re}}, 8 { v {:qty 0, :instr v, :port 8}}, 7 { 3A {:qty 1, :instr 3A, :port 7}}} The closest I have gotten to achieving this is by realising the intermediate steps: (def gen-cache (- (gen/fmap (fn [o] (let [{:keys [port instr] :as ord} o] (assoc-in {} [port instr] ord))) ord-gen) (gen/sample) (reduce (fn [r m] (merge-with merge r m)) {}) (gen/return))) However, this returns the same value constantly (I am aware that, that is what gen/return is supposed to do, however, I can not get much else working for me). I would Ideally like to bind the ord-gen into the gen-cache generator. Any help would be very appreciated. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: clojure.test.check
Hi Reid Yes that's exactly what I was trying to achieve. Thank you very much. As for the multi-maps. I was simply using the term incorrectly, sorry for the confusion. Thanks once again On Thursday, 3 July 2014 16:44:29 UTC+2, Reid Draper wrote: Hi, I've taken a stab at what I think you want: (def gen-cache (gen/fmap #(reduce (fn [r m] (merge-with merge r m)) {} %) (gen/vector (gen/fmap (fn [o] (let [{:keys [port instr] :as ord} o] (assoc-in {} [port instr] ord))) ord-gen Instead of using `gen/sample` to create a sequence, I use `gen/vector`. And in order to apply the `reduce` function, I use `gen/fmap`. As an aside, I'm not sure how this is a multi-map. I was under the impression a multi-map was simply a map that can store multiple values in the same key. Reid On Thursday, July 3, 2014 6:06:29 AM UTC-5, cig wrote: Hi I have been trying to build a test.check generator for a multi map, without much success. I have a generator which generates ordinary maps: (def ord-gen (gen/fmap (partial zipmap [:port :instr :qty]) (gen/tuple (gen/not-empty gen/string-alpha-numeric) (gen/not-empty gen/string-alpha-numeric) (gen/frequency [[9 gen/pos-int] [1 gen/neg-int]] (gen/sample ord-gen 3) ;; = ({:qty 0, :instr X4, :port re} {:qty 0, :instr v, :port 8} {:qty 1, :instr 3A, :port 7}) However, I would like to merge this sequence of individual maps into a multi-map of the form: {re { X4 {:qty 0, :instr X4, :port re}}, 8 { v {:qty 0, :instr v, :port 8}}, 7 { 3A {:qty 1, :instr 3A, :port 7}}} The closest I have gotten to achieving this is by realising the intermediate steps: (def gen-cache (- (gen/fmap (fn [o] (let [{:keys [port instr] :as ord} o] (assoc-in {} [port instr] ord))) ord-gen) (gen/sample) (reduce (fn [r m] (merge-with merge r m)) {}) (gen/return))) However, this returns the same value constantly (I am aware that, that is what gen/return is supposed to do, however, I can not get much else working for me). I would Ideally like to bind the ord-gen into the gen-cache generator. Any help would be very appreciated. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Om: trouble with goog reference
Hi David I tried changing :advanced mode to :whitespace mode. My index.html file looks as follows: html body div id=registry/div script src=http://fb.me/react-0.9.0.js;/script script src=js/om_ho.js/script /body /html my project.clj file looks as follows: (defproject om-ho 0.0.1-SNAPSHOT :description FIXME: write description :url http://example.com/FIXME; :license {:name Eclipse Public License - v 1.0 :url http://www.eclipse.org/legal/epl-v10.html; :distribution :repo} :min-lein-version 2.3.4 :source-paths [src/clj src/cljs] :dependencies [[org.clojure/clojure 1.5.1] [org.clojure/clojurescript 0.0-2156] [org.clojure/core.async 0.1.267.0-0d7780-alpha] [om 0.5.0] [com.facebook/react 0.9.0]] :plugins [[lein-cljsbuild 1.0.2]] :hooks [leiningen.cljsbuild] :cljsbuild {:builds {:om-ho {:source-paths [src/cljs] :compiler {:output-to dev-resources/public/js/om_ho.js :optimizations :none :pretty-print false) With this setup. Evaluating core.cljs (which is taken directly from your Higher Order Components tutorial) I see the, XHR finished Loading events in the browser, which is a good sign, but the only text which renders is, Registry. I assume this is because of the missing goog.closure lines in the index.html file i.e. script src=out/goog/base.js type=text/javascript/script script type=text/javascriptgoog.require(om_ho.core);/script When I include these two lines I get the same errors that Chris mentioned above. Would really appreciate your help. Clifford On Monday, 24 February 2014 03:22:22 UTC+2, boz wrote: I'm having trouble with the Om basic tutorial Higher Order Componentshttps://github.com/swannodette/om/wiki/Basic-Tutorial#wiki-higher-order-components using emacs and a slightly modified version of https://github.com/magomimmo/om-start-template that points to Om 0.5.0 and React 0.9.0. My version is https://github.com/christoferjennings/om-start-template The template doesn't have the goog/base.js out of the box. When I add it, I get a Uncaught ReferenceError: goog is not defined (Chrome Version 33.0.1750.117) Here's the final html (basically the same as in the tutorial. html body div id=registry/div script src=http://fb.me/react-0.9.0.js;/script script src=out/goog/base.js type=text/javascript/script script src=my-stuff.js type=text/javascript/script script type=text/javascriptgoog.require(my-stuff.core);/script /body /html There is no out/goog/base.js, so I'm not too surprised goog is undefined. I'm stumped, though, because I don't know if the goog stuff that ends up in the .repl folder should be enough, or if I have to do something special to get the goog stuff to be in the out folder. I've tried lein cljsbuild once without luck. Any ideas on what I'm doing wrong? Thanks! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
how to turn on smartparens-strict-mode in emacs-live
Where should I place the setting to turn on smartparens-strict-mode in emacs-live? Following this thread, https://github.com/Fuco1/smartparens/issues/158 I tried adding this to my own pack but that did not work, subsequently added it to the clojure-pack under the smartparents-conf.el but that is not a good long term solution. Any suggestions? -- -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
core.logic CLP(Set)
Is CLP(Set) for core.logic available for use? It does not seem like core.logic 0.8.3 contains this feature. How should I access it if it is available? -- -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: core.logic CLP(Set)
Hi David Did you not make use of it for solving this puzzle? https://gist.github.com/swannodette/5127150 On Tuesday, 18 June 2013 13:38:48 UTC+2, David Nolen wrote: CLP(Set) has not been implemented yet. On Tue, Jun 18, 2013 at 2:36 AM, cig clifford...@gmail.com javascript:wrote: Is CLP(Set) for core.logic available for use? It does not seem like core.logic 0.8.3 contains this feature. How should I access it if it is available? -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.comjavascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com javascript:. For more options, visit https://groups.google.com/groups/opt_out. -- -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Clojure vs Scala - anecdote
Impressive, wonder if they were running this on a single node or more widespread? In a wide spread environment I think Erlang would be the true winner, though it does not natively have macros :-( There is an implementation of Lisp for Erlang called LFE (lisp flavored Erlang) which I looked at, which does have macros and a real engine underneath. But clojure is an awesome combination On Sep 7, 7:32 am, Sean Corfield seancorfi...@gmail.com wrote: I just wanted to share this experience from World Singles... Back in November 2009, we started developing with Scala. We needed a long-running process that published large volumes of changes from our member database as XML packets published to a custom search engine. The mapping from half a dozen tables in the database to a flat XML schema was pretty complex and the company had tried a number of solutions with mixed success in the past. I introduced Scala based on the promises of performance, concurrency and type safety - and conciseness (especially with XML being a native data type in Scala). We've been running the Scala publishing daemons in production for most of two years. Generally they work pretty well but, under stress, they tend to hit Out of Memory exceptions and, after a lot of poking around, we became fairly convinced it was due (at least in part) to the default actor implementation in Scala. Scala is going to fold in Akka soon and we had been considering migrating to Akka anyone... But having introduced Clojure this year (after experimenting with it since about May last year), we figured we'd have a short spike to create a Clojure version of the Scala code to see how it worked out. It took about 15 hours to recreate the publishing daemon in Clojure and get it to pass all our tests. Today we ran a soak test publishing nearly 300,000 profiles in one run. The Scala code would fail with OoM exceptions if we hit it with 50,000 profiles in one run (sometimes less). The Clojure code sailed thru and is still happily running - so we'll be replacing the Scala code during our next production build. The other aspect that's interesting is that the Scala code totaled about 1,000 lines (about 31k characters of code). The Clojure replacement is just under 260 lines (around 11.5k characters of code). Neither code base has much in the way of comments (*ahem* - I'm not proud of that, just pointing out that there's no noise offsetting the code comparison). That doesn't include unit tests either, it's just the raw production code. The form of the Clojure code mostly follows the form of the Scala code, most of the same functions - it was very functional Scala - with some refactoring to helper functions to make it more modular and more maintainable. The net result is (obviously) that we'll be taking the Clojure publishing daemon to production and we'll be dropping Scala completely. Kudos to Rich Hickey and the Clojure/core team for creating a great general purpose language that can solve big problems - thank you! -- Sean A Corfield -- (904) 302-SEAN An Architect's View --http://corfield.org/ World Singles, LLC. --http://worldsingles.com/ Railo Technologies, Inc. --http://www.getrailo.com/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) -- 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