This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-04
Channels
- # announcements (1)
- # architecture (16)
- # asami (30)
- # babashka (1)
- # beginners (17)
- # calva (4)
- # clj-kondo (4)
- # clojure (32)
- # clojure-austin (2)
- # clojure-dev (16)
- # clojure-europe (33)
- # clojure-mexico (1)
- # clojurescript (40)
- # data-science (9)
- # emacs (33)
- # fulcro (1)
- # jackdaw (4)
- # malli (25)
- # off-topic (34)
- # pathom (23)
- # react (16)
- # reagent (8)
- # releases (5)
- # vim (46)
Is there anything I need to do when I comment to replies on Ask to make sure the original commenter sees them?
if you reply to an answer or comment, those in the thread should get an email (unless they turned that off)
APersistentVector$Seq
implements IReduce
; APersistent$RSeq
does not. Is there a reason for this?
(While I'm nit-picking, ...`RSeq extends ASeq implements IndexedSeq, Counted` , the Counted
being redundant.)
(I doubt either of these has affected anyone's enjoyment of life, other than myself. I went ahead an implemented IReduce
in ClojureCLR for RSeq
and have been living with my own FUD ever since.)
> Is there a reason for this? no, probably not
While on the topic of reduce
, in ArrayChunk
we have
public Object reduce(IFn f, Object start) {
Object ret = f.invoke(start, array[off]);
if(RT.isReduced(ret))
return ret;
for(int x = off + 1; x < end; x++)
{
ret = f.invoke(ret, array[x]);
if(RT.isReduced(ret))
return ret;
}
return ret;
}
This is the only place I can find in the source where RT.isReduced
is called and if true, the Reduced
object is not deref()
'd. (Ignoring TransformerIterator
, where passing the Reduced
instance out seems reasonble.) Is there something special about the places were reduce
might be called on an ArrayChunk
?In short, yes - this is a different reduce method (part of IChunk), than every other reduce (IReduce, CollReduce)
That's what I was missing. Even with that hint, it took me a bit to piece it together. (The CollReduce bone connects to the InternalReduce bone connects to the IChunkedSeq bone. I think. ) Thx.
I have made the mistake of implementing both interfaces in the same object which caused some very subtle errors that took a long time to figure out
(wrt reduced)
So, before I commit myself to an error, is the following correct for reduce in IReduceInit and IReduce (but not IChunkedSeq.reduce):
One essential rule when writing a reduce
method: after each invocation of the reduction function, check the result to see if it is an instance of Reduced
; if so, stop immediately and return the deref
value.
Thanks. Planning on that note for my next blog post. Not much information out there about clojure.lang.Reduced
The Transducers article seems to be about it. I may have missed others.
there is all the trickiness in expanding transducers that may do a sub-reduce that need to re-wrap reduced, but that doesn't change the rule above