Can we at least get an example of situation where the zero-arity version would be called?
Right now it seems that all the transducer literature out there says there must be three arities – and that’s how map etc are defined – but it doesn’t seem, based on various people’s simple tests, that the zero-arity version is ever called… so why would we define it? Sean Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ "If you're not annoying somebody, you're not really alive." -- Margaret Atwood From: Clojure Mailing List <clojure@googlegroups.com> on behalf of Stephen Nelson <step...@montoux.com> Reply-To: Clojure Mailing List <clojure@googlegroups.com> Date: Wednesday, March 9, 2016 at 12:23 PM To: Clojure Mailing List <clojure@googlegroups.com> Subject: Re: Understanding init (the zero arity function) for transducers. This was discussed further in http://dev.clojure.org/jira/browse/CLJ-1569 On Wed, Mar 9, 2016 at 3:43 PM Patrick Curran <patricktheb...@gmail.com> wrote: Thanks Alex, If you ever do get a chance, I'd be curious to know what it was. The more I think about it the more I think Dan is correct. Also "scan" seems like a natural thing that one should be able to do without having to jump through hoops. On Monday, February 29, 2016 at 5:10:53 PM UTC-5, Alex Miller wrote: I think that Rich had an objection to this, however in the haziness of time I don't recall specifically what it was. If I get a chance, I will ask him this week. On Monday, February 29, 2016 at 3:27:15 PM UTC-6, Patrick Curran wrote: Hi, I was trying to write a transducer and the 0-arity part of it never got called, which was unexpected. I did some searching and found this post: https://groups.google.com/forum/#!msg/clojure/uVKP4_0KMwQ/-oUJahvUarIJ. What Dan is proposing in that post would essentially solve my problem, but it doesn't look like his proposal has gotten much traction... Specifically I was trying to implement scan. (defn scan ([f] (scan f (f))) ([f init] (fn [xf] (let [state (volatile! init)] (fn ([] (xf (xf) init)) ([result] (xf result)) ([result input] (let [next-state (f @state input)] (vreset! state next-state) (xf result next-state)))))))) Which results in the following: (require '[clojure.core.reducers :as r]) (r/reduce ((scan + 3) conj) [1 2 3]) => [3 4 6 9] (transduce (scan + 3) conj [1 2 3]) => [4 6 9] (transduce (scan + 3) conj (((scan + 3) conj)) [1 2 3]) => [3 4 6 9] My expectation would be that we'd always get the 3 at the front of the vector. I'm actually using core.async and I'm expecting that the initial value be available to be taken from the channel. (require '[clojure.core.async :as a :include-macros true]) (def c (a/chan 1 (scan + 3))) (a/go (println (a/<! c))) ; expecting 3 to immediately be printed. (a/>!! c 1) => 4 So this is more of a conceptual thing rather than just how transduce is implemented. I'd love to hear other people's thoughts on this. I'm quite new, but Dan's proposal definitely feels "correct" and the current implementation definitely feels "wrong". --Patrick -- 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.