Definitions such as f[x_]=x^2 specify values for functions. Sometimes, however, you need to specify general properties of functions, without necessarily giving explicit values.

The Wolfram Language provides a selection of attributes that you can use to specify various properties of functions. For example, you can use the attribute Flat to specify that a particular function is "flat", so that nested invocations are automatically flattened, and it behaves as if it were associative.

This assigns the attribute Flat to the function f:
Click for copyable input
Now f behaves as a flat, or associative, function, so that nested invocations are automatically flattened:
Click for copyable input

Attributes like Flat can affect not only evaluation, but also operations such as pattern matching. If you give definitions or transformation rules for a function, you must be sure to have specified the attributes of the function first.

Here is a definition for the flat function f:
Click for copyable input
Because f is flat, the definition is automatically applied to every subsequence of arguments:
Click for copyable input
Attributes[f]give the attributes of f
Attributes[f]={attr1,attr2,}set the attributes of f
Attributes[f]={}set f to have no attributes
SetAttributes[f,attr]add attr to the attributes of f
ClearAttributes[f,attr]remove attr from the attributes of f

Manipulating attributes of symbols.

This shows the attributes assigned to f:
Click for copyable input
This removes the attributes assigned to f:
Click for copyable input
Orderlessorderless, commutative function (arguments are sorted into standard order)
Flatflat, associative function (arguments are "flattened out")
OneIdentityf[f[a]], etc. are equivalent to a for pattern matching
Listablef is automatically "threaded" over lists that appear as arguments (e.g., f[{a,b}] becomes {f[a],f[b]})
Constantall derivatives of f are zero
NumericFunctionf is assumed to have a numerical value when its arguments are numeric quantities
Protectedvalues of f cannot be changed
Lockedattributes of f cannot be changed
ReadProtectedvalues of f cannot be read
HoldFirstthe first argument of f is not evaluated
HoldRestall but the first argument of f are not evaluated
HoldAllnone of the arguments of f are evaluated
HoldAllCompletethe arguments of f are treated as completely inert
NHoldFirstthe first argument of f is not affected by N
NHoldRestall but the first argument of f are not affected by N
NHoldAllnone of the arguments of f are affected by N
SequenceHoldSequence objects appearing in the arguments of f are not flattened out
Temporaryf is a local variable, removed when no longer used
StubNeeds is automatically called if f is ever explicitly input

The complete list of attributes for symbols in the Wolfram Language.

Here are the attributes for the builtin function Plus:
Click for copyable input

An important attribute assigned to builtin mathematical functions in the Wolfram Language is the attribute Listable. This attribute specifies that a function should automatically be distributed or "threaded" over lists that appear as its arguments. This means that the function effectively gets applied separately to each element in any lists that appear as its arguments.

The builtin Log function is Listable:
Click for copyable input
This defines the function p to be listable:
Click for copyable input
Now p is automatically threaded over lists that appear as its arguments:
Click for copyable input

Many of the attributes you can assign to functions in the Wolfram Language directly affect the evaluation of those functions. Some attributes, however, affect only other aspects of the treatment of functions. For example, the attribute OneIdentity affects only pattern matching, as discussed in "Flat and Orderless Functions". Similarly, the attribute Constant is only relevant in differentiation, and operations that rely on differentiation.

The Protected attribute affects assignments. The Wolfram Language does not allow you to make any definition associated with a symbol that carries this attribute. The functions Protect and Unprotect discussed in "Modifying Built-in Functions" can be used as alternatives to SetAttributes and ClearAttributes to set and clear this attribute. As discussed in "Modifying Built-in Functions", most builtin Wolfram Language objects are initially protected so that you do not make definitions for them by mistake.

Here is a definition for the function g:
Click for copyable input
This sets the Protected attribute for g:
Click for copyable input
Now you cannot modify the definition of g:
Click for copyable input

You can usually see the definitions you have made for a particular symbol by typing ?f, or by using a variety of builtin Wolfram Language functions. However, if you set the attribute ReadProtected, the Wolfram Language will not allow you to look at the definition of a particular symbol. It will nevertheless continue to use the definitions in performing evaluation.

Although you cannot modify it, you can still look at the definition of g:
Click for copyable input
This sets the ReadProtected attribute for g:
Click for copyable input
Now you can no longer read the definition of g:
Click for copyable input

Functions like SetAttributes and ClearAttributes usually allow you to modify the attributes of a symbol in any way. However, if you once set the Locked attribute on a symbol, then the Wolfram Language will not allow you to modify the attributes of that symbol for the remainder of your Wolfram System session. Using the Locked attribute in addition to Protected or ReadProtected, you can arrange for it to be impossible for users to modify or read definitions.

Clear[f]remove values for f, but not attributes
ClearAll[f]remove both values and attributes of f

Clearing values and attributes.

This clears values and attributes of p which was given attribute Listable above:
Click for copyable input
Now p is no longer listable:
Click for copyable input

By defining attributes for a function you specify properties that the Wolfram Language should assume whenever that function appears. Often, however, you want to assume the properties only in a particular instance. In such cases, you will be better off not to use attributes, but instead to call a particular function to implement the transformation associated with the attributes.

By explicitly calling Thread, you can implement the transformation that would be done automatically if p were listable:
Click for copyable input

Functions that perform transformations associated with some attributes.

Attributes in the Wolfram Language can only be permanently defined for single symbols. However, the Wolfram Language also allows you to set up pure functions which behave as if they carry attributes.

Function[vars,body,{attr1,}]a pure function with attributes attr1,

Pure functions with attributes.

This pure function applies p to the whole list:
Click for copyable input
By adding the attribute Listable, the function gets distributed over the elements of the list before applying p:
Click for copyable input