1
$\begingroup$

I have a question. Is ClearAttributes the built-in functon work in current cell only? This is my code:

In first cell:

Set[a, 6]

In second cell:

ClearAttributes[Set, HoldFirst]
Attributes[Set]
Set[a, 7]

As you can see in the second cell there is no attribute HoldFirst of Set function.

However, if I make a call in the third cell:

Attributes[Set]

It turns out that the Set function has a HoldFirst attribute.

So does the ClearAttributes function only work in the cell in which it is called?

$\endgroup$
  • 2
    $\begingroup$ No. ClearAttributes happens at the kernel level. Cells are a front-end construct. If this doesn't make sense this will help. You're omitting the fact that your Set[a, 7] causes a huge string of failures. Clearly Set resets itself, restoring its HoldFirst state. $\endgroup$ – b3m2a1 Jan 7 '18 at 18:40
  • 5
    $\begingroup$ You cannot reliably change the attributes or definitions of core system functions like Set. These functions have certain optimizations that insulate them from the full generality of the langage. This often means that any user-assigned attributes and definitions are either ignored or reset without warning. $\endgroup$ – Oleksandr R. Jan 7 '18 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.