Why iteration specification in `for` can't use the function with <transacts> effetct ?

The below code in the Verse Document can’t compile.

for(X := 1..5; S := IncrementSomeVariable(); X < 3):
    X

Because IncrementSomeVariable() is not failer expression.
Even if IncrementSomeVariable() has < transacts >, the code can’t compile too.

Is this a misnomer of documents?
But why?
Why iteration specification in for can’t use the function with < transacts > effect ?

1 Like

The for filter is like an if block, it calls inside a failure context.
If the function does not <transacts> then you can’t call it inside a failure context, it will tell you that :

This invocation calls a function that has the 'no_rollback' effect, which is not allowed by its context.(3512)

You have to workaround it, as the roadmap says, the no_rollback effect is meant to be removed
image

Using a <transacts> specifier should work, it does on my compiler though :

IncrementSomeVariable()<transacts>:int= # Please don't return void because you're using the returned value to assign the variable S
    return 1

for(X := 1..5; S := IncrementSomeVariable(); X < 3):
    X
2 Likes

Thanks a lot !
Sorry, I misunderstood.

Yore code can compile.
0919_2

This my wrong code couldn’t compile.

I wonder why my code can’t compile.
But my first question was solved for you.
thank you.

1 Like

These are not the same code block, mine is

for(X := 1..5; S := IncrementSomeVariable(); X < 3):

Yours is

for(X := 1..5; IncrementSomeVariable(); X < 3):

The for filter is supposed to have failable methods in it, so you’ll need to add the <decides> specifier to it. As shown in the doc :

I think my method works because the compiler allows for variable assignment as an exception so that you can have multiple statements next to each other inside if blocks / for filters.

But you might be right, if the assignment works then a void call should work too. I guess they’ll fix this with the no_rollback update :person_shrugging:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.