Linked Questions

1
vote
1answer
2k views

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 ...
2
votes
1answer
269 views

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 ...
528
votes
19answers
132k 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 ...
13
votes
4answers
972 views

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: ...
33
votes
1answer
911 views

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 ...
8
votes
1answer
178 views

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 ...
7
votes
1answer
116 views

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 ...
3
votes
1answer
208 views

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 ...
2
votes
1answer
75 views

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 ...
0
votes
0answers
55 views

How to handle exceptions and failures in Mathematica?

In python I can write fallback values like: ...
0
votes
0answers
42 views

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 ...