Linked Questions

2
votes
0answers
40 views

Unexpected behavior from Return called in a Block [duplicate]

I like to write functions that dispose of failure cases early, before they do the main calculation, but I don't like to write cascading If statements. Here is a toy ...
526
votes
19answers
130k views

Where can I find examples of good Mathematica programming practice?

I consider myself a pretty good Mathematica programmer, but I'm always looking out for ways to either improve my way of doing things in Mathematica, or to see if there's something nifty that I haven't ...
39
votes
1answer
1k views

What can I use as the second argument to Return in my own functions?

Having found out about the second argument to Return I played a bit with it, and the following tests all resulted in ...
21
votes
3answers
2k views

When must I use the Return function?

In a comment to my answer to this question, QuantumDot asks, "Where can I find more information on when I must use the 'Return' function?". I found this too deep a question to be answered by leaving a ...
10
votes
3answers
445 views

How to exit from the innermost enclosing pure function?

Here is what I tried to do: Scan[Function[x, Scan[Function[y, If[y == 2, Return[]]; (* Do something useful *) Print[y]], x]], {{1, 2, 3}, {4, 5, 6}}] ...
16
votes
2answers
814 views

Generating Gelfand-Tsetlin patterns

I am doing some research on some combinatorial object called GT-patterns. They are generated from three parts of data. Two integer, partitions (sequences of weakly decreasing numbers), $\lambda = \...
3
votes
2answers
395 views

How to force Return[] to return from an arbitrary point (like in C++)?

I need to test some complicated conditions to calculate a Return value. But MMa doesn't let you Return[] from anywhere the way C++ does. The structure of my Module is similar to this: ...
8
votes
1answer
106 views

Understanding the behavior of Return inside Function?

Why doesn't Return actually return a value in a Function? E.g., ...
1
vote
0answers
425 views

Why is Return not forcing an exit from my function? [duplicate]

Here is simplified version of my code that exhibits the behavior troubling me: ...
3
votes
2answers
78 views

Catch parameter order and error using functional form

Question: Why does this fail? In:= (Catch[#] &)[Throw[17]] ...
0
votes
1answer
146 views

Write a function pollard[n, B] that tries to factor an integer n, using Pollard's p − 1 method with at most B iterations [closed]

This is what I got but it seems it's not working. When I test it, it just goes through and nothing gets returned. Is there something I'm missing? ...
1
vote
2answers
55 views

Return is giving me a super-complicated Recursive result in Mathematica 7 [closed]

I'm new to Mathematica, coming from an R and Python background, I need to use Mathematica for my thesis. I have been trying to use Return[] like I'd use return() if I needed to in R. In my practice ...
0
votes
1answer
60 views

Activate[Inactivate] doesn't evaluate the return “sometimes”

I have a behavior that I don't understand. I didn't found a way to have a smaller code to reproduce it, so here is the entire code (you really don't need to understand the functions in details to see ...