5

Found trying to use the usual trick to redefine GaussianFilter[ ]:

out[x_]:=Print["(*"<>ToString@x<>"*)"];
(* Redefining Circle[ ] works as expected*)
Unprotect[Circle];
Circle[a_,args__]:=
      Block[{$i=True},{"Circle",a}]/;!TrueQ[$i];
Protect[Circle];
out@Circle[{0,1},1,{0,2Pi}]

(*{Circle, {0, 1}}*)

(* Redefining GaussianFilter[ ] does not*)
Unprotect[GaussianFilter];
GaussianFilter[a_,args__]:=
              Block[{$j=True},{"GaussianFilter",a}]/;!TrueQ[$j];
Protect[GaussianFilter];

SetDelayed::write: Tag GaussianFilter in GaussianFilter[a_,args__] is Protected>>
Community
  • 1
  • 1
Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190
  • Voting to close because I think it is better to have one thread dealing with this, which people may find or be directed to, rather than two. Leonid & belisarius, if you can think of a more informative title for that question feel free to make the edit. – Mr.Wizard May 14 '11 at 21:47
  • 2
    @Mr.Wizard All I care about is that people who formulate the question similarly to @belisarius are redirected to a proper place (the first thread). Will closing this question still allow for that? Regarding the question title, I think something like "Problem redefining Protected symbols and system functions" may reflect the essence of the matter better. – Leonid Shifrin May 15 '11 at 13:34
  • @Leonid Title changed. Thanks a lot for your suggestion. The word "problem" is not accepted in titles :) – Dr. belisarius Oct 04 '11 at 12:40

1 Answers1

4

When you run the redefinition the second time, it works fine. Most likely the cause of the problem is the same as discussed here. I can not say that I am fond of this language feature, to say the least.

Community
  • 1
  • 1
Leonid Shifrin
  • 22,449
  • 4
  • 68
  • 100
  • @Leonid Thanks. I was aware of that answer. I don't know why I didn't relate both problems! – Dr. belisarius May 14 '11 at 17:00
  • 1
    @belisarius Perhaps because this behavior is too perplexing? It causes a shock every time you run into it, not just the first time (for me anyway). Completely unintuitive. I have expressed my opinion on this before - I think it breaks the language semantics for the part related to `Protect`-ing an `Unprotect`-ing symbols. – Leonid Shifrin May 14 '11 at 17:05
  • @Leonid Indeed But it saved me a few times when I was in need to perform some trick with an internal function and the code was already running. I am sure I could use another way, but this is handy. – Dr. belisarius May 14 '11 at 17:26
  • @belisarius I did not mean the redefinition trick - this one is very handy (and not difficult to understand). I meant the effect of symbols being `Protect`-ed back as a result of stuff loading automatically behind the scenes, without us even knowing about it. – Leonid Shifrin May 14 '11 at 17:29
  • @Leonid Oh, I see. I misunderstood your comment. The "hidden" Protect[ ] is really nasty. I think this is a side effect of Mma not being a monolithic core, but a modular library-extended system – Dr. belisarius May 14 '11 at 17:41
  • 1
    @belisarius I'd just consider it a bug in the module being loaded: it must check and only protect those symbols which were `Protected` at the time it started to load. Roman Maeder in his book shows a very simple idiom to do this for packages. It should not be more difficult for other modules, I guess. – Leonid Shifrin May 14 '11 at 17:56
  • @Leonid - While we're on the general topic of these system .mx files, riddle me this: If .mx's are supposedly dependent on the system, shouldn't we be able to read these back in as regular code somehow? For the life of me, I can't figure out how... Maybe this issue is somehow related? (Reasons for wanting to see the code: (1) want to learn how 'the pro's' code packages and (2) want to investigate the possibility of incorporating additional statistical tests into the estimation functions. Legacy code is available in the code library; I figured there'd be some way to see the current code too.) – telefunkenvf14 Aug 17 '11 at 07:00
  • @telefunkenvf14 I did not really try hard to get that code in a readable form, but I suspect that doing so will violate the Mathematica license - the code is proprietary, and the difficulty in getting it into a readable form is at least partially intentional, I am pretty sure. Packages are a different story - they are external to the system, while part of the core system functionality is indeed implemented in .mx binary files.But regardless of this, code which is internal to the system should not silently undo changes initiated by the user prior to it's auto-loading. – Leonid Shifrin Aug 17 '11 at 07:17