Wolfram ResearchPRODUCTSPURCHASEFOR USERSCOMPANYOUR SITES
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.

Fold

Usage
Notes
Further Examples

Here is a definition of the factorial function in functional programming style.

In[1]:=  

In[2]:=  

Out[2]=

Here is an implementation of Horner's rule.

In[3]:=  

Out[3]=

Here Fold is used to give the alternating sum of a list.

In[4]:=  

In[5]:=  

Out[5]=

Union with one argument drops duplicates from a list and reorders the remaining elements.

In[6]:=  

Out[6]=

Here is a function that also drops duplicates from a list but does not reorder the remaining elements. (See the Further Examples for Union for a version which is considerably faster on long lists with many distinct elements.)

In[7]:=  

In[8]:=  

Out[8]=

In[9]:=  

(See the Further Examples for ReplacePart for a powerful application of Fold to partial evaluation of held expressions.)


Any questions about topics on this page? Click here to get an individual response.Buy NowFree TrialMore Information



 © 2009 Wolfram Research, Inc.  Terms of Use  Privacy Policy |
Sign up for our newsletter: