Re: Get anonymous function's(which is parameter to function) body in called function
I wonder why this can't become a language feature? Couldn't Clojure attach the :source metadata directly to function objects (in addition to vars)? Is there a JIRA ticket for it? I'd instant-vote for it because I know it would make my debugging faster. On Thursday, May 28, 2015 at 1:03:52 PM UTC+2, Shalaka Patil wrote: > > I have one function wait-until whose definition is like- > (defn wait-until >[pred] >(wait-until* pred)) > where, pred is a function & wai-until* is some internal working. > > Now, I want to modify it like- > (defn wait-until >[pred] >(try > (wait-until* pred) > (catch Exception e > (println "Exception happened for fn " pred > > Now, for ex, input is (wait-until #(exists? ".foo")) and if wait-until* > throws exception > it will print something like- # clj_webdriver.taxi$eval40409$fn__40410@7b7b202f>(compiled name for that > anonymous function) > instead of that, I want actual function body which is #(exists? ".foo"). > > But, I didn't get way where I can get source of anonymous function. > > Instead of that I found two ways for better user message: > 1. Add meta to anonymous fn and print that meta in error message, so user > will get exact idea of where wait-until has failed. >(defn wait-until >[pred] >(try > (wait-until* pred) > (catch Exception e >(when (meta pred) > (println "Exception happened for fn with meta: " (meta pred)) > > and input will be like- (wait-until ^{:checks "existence of foo"} > #(exists? ".foo")) > and if it throws exception, > output will be like- Exception happened for fn with meta: {:checks > "existence of foo"} > > 2. Pass pred fun in quoted form, so that wait-until fn can execute + get > its body as it is. >(defn wait-until >[pred] >(try > (wait-until* (exec pred)) > (catch Exception e > (println "Exception happened for fn " pred > > So, which way is better to go with. Or is there any other way to do? > -- 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: Get anonymous function's(which is parameter to function) body in called function
Okay. Thanks BG :) On Saturday, May 30, 2015 at 5:13:00 AM UTC+5:30, Baishampayan Ghose wrote: > > May be wrap it up in a `wait-until-with-meta` macro as Herwig suggested? > Then you can search and replace the invocations. ~BG > > On Fri, May 29, 2015 at 9:30 PM, Shalaka Patil > wrote: > >> Hey BG, >>Yes, having metadata is really a straight forward way but this is kind >> of extra work in every wait-until call which I was trying to avoid. Going >> with metadata option will not just cause extra work for wait-until in >> future code but even I need to add it at all the places in wherever it is >> used. But yes, if having `eval` is really bad way or there is no other way >> to handle it then will go with `metadata` approach :) >> >> On Friday, May 29, 2015 at 8:53:11 PM UTC+5:30, Baishampayan Ghose wrote: >>> >>> Shalaka, >>> >>> This is a really interesting conversation :-) However, I'd insist that >>> you ditch eval or any sort of complicated affair and adopt the metadata >>> approach as I had suggested that day :-P >>> >>> ~BG >>> >>> On Fri, May 29, 2015 at 4:20 PM, Shalaka Patil >>> wrote: >>> Hey, Thanks Herwig & Mohit. So, I have one more solution. Here is the original wait-until function- (defn wait-until ([pred] (wait/wait-until *driver* (fn [_] pred))) ([pred timeout] ( wait/wait-until *driver* (fn [_] pred) timeout)) ([pred timeout interval] (wait/wait-until *driver* (fn [_] pred) timeout interval)) ([driver pred timeout interval] (wait/wait-until driver (fn [d] (pred d )) timeout interval))) I have converted function to macro like - (defmacro with-wait-until-error-log [pred & body] `(try ~@body (catch Exception e# (println "\nWait-until failed for: " ~pred "\n") e#))) (defmacro wait-until [& args] `(if (= (count '~args) 4) (let [pred# (nth '~args 1)] (with-wait-until-error-log pred# (wait/wait-until (eval (nth '~args 0)) (fn [_#] (eval pred#)) (nth '~args 2) (nth '~args 3 (let [pred# (first '~args)] (with-wait-until-error-log pred# (wait/wait-until *driver* (fn [_#] (eval pred#)) (nth '~args 1) (nth '~args 2)) So, by this way I am not breaking input format or fn behaviour, but need to use `eval`. So, is there any other way for doing same as eval? Or, is it OK to use eval? On Friday, May 29, 2015 at 12:55:20 PM UTC+5:30, Mohit Thatte wrote: > > I see what you mean, this is nice > > On Thu, May 28, 2015 at 11:25 PM, Herwig Hochleitner < > hhochl...@gmail.com> wrote: > >> 2015-05-28 19:42 GMT+02:00 Mohit Thatte : >>> >>> The interesting question here is what constitutes useful information! >>> >> >> (let [pred #(exists? ".foo")] >> (wait-until pred)) ;; <- the fact that it's called 'pred is not >> interesting in most cases >> >> >>> The trade-off is breaking an existing public API. >>> >> >> How so? >> >> (defmacro op [msg args expr] >> `(with-meta (fn ~args ~expr) {:msg ~msg :args '~args :expr '~expr})) >> >> (let [pred1 #(exists? ".foo") >> pred2 (op "checks existance" [] (exists? ".foo"))] >> ;; both these will work, the one with pred1 will give less useful >> errors. the API of wait-until is unchanged >> (wait-until pred1) >> (wait-until pred2)) >> >> If Shalaka's primary goal is prettier errors in test failures, I'd >>> settle for the fn body itself as the error message and that could be >>> achieved without breaking the API. >>> >> >> The op macro can include the code in its information. >> >> -- >> 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. >> > > > > -- > -Mohit Thatte > -- You received this message because you are subscribed to the Google Groups "Clojure" g
complex number library
Criterium should probably be just a Dev dependency. -- 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.
[ANN] thi.ng additions/updates
Hi Clojurians, had a bit of a release train this weekend w/ some new (and old, overdue) additions to the thi.ng library collection (all including examples): http://thi.ng/simplecl - OpenCL wrapper http://thi.ng/structgen - Interop between C structs & Clojure data structures (maps/vectors) http://thi.ng/raymarchcl - OpenCL voxel rendering/raymarching from the REPL http://thi.ng/typedarrays - CLJS wrapper for JS typed arrays http://thi.ng/ndarray - CLJ/CLJS port of JS ndarray lib (w/ few additional features) http://thi.ng/strf - Functional string formatters & number parsers for CLJ/CLJS http://thi.ng/color - Cross-platform CLJ/CLJS library for color conversion & manipulation http://thi.ng/geom has also been updated recently - see changelog here: https://github.com/thi-ng/geom/blob/master/CHANGELOG.org Btw. All of the above libs now depend on Clojure 1.7-* and where applicable make use of the new conditional reader forms... Weitermachen! :) K. -- 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.
complex number library
https://clojars.org/complex https://github.com/alanforr/complex Complex is a Clojure library for doing complex number calculations that wraps the Java commons-math3 Complex library. complex A Clojure library for doing calculations with complex numbers. Wraps the Java commons-math3 Complex library. Usage A complex number can be created by invoking the complex number function. With one argument the function produces a complex number in which only the real component is non-zero. With two arguments, the first argument is the real part, the second argument is the imaginary part: => (complex-number 1) Complex (1.0, 0.0) => (complex-number 1 2) Complex (1.0, 2.0). The library can be used to do complex arithmetic. The + function can have any number of real or complex arguments but always produces a complex result. => (+ 1 (complex-number 3 4)) Complex (4.0, 4.0). The same is true of the other arithmetical operations *,-,/. The arithmetical functions are fastest on a per number basis when used on only two arguments. They are also faster when their arguments are complex. The library also provides other functions, such as (pow a b), which raises a to the power b, (sin a) which calculates the sine of a, and several other functions. For details, see the docs. Alan -- 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: what does "release-pending-sends" do?
What it means is if you have nested actions, e.g. (def a (agent 0)) (def b (agent 0)) (send a (fn [x] (send b inc) (inc x))) So under normal circumstances, the inner send is placed on a queue until the value of a is changed. This means we can guarantee that a will change before b. If we want to override this behaviour, you can use release-pending-sends (send a (fn [x] (send b inc) (release-pending-sends) (inc x))) The above code will send to b *before* the send to a completes (unless I've completely misunderstood!) - James On 31 May 2015 at 20:29, wrote: > I am looking here: > > http://clojuredocs.org/clojure.core/release-pending-sends > > It says: > > Normally, actions sent directly or indirectly during another action > are held until the action completes (changes the agent's > state). This function can be used to dispatch any pending sent > actions immediately. This has no impact on actions sent during a > transaction, which are still held until commit. If no action is > occurring, does nothing. Returns the number of actions dispatched. > > > I can not figure out what this means. This function takes no arguments? I > see it defined like this: > > (release-pending-sends) > > So I can not call it on a specific agent, instead, this function is global > in its effects? It effects every agent in my app? Or perhaps I am suppose > to call it from inside the agent, and it only dismisses the functions that > have piled up on that agents queue? > > If I do this: > > (def users (agent {})) > (def contests (agent {})) > (send users calculate-winnings-per-category) > (send users calculate-winnings-total) > (send users remove-the-losers) > (send contests generate-new-contests) > (send contests assign-prize-money) > > (release-pending-sends) > > What happens? The agent starts on whatever function happens to be put into > its queue first, and it continues with the execution of that function, but > all the other sends are cancelled? > > Also, is there a way to see how many functions are pending for an agent? > > > > > > > > > > > -- > 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.
what does "release-pending-sends" do?
I am looking here: http://clojuredocs.org/clojure.core/release-pending-sends It says: Normally, actions sent directly or indirectly during another action are held until the action completes (changes the agent's state). This function can be used to dispatch any pending sent actions immediately. This has no impact on actions sent during a transaction, which are still held until commit. If no action is occurring, does nothing. Returns the number of actions dispatched. I can not figure out what this means. This function takes no arguments? I see it defined like this: (release-pending-sends) So I can not call it on a specific agent, instead, this function is global in its effects? It effects every agent in my app? Or perhaps I am suppose to call it from inside the agent, and it only dismisses the functions that have piled up on that agents queue? If I do this: (def users (agent {})) (def contests (agent {})) (send users calculate-winnings-per-category) (send users calculate-winnings-total) (send users remove-the-losers) (send contests generate-new-contests) (send contests assign-prize-money) (release-pending-sends) What happens? The agent starts on whatever function happens to be put into its queue first, and it continues with the execution of that function, but all the other sends are cancelled? Also, is there a way to see how many functions are pending for an agent? -- 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.
When use Pedestal, Hoplon, Bidi and Route-one?
Hi, I am trying figure out which one (Pedestal, Hoplon, Bidi) should i use? I didn't find any good article in the Internet which help me with this choice. >From https://github.com/juxt/bidi i can read Pedestal is isomorphic, but Bidi is also cljs. What is it mean? What is the difference? I found compojure is to simply. I can't even generate URLs in HTML templates. I started looking something else. I found also route-one (library to generate URLs working with compojure), but i guess soon i will discover i need something more then compojure have again. My intuition say me to choose between: Pedestal, Hoplon and Bidi. What i need: I want have independent business model architecture like http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html http://blog.find-method.de/index.php?/archives/209-Dependency-inversion-in-Clojure.html I don't want depend this part of code with any framework. Less dependency is better. On next stage i want inject this model business into something like bridge, which will be the connector with user interface. It can be time for framework or additional libraries. And at least i want create frontend user interface as website. It will be dynamic content with ClojureScript or mayby static. I don't know. I have to thing about both. What i found out in Clojure i really like conception on building my own set of libraries based on my preferences. But i don't want write my own code to use things like generate URLs for routes. So mayby i should also consider route-one? Please write something clever what help me choose one or complicate my live with some other option to choose :) https://github.com/juxt/bidi https://github.com/pedestal/pedestal https://github.com/tailrecursion/hoplon https://github.com/clojurewerkz/route-one -- 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.