After install V13.1 one of my scripts get broke in my Mac. Below is the core of the bug:
Module[{}, Return[1]; 2]
Return1
In the Wolfram Cloud we get the expected result.
After install V13.1 one of my scripts get broke in my Mac. Below is the core of the bug:
Module[{}, Return[1]; 2]
Return1
In the Wolfram Cloud we get the expected result.
Interesting! It works at Wolfram Cloud
Hey guys,
*2 things:
..regarding the inconsistency between Cloud and Mathematica, I believe a ticket has already been made..
Thanks!
Claudio Chaib
The unexpected behavior exhibited by the cloud can be explained with something like
Attributes[myevaluateFunction] = {HoldAllComplete};
myevaluateFunction[input___] := WithCleanup[setup\[\], input, teardown\[\]\];
CloudEvaluate could very well be using something similar to the code above. Now if you put the module in this evaluation wrapper you get what you initially expected:
In[32]:= myevaluateFunction[Module[{}, Return[1]; 2]]
Out[32]= 1
I imagine this is the same thing happening with CloudEvaluate[Module[{}, Return[1]; 2]] or just running the Module in a cloud notebook: there is some wrapper function that takes your code and passes it to the kernel and then returns the results to you. This extra layer is why the Return[1] works.
So if you ever find yourself wanting to write code like
Module[{}, Return[1]; 2]
stop and write
Catch[Module[{}, Throw[1]; 2]
instead.