MathGroup Archive 2013

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

Search the Archive

Re: redefining builtin but keep original available

  • To: mathgroup at smc.vnet.net
  • Subject: [mg131504] Re: redefining builtin but keep original available
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Wed, 14 Aug 2013 02:16:58 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net

On 8/13/13 at 3:59 AM, roby.nowak at gmail.com (roby) wrote:

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

Yes, it is possible to do what you have described. For example,
here is a snippet of code I have in my init file that modifies
the built-in command NotebookDirectory

Unprotect[NotebookDirectory];
NotebookDirectory[level_Integer] := Nest[ParentDirectory,
NotebookDirectory[], level];
Protect[NotebookDirectory];

This allows me to quickly go up the directory structure. Often I
have projects set up with notebooks in one subdirectory and data
in another subdirectory.

But you should be aware that some (many?) built-in functions are
written in Mathematica code. So, depending on exactly how you
modify a built-in function you could have undesired side effects
including breaking some other functionality within Mathematica
or causing significant slow down.




  • Prev by Date: Unprotect[] Protect[] redefining builtin but keep original available
  • Next by Date: Re: question related to (-1)^(1/3)
  • Previous by thread: Unprotect[] Protect[] redefining builtin but keep original available
  • Next by thread: Re: question related to (-1)^(1/3)