MathGroup Archive 2013

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Unprotect[] Protect[] redefining builtin but keep original available

Hi Robert,

Yes, this is possible. One solution is:

1. Create a conditional rule for the built-in symbol you would like to override, where the condition simply checks the value of some "override" symbol of your choosing. This allows you to effectively enable/disable the rule by setting the "override" symbol to True/False.

2. Globally, set the value of the "override" symbol to True, so that your rule will be in effect.

3. But, in the *body* of your rule, use a Block to locally set the value of the "override" symbol to False. Everything that executes within the body of the Block will ignore the rule, and the built-in symbol will have its default behavior.

Here is an example:

override = True;

Solve[args___] /; override :=
  Block[{override = False},
   Row[{"Here is my solution: ", Solve[args]}]

Solve[2 x + 4 == 13, x]


On Tuesday, August 13, 2013 12:56:31 AM UTC-7, roby wrote:
> Dear Group
> Is it in general possible to redefine mathematica builtins but still call the original function from within (but not only from there) the redefinition ?
> In particular I would like to overload a builtin (distinguished by an additional Option additionalopt->o) and keep the possibility to call the original (distinguished by omitting the additional Option or
> by setting additionalopt->None)
> Regards Robert

  • Prev by Date: Re: problem with mathematica ---> Get::"noopen": "Cannot open ("Graphics`Graphics`'")."
  • Next by Date: Re: MathSource Notebook Smith Normal Form Error - How to Correct?
  • Previous by thread: Re: DynamicModule values not saved correctly in "docked" cells?
  • Next by thread: Re: Unprotect[] Protect[] redefining builtin but keep original available