Fork me on GitHub
#clojure-dev
<
2023-02-04
>
Ben Sless11:02:12

Is there anything I need to do when I comment to replies on Ask to make sure the original commenter sees them?

Alex Miller (Clojure team)18:02:14

if you reply to an answer or comment, those in the thread should get an email (unless they turned that off)

dmiller14:02:40

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.)

😆 2
Alex Miller (Clojure team)18:02:48

> Is there a reason for this? no, probably not

dmiller02:02:14

Good. Now I can sleep more easily.

😄 2
dmiller13:02:47

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?

Alex Miller (Clojure team)14:02:19

In short, yes - this is a different reduce method (part of IChunk), than every other reduce (IReduce, CollReduce)

dmiller14:02:58

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.

Alex Miller (Clojure team)14:02:45

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

dmiller14:02:43

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.

dmiller15:02:08

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.

Alex Miller (Clojure team)15:02:50

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

dmiller15:02:37

Fortunately, all that complication lies out in the Clojure source code, which I can mostly ignore at this stage -- focusing just on the Java/C# parts. Except of course for solving my confusion about ArrayChunk .