# New function suggestion: Dont

Posted 5 years ago
4982 Views
|
5 Replies
|
14 Total Likes
|
 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.  Answer
5 Replies
Sort By:
Posted 5 years ago
 Is this why Wolfram Language has no Try clause? Because Do || Don't, !?Try ? Answer
Posted 5 years ago
 +1 for the Yoda reference. Answer
Posted 5 years ago
 But what should it return then for those cases? Didnt[DivideByZero] ? Answer
Posted 5 years ago
 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} Answer
Posted 5 years ago
 Here is an example, creating function from it won't be easy if it is meant to be general, but is certainly possible: InternalInheritedBlock[{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}} Answer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments