New function suggestion: Dont

In the spirit of using WL to talk to AI, this function should be useful, It is like
Do
except it tells the program what not to do.

A simple example might be

Dont[Outer[Divide, Range[-5,5], Range[-5,5]],  DivideByZero]

There are versions already in the language, like when you solve a differential equation you can stop it under some conditions, and of course there is Break.

One might think this is silly but because of computational irreducibility it is impossible to always predict when something bad will happen.

7 Likes

Is this why Wolfram Language has no Try clause?
Because Do || Don’t, !?Try ?

2 Likes

+1 for the Yoda reference.

1 Like

But what should it return then for those cases?

Didnt[DivideByZero] ?
2 Likes

Good question Sander. It could be Inactive code taking the place whenever the execution tries code which matches the Don’t pattern.

There could be an expression evaluated, like Check which returns something when a message is generated, but evaluate it in place inside the expression. Another analogy is with the optional second argument to Dynamic. which evaluates when a variable changes its value.

In order to give a concrete answer,

Dont[Table[2/i, {i,-2,2}], DivideByZero]

might return

{-1 -1/2,  Inactive[Divide][2,0], 1/2, 1}
1 Like

Here is an example, creating function from it won’t be easy if it is meant to be general, but is certainly possible:

Internal`InheritedBlock[{Divide},
   Unprotect@Divide;
   Divide[x_, 0] := Inactive[Divide][x, 0];
   Outer[Divide, Range[-1, 1], Range[-1, 1]]
 ]

{{1, Inactive[Divide][-1, 0], -1}, {0, Inactive[Divide][0, 0], 0}, {-1, Inactive[Divide][1, 0], 1}}

2 Likes