Linked Questions

1 vote
1 answer

How to print a warning/error message from my own module? [duplicate]

I would like to print a warning/error message from my own module. Of course I could use Print["WARNING: my warning"] but in all the output this would be barely ...
highsciguy's user avatar
  • 1,700
2 votes
1 answer

Why evaluation doesn't fail if arguments are invalid? [duplicate]

Sorry for a noob question, but this is something that I wonder about each time I work with Mathematica. Coming from standard programming languages (Python and Java), I expect my functions to fail ...
Andrei Kucharavy's user avatar
602 votes
19 answers

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 ...
16 votes
4 answers

How to check the style and number of arguments like the built-in functions?

Given that I have a function sqrt[x] that I must check the style and number of argument x. I can do like this: ...
xyz's user avatar
  • 625
34 votes
1 answer

which is better, using Assert[] or manual checks on arguments and other computations?

I never used Asserts in Mathematica, but trying to see what advantage they have over just argument check and additional definitions of the function to capture unwanted input. For example, which one ...
Nasser's user avatar
  • 145k
8 votes
1 answer

How to use Message with an error string without predefining it first?

I need a very simple error reporting using Message. But I do not want to pre-define each error message separately as shown What are the best practices / most common / idiomatic ways to report errors ...
Nasser's user avatar
  • 145k
8 votes
1 answer

What is an example of of idiomatic "typed" WolframScript?

I'd like to make my own "typed function" in WolframScript. Suppose the type we desire is called money, and we'd like to make a function called ...
George's user avatar
  • 3,145
6 votes
2 answers

Assert no unevaluated function applications

Background Suppose I have begun a fresh kernel session, and I have defined the following function alone: F[x_, y_] := x + y; One expected use of ...
justinpc's user avatar
  • 163
3 votes
1 answer

How to force error on pattern match failure?

For example, suppose that foo is defined like this. foo[x_Integer, y_Integer] := x + y; Then, any expression with head ...
kjo's user avatar
  • 11.7k
2 votes
0 answers

How to handle exceptions and failures in Mathematica?

In python I can write fallback values like: ...
user305883's user avatar
2 votes
1 answer

How to enable automatic "grammar check" for MMA? [duplicate]

The special evaluation mechanism of MMA might make it more likely for MMA users (especially new users) to make mistakes and more difficult to find them. For example, one may have defined a function ...
Y.X's user avatar
  • 321
0 votes
0 answers

Inspecting the evaluation stack on computation abort [duplicate]

It happens often that a computation starts consuming more memory or time when it encounters an expression with elements in the input that are in some unexpected form. Is there some way to abort ...
lurscher's user avatar
  • 743