feedback on file parsing with Clojure
hello, i'm looking for some feedback on how i've used Clojure to do some file parsing still getting the hang of Clojure ways of thinking and i'd love to hear any advice on how to improve what i've done for example, i'm guessing the way i've used cond blocks is a bit sketchy - at that point, i was kind of in a just-get-it-done mindset the file being parsed is here https://github.com/AndyKriger/i-ching/blob/master/clojure/resources/i-ching.html the code doing the parsing is here https://github.com/AndyKriger/i-ching/blob/master/clojure/src/i_ching/parser.clj the output is here (a browser JSON viewer is advised) https://raw.githubusercontent.com/AndyKriger/i-ching/master/clojure/resources/i-ching.json thank you for any help a -- 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.
Which emacs packages?
Curious about which emacs packages folks use for increased Clojure productivity (beyond the obvious, like slime/swank-clojure)... -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: ANN: Clojure 1.4.0-beta1
On Feb 3, 10:47 am, Stuart Sierra the.stuart.sie...@gmail.com wrote: Clojure 1.4 goes beta! This release is essentially the same as 1.4.0-alpha5. It will hit the Maven Central repository in a few hours. No new features in the 1.4 line after this point. Bug fixes are still allowed. Also, if somebody wants to compile a list on the wiki of all the bug fixes and changes since 1.3, that would be very helpful. Thanks! -Stuart Sierra clojure.com Is 1.4 supposed to be compatible with 1.3 and libraries written to 1.3? For example, I've found some 1.2 libraries don't play nicely with 1.3 because of the clojure-contrib changes and would like to avoid problems like that while being able to use 1.4 in my code. -- 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: swank-cdt problems
Thank you - I am able to use CDT now. Here's what I had to do... * updated lein plugin to 1.4.0-SNAPSHOT * symlinked to tools.jar in ~/.lein/plugins * added jvm-opts line to project.clj * ran swank using lein swank and M-x slime-connect Problems I still see.. * C-c C-x shortcuts do not work * error in process filter: Wrong number of arguments: nil, 2 = i think this is because I need to update slime, doesn't seem to affect things * cannot use M-x clojure-jack-in any more = error in process filter: Search failed: (run-hooks 'slime-load-hook) ; on port Having M-x clojure-jack-in work would be great as it's much easier than M-x shell, lein swank, M-x slime-connect On Dec 5, 2:02 pm, George Jahad cloj...@blackbirdsystems.net wrote: this error: java.io.IOException: Not a debuggee, or not listening for debugger to attach is usually caused by not having this line in your project.clj: :jvm-opts [-agentlib:jdwp=transport=dt_socket,server=y,suspend=n] if that doesn't fix your problem, send me your project.clj and the name of your OS. Also, I never use clojure-jack-in, so that may also be a part of the problem. I'll look into it, but in the meantime, can you also try using lein swank and then M-x slime-connect. On Dec 5, 10:32 am,AndyKandy.kri...@gmail.com wrote: I'd like to be using swank-cdt, but I'm running into the tools.jar problem warning: unabled to add tools.jar to classpath. CDT 1.4.0a startup failed: #RuntimeException java.lang.RuntimeException: java.io.IOException: Not a debuggee, or not listening for debugger to attach In project.clj, I've tried :extra-classpath-dirs [/usr/lib/jvm/java-6-sun/lib/tools.jar] and :dev-resources-path /usr/lib/jvm/java-6-openjdk/lib/tools.jar Neither worked I've also tried symlinking tools.jar as mentioned herehttp://groups.google.com/group/clojure/msg/70236500461be9c6?dmode=source I have swank 1.4.0-SNAPSHOT installed as a leiningen plugin and I run it in Emacs23 using M-x clojure-jack-in 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
swank-cdt problems
I'd like to be using swank-cdt, but I'm running into the tools.jar problem warning: unabled to add tools.jar to classpath. CDT 1.4.0a startup failed: #RuntimeException java.lang.RuntimeException: java.io.IOException: Not a debuggee, or not listening for debugger to attach In project.clj, I've tried :extra-classpath-dirs [/usr/lib/jvm/java-6-sun/lib/tools.jar] and :dev-resources-path /usr/lib/jvm/java-6-openjdk/lib/tools.jar Neither worked I've also tried symlinking tools.jar as mentioned here http://groups.google.com/group/clojure/msg/70236500461be9c6?dmode=source I have swank 1.4.0-SNAPSHOT installed as a leiningen plugin and I run it in Emacs23 using M-x clojure-jack-in 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
Re: swank-cdt problems
After a bit more messing around - the problem is a little different... I fixed the swank plugin version to 1.4.0-SNAPSHOT and updated clojure- mode to 1.11.4 Now I get error in process filter: Search failed: (run-hooks 'slime-load- hook) ; on port when I try to run clojure-jack-in Thoughts? On Dec 5, 1:32 pm, AndyK andy.kri...@gmail.com wrote: I'd like to be using swank-cdt, but I'm running into the tools.jar problem warning: unabled to add tools.jar to classpath. CDT 1.4.0a startup failed: #RuntimeException java.lang.RuntimeException: java.io.IOException: Not a debuggee, or not listening for debugger to attach In project.clj, I've tried :extra-classpath-dirs [/usr/lib/jvm/java-6-sun/lib/tools.jar] and :dev-resources-path /usr/lib/jvm/java-6-openjdk/lib/tools.jar Neither worked I've also tried symlinking tools.jar as mentioned herehttp://groups.google.com/group/clojure/msg/70236500461be9c6?dmode=source I have swank 1.4.0-SNAPSHOT installed as a leiningen plugin and I run it in Emacs23 using M-x clojure-jack-in 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
Re: The Clojure way to solve this problem?
Thank you - that worked brilliantly. I'm using a Java load testing tool called The Grinder and it has an instrumented HTTP library that is dependent on running within The Grinder. So I have clj-http for developing my tests and then I can drop them into load testing and substitute the Grinder using with-redefs. Works so nicely. Loving Clojure - wonderful for test automation. On Nov 30, 8:13 pm, gaz jones gareth.e.jo...@gmail.com wrote: what about just re-defing the function inside the tests to the instrumented version? something like: (ns one.http) (defn get [] ...) (ns one.http-instrumented) (defn get [] ...) (ns one.test.blah) (with-redefs [one.http/get one.http-instrumented/get] ...) guess you could put the redefs into a function and use it as a fixture if you're using clojure.test? that would get rid of the flag and fork in the code O_o On Wed, Nov 30, 2011 at 5:53 PM,AndyKandy.kri...@gmail.com wrote: I have Clojure code which makes HTTP requests to a server. Depending on the context, I want to swap out the underlying HTTP library code. For example, I use an instrumented library in a testing context and a different library in a REPL context where the instrumented library will not work. These are low-lying functions - the http/get and http/ put - called within other functions for doing specific kinds of requests which are called in turn by other functions. What I'm wondering is what are good ways to dynamically choose which versions of those low-lying functions to use? For now, I'm doing this within the namespace that uses the low-lying functions.. (def get (if (context-flag?) ns.one.http-instrumented/get ns.two.http- repl/get)) What I don't like about this is that context-flag feeling like a hacky approach. Thoughts? -- 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: Avout: Distributed State in Clojure
If you're willing to dig into another language, 'Erlang and OTP in Action' gives a great overview of Erlang and the distributed principles underlying that language. Though different from the approach of distributed STM, the concepts of distributed applications are baked into the core of Erlang. On Nov 30, 2:03 am, Harrison Maseko lis...@gmail.com wrote: Could anyone please recommend a good introductory book about distributed application development? The release of Avout has gotten me interested in the subject. Thanks, Harrison. On Nov 29, 7:38 pm, liebke lie...@gmail.com wrote: Today we are releasing Avout, which brings Clojure's in-memory model of state to distributed application development by providing a distributed implementation of Clojure's Multiversion Concurrency Control (MVCC) STM along with distributable, durable, and extendable versions of Clojure's Atom and Ref concurrency primitives. Here's the post announcing the project:http://clojure.com/blog/2011/11/29/avout.html And here's the project's website:http://avout.io David -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
The Clojure way to solve this problem?
I have Clojure code which makes HTTP requests to a server. Depending on the context, I want to swap out the underlying HTTP library code. For example, I use an instrumented library in a testing context and a different library in a REPL context where the instrumented library will not work. These are low-lying functions - the http/get and http/ put - called within other functions for doing specific kinds of requests which are called in turn by other functions. What I'm wondering is what are good ways to dynamically choose which versions of those low-lying functions to use? For now, I'm doing this within the namespace that uses the low-lying functions.. (def get (if (context-flag?) ns.one.http-instrumented/get ns.two.http- repl/get)) What I don't like about this is that context-flag feeling like a hacky approach. Thoughts? -- 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
Proper parallelism?
I have been using Clojure to write tests on RESTful applications. Since the requests are independent, parallelizing would speed things along. What is the best approach? Using pmap is the obvious first step. Afaik, pmap only creates a small pool of threads. Is there more to gain by going to the Java API's threading classes (like ExecutorService, or building a pool of threads triggered by a CountDownLatch)? What experience have folks had with different approaches? thx -- 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: Dynamic test creation?
Questions about tabular tests... * can they take a lazy-seq as input? * will the tests be parallelized? (i have anywhere from 10k-20k tests to run) On Nov 8, 4:16 pm, Alex Baranosky alexander.barano...@gmail.com wrote: Sounds lile you could use Midje's tabular tests. Or if you want write a acro to generate a tabular fact. Tje tabular fact will give you good reporting. On Nov 8, 2011 1:44 PM, AndyK andy.kri...@gmail.com wrote: I finally had a chance to try this out and it fails with error: java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IObj Compilation failed. When I substituted in something like this... (defn prn-form [n scenario] `(prn ~(str foo n) (prn ~(str n :: scenario the file did compile. Is the fact that deftest is also a macro going to cause a problem with the original idea? On Nov 2, 8:36 am, Nate Young youn...@gmail.com wrote: On 11/01/2011 03:05 PM, AndyK wrote: How would (run-tests 'my-namespace) know to run all thosedynamic tests? I thought that it parsed the namespace for 'my-namespace when you call it. Or is it that the call to defcsvtests sets off a chain of macro resolutions before run-tests can even do its thing (so that it Right. Its that the macro-expansion phase actually reads from the csv file in order to create a number of deftest forms, and each one then gets evaluated, so after you've evaluated (defcsvtests), then (run-tests) will be able to find a number of tests to run. -- 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: lein test with command-line args?
Those are cool - thank you for bringing them to my attention They don't appear to address the issue of setting up environment data. For example, lein test :development -vs- lein test :staging where different configs are loaded for :development or :staging (ex: database, web endpoints). On Nov 7, 5:17 pm, Phil Hagelberg p...@hagelb.org wrote: On Mon, Nov 7, 2011 at 2:14 PM, AndyK andy.kri...@gmail.com wrote: Is it possible to pass command-line arguments to tests using leiningen? Looking for ways to control the way that tests are run usingleintestby passing in switches (e.g. which environment it runs against, which tests run, etc). One workaround that occurs to me is to useleinrun where run calls run-tests directly, but that seems hacktacular. Have you tried usingtestselectors? leinhelp tutorial explains how they work. -Phil -- 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: Dynamic test creation?
I finally had a chance to try this out and it fails with error: java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IObj Compilation failed. When I substituted in something like this... (defn prn-form [n scenario] `(prn ~(str foo n) (prn ~(str n :: scenario the file did compile. Is the fact that deftest is also a macro going to cause a problem with the original idea? On Nov 2, 8:36 am, Nate Young youn...@gmail.com wrote: On 11/01/2011 03:05 PM, AndyK wrote: How would (run-tests 'my-namespace) know to run all thosedynamic tests? I thought that it parsed the namespace for 'my-namespace when you call it. Or is it that the call to defcsvtests sets off a chain of macro resolutions before run-tests can even do its thing (so that it Right. Its that the macro-expansion phase actually reads from the csv file in order to create a number of deftest forms, and each one then gets evaluated, so after you've evaluated (defcsvtests), then (run-tests) will be able to find a number of tests to run. -- 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
lein test with command-line args?
Is it possible to pass command-line arguments to tests using leiningen? Looking for ways to control the way that tests are run using lein test by passing in switches (e.g. which environment it runs against, which tests run, etc). One workaround that occurs to me is to use lein run where run calls run-tests directly, but that seems hacktacular. More generally, how would you set parameters for run-tests using command-line args or function args? -- 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: Korma - cannot acquire connections
My mistake in the original post - that should've read (sql/defenity mytable) Two seprate forms - the defentity + the select. On Nov 4, 3:21 pm, Base basselh...@gmail.com wrote: Did you mean to define the select within the defentity? (sql/defentity mytable (sql/select mytable (sql/fields :id) (sql/ where {:id 1}))) I does this work? (sql/defentity mytable (:pk YOUR PRIMARY KEY AS A KEYWORD) (table YOUR TABLE NAME AS A KEYWORD) (database devdb)) (sql/select mytable (sql/fields :id) (sql/where {:id 1})) On Nov 4, 10:44 am,AndyKandy.kri...@gmail.com wrote: I believe I have setup korma correctly with (require '[korma.db :as db]) (require '[korma.core :as sql]) (db/defdb devdb (db/mysql {:db mydb :host localhost :user me :password mypass})) (sql/defentity mytable (sql/select mytable (sql/fields :id) (sql/where {:id 1}))) But I'm getting SQLException: Message: Connections could not be acquired from the underlying database! SQLState: null Error Code: 0 (db/get-connection devdb) returns a clojure.lang.PersistentHashMap - is that right? or should it be the underlying java.sql.Connection? I have the mysql driver in my classpath, am able to Class/forName the driver, create a connection, and query on the connection - all manually. Korma looks pretty cool and I'd like to be using, any ideas? -- 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
Korma - cannot acquire connections
I believe I have setup korma correctly with (require '[korma.db :as db]) (require '[korma.core :as sql]) (db/defdb devdb (db/mysql {:db mydb :host localhost :user me :password mypass})) (sql/defentity mytable (sql/select mytable (sql/fields :id) (sql/where {:id 1}))) But I'm getting SQLException: Message: Connections could not be acquired from the underlying database! SQLState: null Error Code: 0 (db/get-connection devdb) returns a clojure.lang.PersistentHashMap - is that right? or should it be the underlying java.sql.Connection? I have the mysql driver in my classpath, am able to Class/forName the driver, create a connection, and query on the connection - all manually. Korma looks pretty cool and I'd like to be using, any ideas? -- 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
Update swank classpath on the fly?
I've noticed that swank (which I run in emacs using M-x clojure-jack- in) doesn't pickup changes to the classpath on-the-fly. For example, if I update my leiningen project.clj with a new dependency and run lein deps, I need to restart swank to have it use the library. Is there a way to load something into a running swank without restarting it (which causes loss of state in the slime-repl). thx -- 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
Problem passing a function into a function
I'm running into a strange problem that I can't see the bottom of. Wonder if someone can explain why I'm seeing the behavior I'm seeing... I have a function that uses a Java timer to run a function and can also check the results of that function by passing in an optional test function (defn timed-agent [limit timed-func test-func] (let [a (agent 0) ;; test-func can be defined here agent-func (fn [v] (let [result (timed-func v)] (when test-func (test-func result)) (inc v))) t (java.util.Timer.) tt (proxy [java.util.TimerTask] [] (run [] (send-off a agent- func)))] (set-validator! a #( limit %)) (.scheduleAtFixedRate t tt 1000 1000))) This works if I don't pass in a test function (timed-agent 10 prn) You will see output of 0 1 2 3...9 This does not work if I pass in a test function (timed-agent 10 prn prn) You will see output of 0 and nothing more This does work if I define test-func within the function (on the commented line) - ex, as prn You will see 0 nil 1 nil 2 nil...9 nil First question - why can't I pass in a test function and have the timer loop work as expected Second question - is there a better way for me to set an upper bound on a Java timer using Clojure? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Introspecting functions
Is it possible to print information about a function from within the repl? For example, after using comp or partial to create new functions, can you display the arity, the source, etc? I'm trying to debug a problem and it would be handy to be able to check that my dynamic funcitons are what I think they are. thx -- 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: Dynamic test creation?
How would (run-tests 'my-namespace) know to run all those dynamic tests? I thought that it parsed the namespace for 'my-namespace when you call it. Or is it that the call to defcsvtests sets off a chain of macro resolutions before run-tests can even do its thing (so that it appears to run-tests like a file full of deftests)? On Oct 31, 9:56 am, Nate Young youn...@gmail.com wrote: On 10/28/2011 09:42 AM, AndyK wrote: I am setting up tests with clojure.test that are driven by a CSV where each line represents one test case. Right now, there is a single deftest function that runs all the assertions. That's ok but creates reporting like 1 test was run with 1000s of assertions. Clojure being so dynamic, is it possible to create tests on-the-fly and run them where each dynamic test represents each row so that the reporting says X tests (where X == number of CSV rows). I'm fairly new to clojure and quite unfamiliar with the ins-and-outs of clojure.test. Any pointers here would be appreciated. Thank you It absolutely would be possible, and furthermore this is an area where macros really shine. I would choose macros because from what you describe, it sounds like you'd like to write a program that generates a bunch of deftest forms, and then runs those tests. But you need language facilities like reading from a csv file in order to do so. Clojure (and indeed all lisps) give you this ability. You could write a macro that reads in the CSV file and for each line, generates a deftest form. Below is a quick sketch of what it might look like if your CSV file consisted of two columns of values that were supposed to be equal to each other. (use 'clojure.test) (require '[clojure.java.io :as io] '[clojure.data.csv :as csv]) (defn testdef-form [n [expected actual]] `(deftest ~(str testfromline n) (is (= ~expected ~actual (defmacro defcsvtests [filename] (with-open [in-file (io/reader in-file.csv)] (let [testdefs (csv/read-csv in-file)] `(do ~@(map testdef-form (iterate inc 1) testdefs) (defcsvtests test-cases.csv) -- 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
Await and thread blocking?
I would like to block the thread until an agent has done its thing - in this case serving as a cap on a timer. I had thought that wrapping a call to the timed-agent function with await would do just that, but apparently not. At least in the repl, the function returns immediately and you can follow along as the agent updates until it's finished. (defn timed-agent [limit f] (let [a (agent 0) t (java.util.Timer.) tt (proxy [java.util.TimerTask] [] (run [] (send-off a (fn[v] (f) (inc v)] (set-validator! a #( limit %)) (.scheduleAtFixedRate t tt 1000 1000) a)) For example user (await (timed-agent 20 #(println running))) nil user (returns immediately and 20 running strings will be printed) user (def a (timed-agent 20 #(println running))) #'user/a user @a whatever the value of a is at the time Clearly I'm misunderstanding await + agents (not surprising - clojure is fairly new to me). Can someone clarify how await works and how one should block a thread for a timed task where you want a limit to the number of times it runs? thank you -- 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: Await and thread blocking?
After a bit more digging - Timer is a background thread so clearly that's not going to mesh well as a foreground blocking activity with agent (which is what I get for plugging along one path and trying to bring in another path without thinking things through). But the question remains - any ideas for using Timer while blocking the current thread? Is a future a better choice here? On Nov 1, 4:19 pm, AndyK andy.kri...@gmail.com wrote: I would like to block the thread until an agent has done its thing - in this case serving as a cap on a timer. I had thought that wrapping a call to the timed-agent function with await would do just that, but apparently not. At least in the repl, the function returns immediately and you can follow along as the agent updates until it's finished. (defn timed-agent [limit f] (let [a (agent 0) t (java.util.Timer.) tt (proxy [java.util.TimerTask] [] (run [] (send-off a (fn[v] (f) (inc v)] (set-validator! a #( limit %)) (.scheduleAtFixedRate t tt 1000 1000) a)) For example user (await (timed-agent 20 #(println running))) nil user (returns immediately and 20 running strings will be printed) user (def a (timed-agent 20 #(println running))) #'user/a user @a whatever the value of a is at the time Clearly I'm misunderstanding await + agents (not surprising - clojure is fairly new to me). Can someone clarify how await works and how one should block a thread for a timed task where you want a limit to the number of times it runs? thank you -- 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: Await and thread blocking?
Sometimes the obvious is too obvious - call timed-agent and then Thread/sleep while the timer of known duration runs. One further question however, is there any significant difference between calling the timed-agent worker function in send-off or in add-watch? For my needs, the task that runs does not depend on the value of the agent - the agent is just a convenient way to limit the timer. On Nov 1, 4:29 pm, AndyK andy.kri...@gmail.com wrote: After a bit more digging - Timer is a background thread so clearly that's not going to mesh well as a foreground blocking activity with agent (which is what I get for plugging along one path and trying to bring in another path without thinking things through). But the question remains - any ideas for using Timer while blocking the current thread? Is a future a better choice here? On Nov 1, 4:19 pm, AndyK andy.kri...@gmail.com wrote: I would like to block the thread until an agent has done its thing - in this case serving as a cap on a timer. I had thought that wrapping a call to the timed-agent function with await would do just that, but apparently not. At least in the repl, the function returns immediately and you can follow along as the agent updates until it's finished. (defn timed-agent [limit f] (let [a (agent 0) t (java.util.Timer.) tt (proxy [java.util.TimerTask] [] (run [] (send-off a (fn[v] (f) (inc v)] (set-validator! a #( limit %)) (.scheduleAtFixedRate t tt 1000 1000) a)) For example user (await (timed-agent 20 #(println running))) nil user (returns immediately and 20 running strings will be printed) user (def a (timed-agent 20 #(println running))) #'user/a user @a whatever the value of a is at the time Clearly I'm misunderstanding await + agents (not surprising - clojure is fairly new to me). Can someone clarify how await works and how one should block a thread for a timed task where you want a limit to the number of times it runs? thank you -- 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
Dynamic test creation?
I am setting up tests with clojure.test that are driven by a CSV where each line represents one test case. Right now, there is a single deftest function that runs all the assertions. That's ok but creates reporting like 1 test was run with 1000s of assertions. Clojure being so dynamic, is it possible to create tests on-the-fly and run them where each dynamic test represents each row so that the reporting says X tests (where X == number of CSV rows). I'm fairly new to clojure and quite unfamiliar with the ins-and-outs of clojure.test. Any pointers here would be appreciated. Thank you -- 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
Lazytest on the repl?
How can lazytest describe blocks be run from the repl? -- 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