Group Abstract Group Abstract

Message Boards Message Boards

0
|
2K Views
|
1 Reply
|
1 Total Like
View groups...
Share
Share this post:

Ideas to add a Clear highlighted button to toolbar?

Posted 2 years ago

Since all times I fight with a method to clear a wrong definition by

Clear@mydef[x_]:=...

just by prepending the Clear@ in front, highlight the text up to " [" and press Shift+Ctrl+Enter for immediate execution and clearing the definition.

In vs 13, often overwriting a definition does not work so anymore, especially in multiple definitions with conditions. Not to mention the nuisance when setting f=4 first and defining f[x_]:= later on.

How to add this procedure similar to the Shift+Ctrl+Enter entry in keyevent.tr located in SystemFiles\FrontEnd\TextResources\Windows\KeyEventTranslations.tr ?

POSTED BY: Roland Franzius

Not an answer to give what you ask, but an alternative way to "fight" an old definition:

I put my definition(s) for a function func[] in a single cell that begins with ClearAll. If I have resources I want precomputed, I put those in a separate cell and define a way to access them from func[]. Then I don't have to recompute them every time I adjust the API or code for func[].

func // ClearAll;
func // Options = {Method -> Automatic,...}; (* optional: default options *)
func // Attributes = {HoldFirst}; (* optional: attributes *)
func::usage = (* optional: messages *)
 "func[x, n] computes something for nonnegative integers n.";
(* Definitions: *)
func[x_, 0] := 1;
func[x_, 1] := x;
func[x_, n_Integer?Positive] : 2 x func[x, n - 1] - func[x, n - 2];

There is no need for HoldFirst in this function; the example just illustrates how to include options, attributes, etc. You don't have to use the // style either. It's my preference to see func start many lines in a row.

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