Questions tagged [return-value]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
4 votes
1 answer
145 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 ...
  • 69
0 votes
0 answers
54 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: ...
  • 47
4 votes
0 answers
65 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 ...
  • 163
2 votes
1 answer
257 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
43 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 ...
's user avatar
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} *) ...
  • 1,073
2 votes
2 answers
99 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, ...
  • 4,388
4 votes
1 answer
528 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 ...
  • 279
2 votes
1 answer
217 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,227
2 votes
2 answers
123 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 ...
  • 435
3 votes
2 answers
98 views

Catch parameter order and error using functional form

Question: Why does this fail? In:= (Catch[#] &)[Throw[17]] ...
  • 1,456
1 vote
1 answer
148 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
115 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
431 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,381
4 votes
1 answer
188 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 ...
  • 3,804
1 vote
1 answer
215 views

Throw and Catch or Return inside Compile

Consider this code: ...
  • 3,804
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
225 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 ...
  • 6,933
17 votes
1 answer
6k 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 ...
  • 1,002
6 votes
1 answer
219 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 ...
  • 2,013
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. ...
  • 283
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...
  • 539
59 votes
8 answers
25k 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 ...
  • 701