13

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.

Basheer Algohi
  • 19,917
  • 1
  • 31
  • 78

2 Answers2

18

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}

Jens
  • 97,245
  • 7
  • 213
  • 499
15

Save defaults before any changes

attrLog = Log // Attributes;

ClearAttributes[Log, Listable]

Log // Attributes

{NumericFunction, Protected}

Restore defaults

Attributes[Log] = attrLog

{Listable, NumericFunction, Protected}

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198