Thanks, all! Luke, in `(source reduce)`, that code makes use of clojure.core.protocols/coll-reduce, which I see is in src/clj/clojure/core/protocols.clj. And although I haven't yet made sense of all that, I see that `coll-reduce` calls `seq-reduce`/`iter-reduce`, which in turn call `reduced?`!
Regarding `(source reduced)`, that points me toward clojure.lang.Reduced. And `(source reduced?)` points me toward clojure.lang.RT/isReduced. I found the corresponding source code in src/jvm/clojure/Reduced.java src/jvm/clojure/RT.java -- John On Tuesday, April 25, 2017 at 5:11:59 PM UTC-4, Alex Miller wrote: > > The source for both functions is pretty simple (use the source!), although > admittedly `reduced?` does some work to optimize perf that obscures it a > little. > > `reduced` is used by a reducing function to indicate to the outer reducing > process that a return value should end the reduce. It does this by simply > wrapping the return value in a Reduced object. > > `reduced?` is used by the outer process to detect that wrapper (it just > checks if it is a Reduced) > > > On Tuesday, April 25, 2017 at 2:34:05 PM UTC-5, John Gabriele wrote: >> >> Just recently stumbled upon `reduced` and `reduced?`. It seems rather >> magical... how does the outer `reduce` (or `reductions`) know to stop? That >> is, how does the function which is being called (`reduced`) affect the >> function that's calling it (below, `reductions`)? : >> > >> ~~~clojure >> (defn main >> [] >> (let [res (reductions (fn [accum x] >> (if (< accum 100) >> (+ accum x) >> (reduced [x accum]))) >> (range))] >> (prn res) >> (prn (reduced? res)) ;=> false >> (prn (reduced? (last res))))) ;=> false --- why isn't this `true`? >> ~~~ >> >> Also, what's the use of `reduced?`, and on what in the above snippet >> would I call it to return true? >> > > -- 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.