Re: How to make a static variable dynamic at runtime?
Hello Alexander, Marc, Ah, now I get this. Thank you for your responses! вторник, 21 июля 2015 г., 17:54:42 UTC+3 пользователь Yuri Govorushchenko написал: The problem I'm trying to solve is how to stub a variable (e.g. a function from a third-party lib) in tests so that the stubbing occurs only in the current thread with other threads continuing using var's root value. It's important because unit tests may be run in parallel. Without thread-local binding two threads stubbing the same function will lead to race conditions: (binding [somelib/foo foo-stub] ; throws java.lang.IllegalStateException: Can't dynamically bind non-dynamic var ; invoke tested code which depends on foo ; assert stuff ) I've tried to use *.setDynamic* (as described in blog post [1]) but it doesn't work without direct *deref*-ing of the var: (def static-var 123) (defn quz[] (.setDynamic #'static-var true) (binding [static-var 1000] (println static-var = static-var deref = @#'static-var))) (quz) ; = static-var = 123 deref = 1000 This approach seems to be used in a recent *bolth* lib [2]. And The strange thing is that in REPL running this code line by line works: user= (def static-var 123) #'user/static-var user= (.setDynamic #'static-var true) #'user/static-var user= (binding [static-var 1000] (println static-var = static-var)) static-var = 1000 Looking at Var class implementation I couldn't figure out why . *setDynamic* call wouldn't work. My guess is that compiler somehow caches initial static Var value for performance reasons?.. So the questions are: 1) Is it a bug that *.setDynamic* + *binding* don't work? 2) Is there any other way to temporally rebind static variable thread-locally? Considering I can't add *^:dynamic* into third-party lib and don't want to write a wrapper or use dependency injection in order to explicitly substitute the dependency in my unit tests. 3) Is there a Clojure parallel test runner which runs tests in new processes instead of threads? This would eliminate any race conditions. Python's *nose* test runner works this way [3]. 4) Maybe crazy: does Clojure allow dynamically rebinding the symbol to a new Var instance so that I could set *'static-var* to point at *(.setDynamic (Var/create)*? 5) Even crazier idea: can I change the nature of the var so that it behaves like an InheritedThreadLocal instead of ThreadLocal, but without forcing a user to *deref* it (as it was described in [4])? Links: [1] http://blog.zolotko.me/2012/06/making-variable-dynamic-in-clojure.html [2] https://github.com/yeller/bolth/blob/323532683e3f66ae11566db5423c1e927e51818e/src/bolth/runner.clj#L99 [3] http://nose.readthedocs.org/en/latest/doc_tests/test_multiprocess/multiprocess.html [4] https://aphyr.com/posts/240-configuration-and-scope - see Thread-inheritable dynamic vars in 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 --- 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: confusion about some paragraph in book clojure programming By Chas Emerick, Brian Carper, Christophe Grand 2012
The vector of parameter names is matched to the actual parameter values when the fn is called, so it's equivalent to (let [x val1 y val2] ...) when (hypot val1 val2) is called. -- Fergal Byrne, Brenter IT Author, Real Machine Intelligence with Clortex and NuPIC https://leanpub.com/realsmartmachines Speaking on Clortex and HTM/CLA at euroClojure Krakow, June 2014: http://euroclojure.com/2014/ and at LambdaJam Chicago, July 2014: http://www.lambdajam.com http://inbits.com - Better Living through Thoughtful Technology http://ie.linkedin.com/in/fergbyrne/ - https://github.com/fergalbyrne e:fergalbyrnedub...@gmail.com t:+353 83 4214179 Join the quest for Machine Intelligence at http://numenta.org Formerly of Adnet edi...@adnet.ie http://www.adnet.ie On Wed, Jul 22, 2015 at 1:25 PM, Gary Trakhman gary.trakh...@gmail.com wrote: I am looking at the definition of fn and I can't see where let is used inside the function definition: https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L4335 I think they're saying the binding forms are equivalent in power (destructuring), not implementation. On Wed, Jul 22, 2015 at 8:07 AM Johnny Wong zhanlandet...@gmail.com wrote: page 27(pdf version): Local Bindings: let let allows you to define named references that are lexically scoped to the extent of the let expression. Said another way, let defines locals. .. ... Note that let is implicitly used anywhere locals are required. In particular, fn (and therefore all other function-creation and function-definition forms like defn) uses let to bind function parameters as locals within the scope of the function being defined. For example, x and y in the hypot function above are let-bound by defn. *So, the vector that defines the set of bindings for a let scope obeys the same semantics whether it is used to define function parameters or an auxiliary local binding scope.* ** i am confused about the text in red. apparently ,the vector used for let locale binding is not the same as the vector used for function parameters , for example (defn hypot [x y] (let [x2 (* x x) y2 (* y y)] (Math/sqrt (+ x2 y2))) ) the second line [x y] vector says the function has two parameter, it doesn't mean let x=y, while , the third line ,it means let x2=(* x x), it is set value operation. is it a book error ? -- 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. -- 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.
run Clojurescript via %magic in an iPython notebook?
It is apparently possible to run javascript via magic commands in iPython notebooks (https://ipython.org/ipython-doc/3/interactive/magics.html). I assume that this would make it possible also to use Clojurescript, but I don't know what would be involved. I have a fair bit of Clojure experience but little experience with Clojurescript or Javascript, and I'm new to iPython. Does anyone have experience with this or interest in looking into it? I am familiar with the wonderful Gorilla REPL, which provides a similar notebook-like environment for Clojure (http://gorilla-repl.org), but my question here is in the context of a course in which I'll be teaching Python. It might be both fun and useful to sneak in a little Clojure/Clojurescript from time to time. Thanks, -Lee -- 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.
Best Practice on loading namespaces
I've begun building a rather complex web application in Clojure/ClojureScript. After some evaluation I decided that CQRS + event sourcing would fit the requirements well. As such I have a bunch of aggregates (models) each in their own namespace that contain all the applicable record definitions, their invariants, and the commands each responds to. Predictably there are numerous operations that are similar between all aggregates. In my controllers I will be evaluating JSON requests and creating a list of commands based on those requests. I would like to dynamically dispatch the commands to the aggregates and let the aggregates handle them by either returning more commands or committing an event to the db. What is the best practice to dynamically send a command to an aggregate's namespace? I'm aware of solutions that make use of protocols and multimethods. My primary concern is where should I be requiring the aggregate namespaces? Is it best to do as some web frameworks do and just require everything (all namespaces) in some kind of application wide superset (probably using tools.namespace). Should I have a superset for each type of namespace (eg all controllers required together, all aggregates ...) or should I only require a namespace on an as needed basis. If so how would I achieve dynamic dispatch between aggregates without requiring their namespace. Sorry I'm still pretty new to Clojure. I know I can achieve this in a number of ways, but I'm looking for the most idiomatic approach that will cause the least headaches as this application grows. -- 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: Best Practice on loading namespaces
Ah, one of the eternal questions, so there isn’t really a ‘do this’ answer. My experience: [multi-methods/protocols] You need to include the namespace they are compiled in for those methods to take effect and because they are defn’d at the root you cannot provide collaborators easily. You cannot DI collaborators into the multi-method implementations. Of course, you can use thread local binding but this is less than satisfactory as your functions are no longer pure. Another workaround is to always pass a map of collaborators around…no, I can’t even finish that sentence. I have also seen (defn) happening inside other fns which always makes me shiver, but you could defn the multi method inside the component record which has access to the collaborators. [service registry] I went the other way and had a central service that consumers registered with. My command-bus had a (defprotocol IHandle (can-handle [this cmd]) (handle [this cmd]). I then had a number of (Stuart Sierra’s) components which, when started, registered with their implementations of IHandle with the command-bus for the commands they needed. These command-handlers were typically injected with the collaborators and then delegated to the ‘domain’ fns. My actual ‘domain’ was only ever a map with was constructed by (reduce {} events) - lovely! ‘typed-straight-into-email’ and very incomplete pseudocode: (ns command-bus) (defprotocol IHandle (can-handle [this cmd]) (handle [this cmd]) (defprotocol IAmACommandBus (register [this handler]…)) (defrecord CommandBus [registry] IAmACommandBus (register [this handler] (assoc! registry #(conj handler (defn command-bus [] (-CommandBus (atom []))) (ns ar-1.domain) ;; the ‘pure’ domain functions which can be easily tested (defn do-something [ar some-state] [ar-id (:id ar) :version (inc (:version ar)) :event-type :woot {:this :worked}])) (ns ar-1.service (:require [:command-bus :as command-bus] [:ar-1.domain :as domain]) ;; the command handler (defrecord DoSomethingCommandHandler [repository some-service] command-bus/IHandle (can-handle [this cmd] (= :do-something-with-ar-1 (:command-type cmd)) (handle [this cmd] (let [ar (repository-api/hydrate repository (:ar-id cmd) some-state (some-service (:something cmd))] (domain/do-something ar some-state))..) (defrecord DoSomethingElseCommandHandler [some-other-service] ….) (defrecord DomainComponent [command-bus repository some-service some-other-service] component/Lifecycle (start [_] (command-bus/register command-bus (-DoSomethingCommandHandler repository some-service)) (command-bus/register command-bus (-DoSomethingElseCommandHandler some-other-service)) (stop [_] …)) (ns the-app (:require [command-bus :as command-bus] [some-service….] [some-other-service…] [ar-1.service :as ar-1]) (let [systems {:command-bus (command-bus/command-bus) :ar-1 (component/using (ar-1/ar-1) [:command-bus :some-service :some-other-service]}] ;; start the system etc.)) Thoughts: - boiler plate ‘wiring’ up is done in the .service layer which contains domain services that delegate straight to pure domain fns - DomainCommandHandlers could themselves be Components but this felt cleaner - the very common repetition can be handled by a macro if needed - if no extra collaborators are needed then sure, the domain-fns can be multi-methods, fine - a lot of plumbing but it keeps it very clean. - start using Prismatic schema and/or Clojure core.typed from the beginning Hopefully that is enough to get to started? On 22 Jul 2015, at 16:24, keegan myers keeganmyers...@gmail.com wrote: I've begun building a rather complex web application in Clojure/ClojureScript. After some evaluation I decided that CQRS + event sourcing would fit the requirements well. As such I have a bunch of aggregates (models) each in their own namespace that contain all the applicable record definitions, their invariants, and the commands each responds to. Predictably there are numerous operations that are similar between all aggregates. In my controllers I will be evaluating JSON requests and creating a list of commands based on those requests. I would like to dynamically dispatch the commands to the aggregates and let the aggregates handle them by either returning more commands or committing an event to the db. What is the best practice to dynamically send a command to an aggregate's namespace? I'm aware of solutions that make use of protocols and multimethods. My primary concern is where should I be requiring the aggregate namespaces? Is it best to do as some web frameworks do and just require everything (all namespaces) in some kind of application wide superset (probably using tools.namespace). Should I have a superset for each type of namespace (eg all controllers
Re: [clojure-rabbitmq] The execution hangs when nested publish inside consumer handler function
I posted the code snippet that can cause the issue on github. Also posted differences in network trace between blocking and success run that I've noticed there. The output from rabbitmqctl eval `rabbitmq_diagnostics:maybe_stuck().` is Error: {undef,[{rabbitmq_diagnostics,maybe_stuck,[],[]}, {erl_eval,do_apply,6,[{file,erl_eval.erl},{line,657}]}, {rpc,'-handle_call_call/6-fun-0-',5, [{file,rpc.erl},{line,205}]}]} On Tuesday, July 21, 2015 at 5:47:44 PM UTC+7, Michael Klishin wrote: On 21 Jul 2015 at 11:17:50, Nuttanart Pornprasitsakul (visib...@gmail.com javascript:) wrote: Follow up from the issue #74 I created on Github( https://github.com/michaelklishin/langohr/issues/74). Sorry that I posted there. It doesn't eventually unblock, both in and out queue are in idle state not flow state. I'll get back again with the log and thread dump. There’s nothing unusual in the thread stack traces. We need a Wireshark protocol capture. rabbitmqctl eval `rabbitmq_diagnostics:maybe_stuck().` output may also help. -- MK Staff Software Engineer, Pivotal/RabbitMQ -- You received this message because you are subscribed to the Google Groups clojure-rabbitmq group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure-rabbitmq+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Paper on Immutable Persistent Data Structures
I think Chapter 2 from here http://daly.axiom-developer.org/clojure.pdf could be helpful. вторник, 21 июля 2015 г., 2:43:54 UTC+3 пользователь JvJ написал: Does anyone know if there exists a paper/web page describing in detail how each of Clojure's data structures are implemented? -- 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: How to make a static variable dynamic at runtime?
Thank you for a reply, I totally agree with you on dependency injection. Though I'm exercising in writing a mocking framework and thought it would be an interesting feature to implement a thread-safe mocking of an implicit dependency. среда, 22 июля 2015 г., 5:03:36 UTC+3 пользователь Surgo написал: Not that it's the answer you're looking for, but usually this is when you rewrite the code you're testing to use dependency injection (ie, take the var of interest as an argument instead of a global or in its lexical environment). -- Morgon On Tuesday, July 21, 2015 at 10:54:42 AM UTC-4, Yuri Govorushchenko wrote: The problem I'm trying to solve is how to stub a variable (e.g. a function from a third-party lib) in tests so that the stubbing occurs only in the current thread with other threads continuing using var's root value. It's important because unit tests may be run in parallel. Without thread-local binding two threads stubbing the same function will lead to race conditions: (binding [somelib/foo foo-stub] ; throws java.lang.IllegalStateException: Can't dynamically bind non-dynamic var ; invoke tested code which depends on foo ; assert stuff ) I've tried to use *.setDynamic* (as described in blog post [1]) but it doesn't work without direct *deref*-ing of the var: (def static-var 123) (defn quz[] (.setDynamic #'static-var true) (binding [static-var 1000] (println static-var = static-var deref = @#'static-var))) (quz) ; = static-var = 123 deref = 1000 This approach seems to be used in a recent *bolth* lib [2]. And The strange thing is that in REPL running this code line by line works: user= (def static-var 123) #'user/static-var user= (.setDynamic #'static-var true) #'user/static-var user= (binding [static-var 1000] (println static-var = static-var)) static-var = 1000 Looking at Var class implementation I couldn't figure out why . *setDynamic* call wouldn't work. My guess is that compiler somehow caches initial static Var value for performance reasons?.. So the questions are: 1) Is it a bug that *.setDynamic* + *binding* don't work? 2) Is there any other way to temporally rebind static variable thread-locally? Considering I can't add *^:dynamic* into third-party lib and don't want to write a wrapper or use dependency injection in order to explicitly substitute the dependency in my unit tests. 3) Is there a Clojure parallel test runner which runs tests in new processes instead of threads? This would eliminate any race conditions. Python's *nose* test runner works this way [3]. 4) Maybe crazy: does Clojure allow dynamically rebinding the symbol to a new Var instance so that I could set *'static-var* to point at *(.setDynamic (Var/create)*? 5) Even crazier idea: can I change the nature of the var so that it behaves like an InheritedThreadLocal instead of ThreadLocal, but without forcing a user to *deref* it (as it was described in [4])? Links: [1] http://blog.zolotko.me/2012/06/making-variable-dynamic-in-clojure.html [2] https://github.com/yeller/bolth/blob/323532683e3f66ae11566db5423c1e927e51818e/src/bolth/runner.clj#L99 [3] http://nose.readthedocs.org/en/latest/doc_tests/test_multiprocess/multiprocess.html [4] https://aphyr.com/posts/240-configuration-and-scope - see Thread-inheritable dynamic vars in 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 --- 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: [ANN] Replete ClojureScript REPL iOS app available
Wow. That will be great. On Tuesday, July 21, 2015 at 1:01:36 PM UTC-5, Mike Fikes wrote: Yes, that's part of what I have in mind, in addition to downloading JARs from, say, Clojars. On Jul 21, 2015, at 1:55 PM, Fergal Byrne fergalby...@gmail.com javascript: wrote: Really nice, thanks Mike for such a clean app. One suggestion: would it be possible to use the documents interface in iTunes to drop in jar files (the same way you drop books into Kindle)? We could then use the app like a real 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 --- 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-rabbitmq] The execution hangs when nested publish inside consumer handler function
On 22 Jul 2015 at 10:46:18, Nuttanart Pornprasitsakul (visiblet...@gmail.com) wrote: I posted the code snippet that can cause the issue on github. Also posted differences in network trace between blocking and success run that I've noticed there. Thanks, this is a fairly busy week for me with 3 releases but I will take a look in the next few days. The output from rabbitmqctl eval `rabbitmq_diagnostics:maybe_stuck().` is Error: {undef,[{rabbitmq_diagnostics,maybe_stuck,[],[]}, {erl_eval,do_apply,6,[{file,erl_eval.erl},{line,657}]}, {rpc,'-handle_call_call/6-fun-0-',5, [{file,rpc.erl},{line,205}]}]} This means your version doesn’t have that function (it’s fairly new, I think 3.5.x) -- MK Staff Software Engineer, Pivotal/RabbitMQ -- You received this message because you are subscribed to the Google Groups clojure-rabbitmq group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure-rabbitmq+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: confusion about some paragraph in book clojure programming By Chas Emerick, Brian Carper, Christophe Grand 2012
clear, thanks for your reply, i am new clojure learner , i am trying to fully understand the book, On Wednesday, July 22, 2015 at 11:48:06 PM UTC+8, Fergal Byrne wrote: The vector of parameter names is matched to the actual parameter values when the fn is called, so it's equivalent to (let [x val1 y val2] ...) when (hypot val1 val2) is called. -- Fergal Byrne, Brenter IT Author, Real Machine Intelligence with Clortex and NuPIC https://leanpub.com/realsmartmachines Speaking on Clortex and HTM/CLA at euroClojure Krakow, June 2014: http://euroclojure.com/2014/ and at LambdaJam Chicago, July 2014: http://www.lambdajam.com http://inbits.com - Better Living through Thoughtful Technology http://ie.linkedin.com/in/fergbyrne/ - https://github.com/fergalbyrne e:fergalb...@gmail.com javascript: t:+353 83 4214179 Join the quest for Machine Intelligence at http://numenta.org Formerly of Adnet edi...@adnet.ie javascript: http://www.adnet.ie On Wed, Jul 22, 2015 at 1:25 PM, Gary Trakhman gary.t...@gmail.com javascript: wrote: I am looking at the definition of fn and I can't see where let is used inside the function definition: https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L4335 I think they're saying the binding forms are equivalent in power (destructuring), not implementation. On Wed, Jul 22, 2015 at 8:07 AM Johnny Wong zhanla...@gmail.com javascript: wrote: page 27(pdf version): Local Bindings: let let allows you to define named references that are lexically scoped to the extent of the let expression. Said another way, let defines locals. .. ... Note that let is implicitly used anywhere locals are required. In particular, fn (and therefore all other function-creation and function-definition forms like defn) uses let to bind function parameters as locals within the scope of the function being defined. For example, x and y in the hypot function above are let-bound by defn. *So, the vector that defines the set of bindings for a let scope obeys the same semantics whether it is used to define function parameters or an auxiliary local binding scope.* ** i am confused about the text in red. apparently ,the vector used for let locale binding is not the same as the vector used for function parameters , for example (defn hypot [x y] (let [x2 (* x x) y2 (* y y)] (Math/sqrt (+ x2 y2))) ) the second line [x y] vector says the function has two parameter, it doesn't mean let x=y, while , the third line ,it means let x2=(* x x), it is set value operation. is it a book error ? -- 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. -- 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. -- 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-rabbitmq] Re: Reusing channel in message handler function
On Wednesday, July 22, 2015 at 12:14:36 PM UTC+3, Nuttanart Pornprasitsakul wrote: Hi, This question is related to blocking issue that I'm asking https://github.com/michaelklishin/langohr/issues/74, but I think better separating this to prevent putting more noises in that issue. I started to think that the issue that happens to me causes by opening and closing channel to often in the subscribe handler function (the snippet below extracted from here https://github.com/michaelklishin/langohr/issues/74#issuecomment-123536849 ) (lc/subscribe channel source (fn [ch meta message] (let [pub-ch (lch/open conn)] (lb/publish pub-ch destination (str message)) (lch/close pub-ch)) (lb/ack ch (:delivery-tag meta The reason I keep doing it this way is because in the Java RabbitMQ client Channel documentation https://www.rabbitmq.com/releases/rabbitmq-java-client/current-javadoc/com/rabbitmq/client/Channel.html says that a channel shouldn't be shared between threads. As my understanding, message handler function can be executed in multiple threads that's why I create a new channel and close it within the handler function. But from my other test results, it seems like sharing channel between threads making handler function run a lot faster and importantly, blocking issue doesn't happen. You can reuse the channel in this particular case. Yes, consumer methods will be executed in a thread pool but per-channel ordering is guaranteed by the Java client (ConsumerWorkService, in case you wonder). I didn't realise you were closing and opening channels inside a delivery handler. That should not be necessary and sounds more dangerous than technically having channel sharing ;) Thread sharing is a no-go if you intend to publish on a channel concurrently. As I explained in above, Java client will effectively make publishing sequential in your case. If this solves the blocking issue for you, I'd simply recommend you publish responses on the same channel your deliveries are on (this is why the callback has `ch` as the first argument!) and move on :) MK -- You received this message because you are subscribed to the Google Groups clojure-rabbitmq group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure-rabbitmq+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Project Better Clojure/Android integration
I believe student application for GSoC 2015 is already closed at March, you can only try it next year. 2015-07-23 11:12 GMT+08:00 Devang Shah devang221...@gmail.com: Can anyone please help? On Saturday, July 18, 2015 at 8:33:58 PM UTC-7, Devang Shah wrote: Hello I am a master's student and would like to contribute to the clojure/android platform. I found this project http://dev.clojure.org/display/community/Project+Ideas#ProjectIdeas-BetterClojureAndroidintegration on the project ideas site for GSoC 2015. I was hoping to submit the project proposal, however could not submit the proposal. I was wondering, if I still take up the project, will anyone be able to mentor me (very little time, by answering my questions on google groups). I checked the GSoC 2015 website and this is not something that's done by any student for GSoC 15. I also would like to take this project as my master's project, if that's OK to do so. I know Clojure (decent), Android(pretty good), Leiningen(used it for Clojure programming) and Gradle (beginner). Can someone please help me getting started and also comment on this? Thank you. Devang -- 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: Project Better Clojure/Android integration
I know, it's over. Can I do it as a project outside of the GSoC? I believe it should not be a problem. Would it be? On Wednesday, July 22, 2015 at 9:14:30 PM UTC-7, Di Xu wrote: I believe student application for GSoC 2015 is already closed at March, you can only try it next year. 2015-07-23 11:12 GMT+08:00 Devang Shah devang...@gmail.com javascript: : Can anyone please help? On Saturday, July 18, 2015 at 8:33:58 PM UTC-7, Devang Shah wrote: Hello I am a master's student and would like to contribute to the clojure/android platform. I found this project http://dev.clojure.org/display/community/Project+Ideas#ProjectIdeas-BetterClojureAndroidintegration on the project ideas site for GSoC 2015. I was hoping to submit the project proposal, however could not submit the proposal. I was wondering, if I still take up the project, will anyone be able to mentor me (very little time, by answering my questions on google groups). I checked the GSoC 2015 website and this is not something that's done by any student for GSoC 15. I also would like to take this project as my master's project, if that's OK to do so. I know Clojure (decent), Android(pretty good), Leiningen(used it for Clojure programming) and Gradle (beginner). Can someone please help me getting started and also comment on this? Thank you. Devang -- 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. -- 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: Project Better Clojure/Android integration
Can anyone please help? On Saturday, July 18, 2015 at 8:33:58 PM UTC-7, Devang Shah wrote: Hello I am a master's student and would like to contribute to the clojure/android platform. I found this project http://dev.clojure.org/display/community/Project+Ideas#ProjectIdeas-BetterClojureAndroidintegration on the project ideas site for GSoC 2015. I was hoping to submit the project proposal, however could not submit the proposal. I was wondering, if I still take up the project, will anyone be able to mentor me (very little time, by answering my questions on google groups). I checked the GSoC 2015 website and this is not something that's done by any student for GSoC 15. I also would like to take this project as my master's project, if that's OK to do so. I know Clojure (decent), Android(pretty good), Leiningen(used it for Clojure programming) and Gradle (beginner). Can someone please help me getting started and also comment on this? Thank you. Devang -- 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: Project Better Clojure/Android integration
Talk to the people on this forum https://groups.google.com/forum/#!forum/clojure-android and see how you go. I am sure that they would welcome your participation. There was an talk at euroclojure by Alexander Yakushev: https://www.youtube.com/watch?v=mVXTcAEKgF8 Dave On Thursday, 23 July 2015 14:33:15 UTC+10, Devang Shah wrote: I know, it's over. Can I do it as a project outside of the GSoC? I believe it should not be a problem. Would it be? On Wednesday, July 22, 2015 at 9:14:30 PM UTC-7, Di Xu wrote: I believe student application for GSoC 2015 is already closed at March, you can only try it next year. 2015-07-23 11:12 GMT+08:00 Devang Shah devang...@gmail.com: Can anyone please help? On Saturday, July 18, 2015 at 8:33:58 PM UTC-7, Devang Shah wrote: Hello I am a master's student and would like to contribute to the clojure/android platform. I found this project http://dev.clojure.org/display/community/Project+Ideas#ProjectIdeas-BetterClojureAndroidintegration on the project ideas site for GSoC 2015. I was hoping to submit the project proposal, however could not submit the proposal. I was wondering, if I still take up the project, will anyone be able to mentor me (very little time, by answering my questions on google groups). I checked the GSoC 2015 website and this is not something that's done by any student for GSoC 15. I also would like to take this project as my master's project, if that's OK to do so. I know Clojure (decent), Android(pretty good), Leiningen(used it for Clojure programming) and Gradle (beginner). Can someone please help me getting started and also comment on this? Thank you. Devang -- 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. -- 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: How to make a static variable dynamic at runtime?
Sorry, didn't link to the exact time. The correct link is: https://youtu.be/8NUI07y1SlQ?t=217 -- 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: How to make a static variable dynamic at runtime?
Hello Yuri, You probably need something like with-redefs[1] to do mocking. Setting a var to dynamic at runtime will have impact only on code that was *compiled* after doing that. See the excerpt from Daniel's talk about this behavior[2]. [1] http://conj.io/store/v1/org.clojure/clojure/1.7.0/clj/clojure.core/with-redefs/ [2] https://www.youtube.com/watch?v=8NUI07y1SlQ Best regards, Alex On Tuesday, July 21, 2015 at 5:54:42 PM UTC+3, Yuri Govorushchenko wrote: The problem I'm trying to solve is how to stub a variable (e.g. a function from a third-party lib) in tests so that the stubbing occurs only in the current thread with other threads continuing using var's root value. It's important because unit tests may be run in parallel. Without thread-local binding two threads stubbing the same function will lead to race conditions: (binding [somelib/foo foo-stub] ; throws java.lang.IllegalStateException: Can't dynamically bind non-dynamic var ; invoke tested code which depends on foo ; assert stuff ) I've tried to use *.setDynamic* (as described in blog post [1]) but it doesn't work without direct *deref*-ing of the var: (def static-var 123) (defn quz[] (.setDynamic #'static-var true) (binding [static-var 1000] (println static-var = static-var deref = @#'static-var))) (quz) ; = static-var = 123 deref = 1000 This approach seems to be used in a recent *bolth* lib [2]. And The strange thing is that in REPL running this code line by line works: user= (def static-var 123) #'user/static-var user= (.setDynamic #'static-var true) #'user/static-var user= (binding [static-var 1000] (println static-var = static-var)) static-var = 1000 Looking at Var class implementation I couldn't figure out why . *setDynamic* call wouldn't work. My guess is that compiler somehow caches initial static Var value for performance reasons?.. So the questions are: 1) Is it a bug that *.setDynamic* + *binding* don't work? 2) Is there any other way to temporally rebind static variable thread-locally? Considering I can't add *^:dynamic* into third-party lib and don't want to write a wrapper or use dependency injection in order to explicitly substitute the dependency in my unit tests. 3) Is there a Clojure parallel test runner which runs tests in new processes instead of threads? This would eliminate any race conditions. Python's *nose* test runner works this way [3]. 4) Maybe crazy: does Clojure allow dynamically rebinding the symbol to a new Var instance so that I could set *'static-var* to point at *(.setDynamic (Var/create)*? 5) Even crazier idea: can I change the nature of the var so that it behaves like an InheritedThreadLocal instead of ThreadLocal, but without forcing a user to *deref* it (as it was described in [4])? Links: [1] http://blog.zolotko.me/2012/06/making-variable-dynamic-in-clojure.html [2] https://github.com/yeller/bolth/blob/323532683e3f66ae11566db5423c1e927e51818e/src/bolth/runner.clj#L99 [3] http://nose.readthedocs.org/en/latest/doc_tests/test_multiprocess/multiprocess.html [4] https://aphyr.com/posts/240-configuration-and-scope - see Thread-inheritable dynamic vars in 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 --- 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: How to make a static variable dynamic at runtime?
Hi Yuri, You need to call .setDynamic before the access to the var is compiled. In your test, the call to .setDynamic is invoked when the function is called, which is after the function has been compiled. So when compiler sees the read of static-var the var is still static, and it can emit a read of the static var (or inline the value, I'm not sure which approach the compiler takes). If the var is dynamic when a form is compiled that reads the var, a dynamic look-up can be emitted. Try this: (def static-var 123) (.setDynamic #'static-var true) (defn quz[] (binding [static-var 1000] (println static-var = static-var deref = @#'static-var))) (quz) ; = static-var = 1000 deref = 1000 static-var ; = 123 This doesn't help much when the var is defined in a library though, since the library will be compiled before you get a chance to set the var to be dynamic. It explains the behaviour that you are seeing though. Marc On 22 July 2015 at 13:13, Yuri Govorushchenko yuri.go...@gmail.com wrote: Thank you for a reply, I totally agree with you on dependency injection. Though I'm exercising in writing a mocking framework and thought it would be an interesting feature to implement a thread-safe mocking of an implicit dependency. среда, 22 июля 2015 г., 5:03:36 UTC+3 пользователь Surgo написал: Not that it's the answer you're looking for, but usually this is when you rewrite the code you're testing to use dependency injection (ie, take the var of interest as an argument instead of a global or in its lexical environment). -- Morgon On Tuesday, July 21, 2015 at 10:54:42 AM UTC-4, Yuri Govorushchenko wrote: The problem I'm trying to solve is how to stub a variable (e.g. a function from a third-party lib) in tests so that the stubbing occurs only in the current thread with other threads continuing using var's root value. It's important because unit tests may be run in parallel. Without thread-local binding two threads stubbing the same function will lead to race conditions: (binding [somelib/foo foo-stub] ; throws java.lang.IllegalStateException: Can't dynamically bind non-dynamic var ; invoke tested code which depends on foo ; assert stuff ) I've tried to use .setDynamic (as described in blog post [1]) but it doesn't work without direct deref-ing of the var: (def static-var 123) (defn quz[] (.setDynamic #'static-var true) (binding [static-var 1000] (println static-var = static-var deref = @#'static-var))) (quz) ; = static-var = 123 deref = 1000 This approach seems to be used in a recent bolth lib [2]. And The strange thing is that in REPL running this code line by line works: user= (def static-var 123) #'user/static-var user= (.setDynamic #'static-var true) #'user/static-var user= (binding [static-var 1000] (println static-var = static-var)) static-var = 1000 Looking at Var class implementation I couldn't figure out why .setDynamic call wouldn't work. My guess is that compiler somehow caches initial static Var value for performance reasons?.. So the questions are: 1) Is it a bug that .setDynamic + binding don't work? 2) Is there any other way to temporally rebind static variable thread-locally? Considering I can't add ^:dynamic into third-party lib and don't want to write a wrapper or use dependency injection in order to explicitly substitute the dependency in my unit tests. 3) Is there a Clojure parallel test runner which runs tests in new processes instead of threads? This would eliminate any race conditions. Python's nose test runner works this way [3]. 4) Maybe crazy: does Clojure allow dynamically rebinding the symbol to a new Var instance so that I could set 'static-var to point at (.setDynamic (Var/create)? 5) Even crazier idea: can I change the nature of the var so that it behaves like an InheritedThreadLocal instead of ThreadLocal, but without forcing a user to deref it (as it was described in [4])? Links: [1] http://blog.zolotko.me/2012/06/making-variable-dynamic-in-clojure.html [2] https://github.com/yeller/bolth/blob/323532683e3f66ae11566db5423c1e927e51818e/src/bolth/runner.clj#L99 [3] http://nose.readthedocs.org/en/latest/doc_tests/test_multiprocess/multiprocess.html [4] https://aphyr.com/posts/240-configuration-and-scope - see Thread-inheritable dynamic vars in 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 --- 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
confusion about some paragraph in book clojure programming By Chas Emerick, Brian Carper, Christophe Grand 2012
page 27(pdf version): Local Bindings: let let allows you to define named references that are lexically scoped to the extent of the let expression. Said another way, let defines locals. .. ... Note that let is implicitly used anywhere locals are required. In particular, fn (and therefore all other function-creation and function-definition forms like defn) uses let to bind function parameters as locals within the scope of the function being defined. For example, x and y in the hypot function above are let-bound by defn. *So, the vector that defines the set of bindings for a let scope obeys the same semantics whether it is used to define function parameters or an auxiliary local binding scope.* ** i am confused about the text in red. apparently ,the vector used for let locale binding is not the same as the vector used for function parameters , for example (defn hypot [x y] (let [x2 (* x x) y2 (* y y)] (Math/sqrt (+ x2 y2))) ) the second line [x y] vector says the function has two parameter, it doesn't mean let x=y, while , the third line ,it means let x2=(* x x), it is set value operation. is it a book error ? -- 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: confusion about some paragraph in book clojure programming By Chas Emerick, Brian Carper, Christophe Grand 2012
I am looking at the definition of fn and I can't see where let is used inside the function definition: https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L4335 I think they're saying the binding forms are equivalent in power (destructuring), not implementation. On Wed, Jul 22, 2015 at 8:07 AM Johnny Wong zhanlandet...@gmail.com wrote: page 27(pdf version): Local Bindings: let let allows you to define named references that are lexically scoped to the extent of the let expression. Said another way, let defines locals. .. ... Note that let is implicitly used anywhere locals are required. In particular, fn (and therefore all other function-creation and function-definition forms like defn) uses let to bind function parameters as locals within the scope of the function being defined. For example, x and y in the hypot function above are let-bound by defn. *So, the vector that defines the set of bindings for a let scope obeys the same semantics whether it is used to define function parameters or an auxiliary local binding scope.* ** i am confused about the text in red. apparently ,the vector used for let locale binding is not the same as the vector used for function parameters , for example (defn hypot [x y] (let [x2 (* x x) y2 (* y y)] (Math/sqrt (+ x2 y2))) ) the second line [x y] vector says the function has two parameter, it doesn't mean let x=y, while , the third line ,it means let x2=(* x x), it is set value operation. is it a book error ? -- 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.