[Date Index] [Thread Index] [Author Index]
Re: redefining builtin but keep original available
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.