Message Boards Message Boards

7
|
8854 Views
|
6 Replies
|
26 Total Likes
View groups...
Share
Share this post:

Different Cloud vs. Desktop Return behavior in V13.1

Posted 2 years ago

After install V13.1 one of my scripts get broke in my Mac. Below is the core of the bug:

Module[{}, Return[1]; 2]

Return[1]

In the Wolfram Cloud we get the expected result.

Cross post in Stack Exchange

POSTED BY: Rodrigo Murta
6 Replies

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.

POSTED BY: Jason Biggs
Posted 2 years ago

With versions 5.2, 8.0.4 and 12.3.1 on Windows 10 x64 I get the same result:

screenshot screenshot

POSTED BY: Alexey Popkov

I can confirm that this bug also occurs on 13.0.0 for Linux (64-bit), see this attached screenshot:

bug

POSTED BY: Pedro Cabral

Interesting! It works at Wolfram Cloud

POSTED BY: Daniel Carvalho
Posted 2 years ago

Here is a duplicate question on MMa.SE with a detailed answer from Leonid Shifrin:

Read also this (the last section "Why did Return appear?") and this.

POSTED BY: Alexey Popkov

ex1

Hey guys,

*2 things:

  • 1) not everything is a BUG, I myself fell into a lot of traps in Return problems when I create functions in WL, due to lack of training thro documentation (my fault), but (I believe that) nothing about this command has changed in recent years.. I recommend testing through the Documentation!

  • 2) Wolfram's QA (quality assurance) is the best of the best developers, they are amazing! ..for me, Return is working correctly in 13.1, I don't know if something has changed internally, because I didn't identify it..

..regarding the inconsistency between Cloud and Mathematica, I believe a ticket has already been made..

Thanks!

Claudio Chaib

POSTED BY: Claudio Chaib
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract