it sounds great, thanks
Jay
On Tuesday, April 25, 2017 at 6:33:49 AM UTC+7, Dragan Djuric wrote:
>
> I'll write more in an introductory blog post in a day or two. Until that,
> there is a website http://clojurecuda.uncomplicate.org, that has the
> details and documentation.
>
> It is similar to
Call for Tutorials
Commercial Users of Functional Programming (CUFP) 2017
September 7th-9th, 2017, Oxford, United Kingdom
Co-located with International Conference on Functional Programming
(ICFP)
Dear
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
[]
Hi John,
reduced really just wraps a value in a special container; nothing magical.
All it does is signal to reduce to stop. reduce knows to stop by checking
with reduced?. reduced? is otherwise extremely narrow-use: it's basically
only useful if you're trying to write something like reduce but d
To add to Ivh's answer, the source code isn't too hard to follow here. Cursive
makes this really easy because you can follow the source right into
clojure.lang.RT, but you don't need to go that far to see how `reduced?` is
used.
You can see that all implementations of `reduce` in clojure.core.
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
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?`!