This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

Documentation / Mathematica / Built-in Functions / Programming / Functional Programming /

Further Examples: Function (&)

Here is a pure function that squares its argument.

In[1]:=

Out[1]=

You can pass an argument to pure functions just as if they were ordinary functions like Sin or Min.

In[2]:=

Out[2]=

In[3]:=

Out[3]=

These use the shorthand notation for a pure function.

In[4]:=

Out[4]=

In[5]:=

Out[5]=

MyHead uses the third argument of Function to define a version of Head that does not evaluate its arguments.

In[6]:=

If the argument comes in unevaluated, it will remain that way.

In[7]:=

Out[7]=

This is in contrast to Head.

In[8]:=

Out[8]=

This tests unevaluated products to see if they contain spurious zeros.

In[9]:=

Out[9]=

This uses DeleteCases to delete the zeros so that the products do not evaluate to zero.

In[10]:=

Out[10]=

Here is a held list of elements.

In[11]:=

This groups consecutive elements that have the same head.

In[12]:=

Out[12]=

This does not work since the ordinary form of pure function will evaluate #1 and #2, which destroys the structure in expressions such as and .

In[13]:=

Out[13]=

In[14]:=