Group Abstract Group Abstract

Message Boards Message Boards

6
|
10.9K Views
|
5 Replies
|
14 Total Likes
View groups...
Share
Share this post:

New function suggestion: Dont

POSTED BY: Todd Rowland
5 Replies
Posted 10 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:

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

POSTED BY: Kuba Podkalicki

But what should it return then for those cases?

Didnt[DivideByZero] ?
POSTED BY: Sander Huisman

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

POSTED BY: Karan Shah

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}
POSTED BY: Todd Rowland

+1 for the Yoda reference.

POSTED BY: John Burnette
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard