12
$\begingroup$

Adding an attribute to a function is easy and clearing attribute is easy also. But I don't know really how to restore the attributes of a function to its defaults. All I do is quit the kernel or close Mathematica and open again.

any idea?

Update

For example :

Log // Attributes
(* {Listable, NumericFunction, Protected} *)

ClearAttributes[Log, Listable]
Log // Attributes
(* {NumericFunction, Protected} *)

Now is there any way to restore the attributes of Log to its defaults other than SetAttributes or quitting Mathematica?

Thanks.

$\endgroup$
  • 1
    $\begingroup$ SetAttributes[f, {Listable, Orderless}]; ClearAttributes[f, Attributes@f]; Attributes@f $\endgroup$ – Dr. belisarius Sep 22 '14 at 13:53
  • $\begingroup$ This clears all attributes. I am looking for something to reset attributes to default. $\endgroup$ – Algohi Sep 22 '14 at 14:12
  • 1
    $\begingroup$ You don't have to quit MMA, you can just Quit[], i.e.,Quit Kernel without having to start a new front-end session. $\endgroup$ – kglr Sep 22 '14 at 14:28
  • $\begingroup$ @kguler pity that you didn't post this as an answer :) $\endgroup$ – eldo Sep 22 '14 at 18:49
  • $\begingroup$ What I don't understand: Log has the attribute Protected. Why can we change its attributes without unprotecting it - Unprotect[Log] - in the first place? $\endgroup$ – eldo Sep 22 '14 at 18:55
16
$\begingroup$

If you have not saved the attributes before changing them, and also can't quit the Kernel, then you could launch a Subkernel and get the original attributes that way:

ClearAttributes[Log, Listable]

Attributes[Log]

{NumericFunction, Protected}

First@ParallelEvaluate[Attributes[Log]]

{Listable,NumericFunction,Protected}

$\endgroup$
14
$\begingroup$

Save defaults before any changes

attrLog = Log // Attributes;

ClearAttributes[Log, Listable]

Log // Attributes

{NumericFunction, Protected}

Restore defaults

Attributes[Log] = attrLog

{Listable, NumericFunction, Protected}

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.