A Failure To Understand lazy-seq
I'm trying to understand infinite sequences. Wikipedia defines an implementation of the Fibonacci sequence as: (def fibs (cons 0 (cons 1 (lazy-seq (map +' fibs (rest fibs)) However, when I wrote fibs in the repl as: (def fibs (lazy-seq (cons 0 (cons 1 (map +' fibs (rest fibs)) executing (first fibs) produces a StackOverflow exception. What is the reason that the second, incorrect definition throws a StackOverflow exception, but the first generates an infinite sequence? Thanks. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Cosla: Clojure tool for SLA metrics via JIRA Rest API
Greetings, I've open sourced a command-line tool I wrote, in Clojure, for pulling SLA (service-level agreement) stats from JIRA using the JIRA Rest API. https://github.com/noahlz/cosla Given a JIRA instance, it can generate some CSV files reporting on the issues matching a JQL you provide, such as issues open-per-day and per-issue time-to-close. Hopefully useful to somebody as-is, or an interesting project to hack on / extend that could have practical business use. Issues / pull-requests welcome! @noahlz -- 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: transducers and eduction
On Monday, September 4, 2017 at 3:54:14 PM UTC-5, Peter Hull wrote: > > I am trying to understand transducers and am reading through > https://clojure.org/reference/transducers I think I am missing something, > please can someone help? > > I read the part about the 'shape' of a transducer-creating-function ( > https://clojure.org/reference/transducers#_creating_transducers) and made > this function > > (defn no-op [rf] > (fn ([] (rf)) > ([x] (rf x)) > ([x r] (rf x r > > which I call with > > (pprint (eduction no-op (range 5))) > > and get > > (0 1 2 3 4) > > This is OK. If I now define > > (defn nearly-no-op [rf] > (fn ([] (rf)) > ([x] (let [tmp (rf x)] (* x 2))) > ([x r] (rf x r > > (I want the 'finishing' function to double the answer) > When you say "the" answer here, that doesn't make sense to me. An eduction is like a 1-time (or maybe each-time would be more accurate) non-caching sequence. Here the values (0, 1, 2, 3 , 4) are passed to the reducing function in the [x r] arity when you invoke (rf x r) in nearly-no-op. The output of an eduction is a special kind of reducible, seqable collection. If you want to double "each" value you you could do that as so: (defn nearly-no-op [rf] (fn ([] (rf)) ([x] (rf x)) ([x r] (rf x (* 2 r) (eduction nearly-no-op (range 5)) ;;=> (0 2 4 6 8) If you want to like sum and then double, you want to use a transducing context that accumulates to a result value with a finalization function, you could use transduce: (defn nearly-no-op [rf] (fn ([] (rf)) ([x] (rf (* 2 x))) ([x r] (rf x r (transduce nearly-no-op + 0 (range 5)) 20 > > Then (pprint (eduction nearly-no-op (range 5))) gives me a null pointer > exception in multiply. Where does this come from? > The termination value in an eduction is just a nil, so x is nil in the ([x] ...) arity. > > If I try > > (defn nearly-no-op [rf] > (fn ([] (rf)) > ([x] (count (rf x))) > ([x r] (rf x r > > then I get (0 1 2 3 4) again, i.e. the count doesn't play any part in the > final result. > > Thanks in advance! > > Complete program: > (ns ttry.core > (:require [clojure.pprint :refer [pprint]]) > (:gen-class)) > > (defn no-op [rf] > (fn ([] (rf)) > ([x] (rf x)) > ([x r] (rf x r > > (defn nearly-no-op [rf] > (fn ([] (rf)) > ([x] (let [tmp (rf x)] (* x 2))) > ([x r] (rf x r > > (defn -main > [& args] > (pprint (eduction (map identity) (range 5))) > (pprint (eduction no-op (range 5))) > (pprint (eduction nearly-no-op (range 5 > > > > > > > -- 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.
transducers and eduction
I am trying to understand transducers and am reading through https://clojure.org/reference/transducers I think I am missing something, please can someone help? I read the part about the 'shape' of a transducer-creating-function ( https://clojure.org/reference/transducers#_creating_transducers) and made this function (defn no-op [rf] (fn ([] (rf)) ([x] (rf x)) ([x r] (rf x r which I call with (pprint (eduction no-op (range 5))) and get (0 1 2 3 4) This is OK. If I now define (defn nearly-no-op [rf] (fn ([] (rf)) ([x] (let [tmp (rf x)] (* x 2))) ([x r] (rf x r (I want the 'finishing' function to double the answer) Then (pprint (eduction nearly-no-op (range 5))) gives me a null pointer exception in multiply. Where does this come from? If I try (defn nearly-no-op [rf] (fn ([] (rf)) ([x] (count (rf x))) ([x r] (rf x r then I get (0 1 2 3 4) again, i.e. the count doesn't play any part in the final result. Thanks in advance! Complete program: (ns ttry.core (:require [clojure.pprint :refer [pprint]]) (:gen-class)) (defn no-op [rf] (fn ([] (rf)) ([x] (rf x)) ([x r] (rf x r (defn nearly-no-op [rf] (fn ([] (rf)) ([x] (let [tmp (rf x)] (* x 2))) ([x r] (rf x r (defn -main [& args] (pprint (eduction (map identity) (range 5))) (pprint (eduction no-op (range 5))) (pprint (eduction nearly-no-op (range 5 -- 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.
Question regarding core.logic
When I run (run* [q] (fresh [x] (== [x] ['z]) (== q x))), I get (z), which makes sense. When I run (run* [q] (fresh [x] (== q x))), I get (_0), which makes sense since I've placed no restriction on x. However, when I run (run* [q] (fresh [x] (== ['x] ['z]) (== q x))), I get (), which doesn't make sense to me. Obviously (== ['x] ['z]) is placing some sort of impossible constraint on x, but I can't tell what that constraint is actually doing. Ultimately, what I want to be able to do is something along the lines of: (def my-var '[x]) (run* [q] (fresh [x] (== my-var ['z]) (== q x))) and get back (z) instead of (). Note that the following produces (z) as desired: (def my-other-var '[z]) (run* [q] (fresh [x] (== [x] my-other-var) (== q x))) So it is only the passing in of the fresh variable that isn't working the way I would expect it to. Any idea on what I can do to make this work? -- 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.