Fold
Usage
• Fold[f, x, list]给出FoldList[f, x, list]的最后元素。
Notes
• 可以使用Throw在它被完成前从Fold退出。 • 参见 Mathematica 全书 节 2.2.2.
Further Examples
(See the Further Examples for ReplacePart for a powerful application of Fold to partial evaluation of held expressions.) Here is the result of folding the function f over the list {a,b,c} starting with x.
In[1]:=
|
Out[1]=
|
Here is a definition of the factorial function in a functional style.
In[2]:=
|
In[3]:=
|
Out[3]=
|
In[4]:=
|
Here is an implementation of Horner's rule.
In[5]:=
|
Out[5]=
|
|