Anormally When Using Run with Continuation to do early termination

By following the examples in the Manual of Product of List block, I modified the library function all of predicates block. I ran into a subtle situation that I don't understand:

anormally of running with continuation - c should be 5 not 6

The expected behavior is: d should return false when c at 5, but instead it stopped at 6. I could not figure out the reason.

Here my all of predicates used a helper function which uses call with continuation to stop, I am testing this in order to make use of this feature in certain situations that I needed to do early termination during fold/reduce/scan operations on the list.

Can anyone provide some insight?

Thanks in advance.

Never mind, I figured out the problem, in certain cases, this may not be critical, but if you are relying on certain state to be precisely the moment something tested positive or negative, it's important to pay attention to this subtle detail.

anormally of running with continuation - solution

You can compare this newer version with the version contained inside the previous script pic.

Thank you all.

I am wondering whether that product list with continuation block may also have this subtle problem?

Your MY ALL OF looks fine to me, although in this instruction

you could instead just say

because in the previous instruction you've already established that the first item is true. If it were false, running the continuation would never return here; that's the whole point of continuations!

But the script you actually posted is weird and I don't understand it. I think that you probably mean

but mainly this script is an example of why you should give your variables meaningful names.

Why do you think you need that? I think your original version was fine. I don't see what race condition you think might arise.

Wonderful, thanks @bh for your optimization.

I don't know, without doing that, c value goes to 6 before the code finished running...

I take it back, this optimization does not work unless I put it into the else block, my 1st posted version did not use the else block (same as the example in the product list block in the manual).

This is the final optimized version using the else branch:

anormally of running with continuation - improved solution


No, I think this is similar to one problem I discovered during the generalized sorting problem. a is defined to be ring, and that green circle a is just the identity function, if placing a directly in there, it won't work, for some reasons... Do you know why?

I just checked the example in the manual, it does not work either, even worse, I don't think it ever stopped...
@bh, could you please explain to me why? It maybe a real bug?

product of calling with continuation also fails

Oh. I looked again and found a problem. In your helper function you declare CONT to be of type Any (Unevaluated). Instead it should be of type Reporter.

Brief explanation: Unevaluated input types effectively wrap an invisible ring around whatever expression you give as the actual input. So when ALL OF calls ALL OF HELPER with input untitled script pic (3), the input value is untitled script pic (4) instead of the actual continuation. So calling it doesn't work.

If that's not enough of an explanation, go reread Section VI.E of the Reference Manual and then come back with a specific question if that isn't clear.

So if you fix that, it should all work without that redundant REPORT.

I swear that I had replied, but somehow it had got lost. Thanks, it works perfectly now.

BTW, is there any issue with the cloud? I tried to save my project to the cloud, but it says I am not connected.

Maybe this is related why my post mysteriously disappeared?

We had a cloud problem a few weeks ago, but it's fixed now and no data were lost. If you're still having trouble, log out and log in again.