13
$\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$
5
  • 1
    $\begingroup$ SetAttributes[f, {Listable, Orderless}]; ClearAttributes[f, Attributes@f]; Attributes@f $\endgroup$ Commented Sep 22, 2014 at 13:53
  • $\begingroup$ This clears all attributes. I am looking for something to reset attributes to default. $\endgroup$ Commented Sep 22, 2014 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
    Commented Sep 22, 2014 at 14:28
  • $\begingroup$ @kguler pity that you didn't post this as an answer :) $\endgroup$
    – eldo
    Commented Sep 22, 2014 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
    Commented Sep 22, 2014 at 18:55

2 Answers 2

18
$\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$
15
$\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 and acknowledge you have read our privacy policy.

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