Questions tagged [return-value]
The return-value tag has no usage guidance.
27
questions
0
votes
0
answers
31
views
How do subkernels return results to the master kernel?
Assume you have a large Table defined in the master kernel. I want to compute its elements in parallel. I am familiar with ParallelTable but, for my particular case,...
2
votes
1
answer
51
views
How to modify the argument of a specific function below?
I would like to change the values of a and b in the following function:
...
2
votes
2
answers
172
views
about Return value of Module[]
questions are in the below code.
Although I'm pretty sure of the answer, I still feel a little uncomfortable, because I feel that the format of the body of Module[] ...
4
votes
1
answer
328
views
How to get a function from a string?
I'm trying to create a function that takes in input a function written as string and the return it applying a ToExpression and an Evaluate (Code below).
The goal of this function is to transform the ...
0
votes
0
answers
55
views
How to use Mathematica to return value from for-loop [duplicate]
I tried to use Mathematica to implement random generator. The pseudo code I use is as following:
...
4
votes
0
answers
69
views
Should I worry about concurrent access to LibraryLinked code?
According to these answers, when several heterogeneous results (say {MTensor, mint, double}) are needed to be returned from a LibraryLink ...
2
votes
1
answer
611
views
How to return two values from function
I have a function that generates cipher text for ElGamal encryption and I want to make return two values, but it returns only one. This is the code:
...
0
votes
1
answer
54
views
How to get While to Return a Custom Value?
The Documentation for While says:
Unless an explicit Return is used, the value returned by While is Null.
But how do I implement it? I'd like to build a function ...
3
votes
3
answers
65
views
Return[] being saved to DownValues
Example:
f[x_] := f[x] = (If[x < 0, Return[x]]; x)
f[1];
f[-5];
DownValues[f][[1 ;; 2]]
(* {HoldPattern[f[-5]] :> Return[-5], HoldPattern[f[1]] :> 1} *)
...
2
votes
2
answers
119
views
Vanishing function and Manipulate
Within Manipulate, I want to vanish certain controls if other controls satisfy a specific condition. The simplest case is to consider two checkboxes, ...
5
votes
1
answer
813
views
Best practice with Return in Module or Block
I am a bit confused on the use of Return in either Block or Module when defining a custom ...
2
votes
1
answer
314
views
Defining a function that has no return value
How can I define a function with no return value. For example, the Notation function from the Notation package seems to have no return value; I am looking to do the same thing for some of my custom ...
2
votes
2
answers
134
views
Compound Statements and returning earlier results in () parentheses
I am trying to debug some script and need to Print[] out some results, sometimes before, and sometimes after, certain executions.
These 3 trials exemplify my ...
3
votes
2
answers
106
views
Catch parameter order and error using functional form
Question: Why does this fail?
In:= (Catch[#] &)[Throw[17]]
...
1
vote
1
answer
165
views
Iterations in Mathematica [closed]
this is probably a very easy question for all of you.
I have a stochastic Mathematica code (not important what it's exactly) which gives me a number at the end. Now I want Mathematica to run this ...
1
vote
2
answers
123
views
Returning value if a point is in a region?
I'm writing a function so that if the user clicks on a certain region, a value is returned. The function takes in a condition list like the one below and a point.
...
5
votes
2
answers
441
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:
...
4
votes
1
answer
196
views
Throw and Catch return wrong result inside Compile
Consider this code:
fun = Compile[{{i, _Integer}},
Catch[Do[
If[j >= i, Throw[j]]
, {j, 1, 10}]]
]
I put an integer as argument then if this ...
1
vote
1
answer
232
views
Throw and Catch or Return inside Compile
Consider this code:
...
1
vote
1
answer
1k
views
How to check empty tables using SQL Select or Execute?
If[SQLExecute[con, "Select * from TABLE"] == "{}", Print["TRUE"], Print["FALSE"]]
I need to know the way, if the TABLE is empty or not
5
votes
2
answers
230
views
Returning ancillary computation results from a function
Suppose I want to implement a function to solve a very basic Elliptic problem using Finite Element of some degree (It's just an example).
Normally the user of my function is only interested to the ...
17
votes
1
answer
7k
views
Returning a value from a Module
In the following simple example
MyMod := Module[{i},
Do[
Return[1],
{i, 3}
];
Print["test"]
]
I expected the module to exit on ...
6
votes
1
answer
221
views
Return struct from function (with DownValues)
In Mathematica there is a way to create struct-like data type:
struct[myField]=value
I want to return myStruct from a function:
...
4
votes
2
answers
5k
views
Function returning Null along with other unexpected expressions
When I use some function, at the end along with the output I get some NULLs returned that I don't understand the reason for and are highly undesirable.
For example, when I define the reversal of list ...
14
votes
4
answers
1k
views
How can I return a Sequence?
Recently I had the need to redefine a certain symbol in my init.m so it would be automatically omitted from any lists it appears in. I decided to redefine it to an empty sequence, e.g. ...
5
votes
4
answers
3k
views
Compile and "True should be a machine-size real number..." Error
I am trying to compile a little summation function.
As far as I understand, because the built-in Sum function can also return NaN...
59
votes
8
answers
26k
views
How to avoid returning a Null if there is no "else" condition in an If construct
I need to use If but with only one option that is if "a" then do "b", else do nothing. So I wrote If[a,b] but the problem is ...