Scan
Usage
• Scan[f, expr] 依次把f 应用到expr的每个元素并对其进行计算.
• Scan[f, expr, levelspec] 把 f 应用到expr 中由levelspec指定的部分.
Notes
• Scan[f, expr] 丢掉把 f 应用到expr中的子表达式得到的结果. 与 Map不同,Scan返回时不创建新的表达式. • 你可以使用Return从Scan退出. Return[ret]使得Scan的最后值为ret. 如果不明确指定一个返回值,Scan的最后结果是Null. • 你也可以使用Throw从Scan退出. • Scan在对表达式的部分实现类似进行赋值这样一个具有"副作用"的操作是有用的. • Scan中levelspec的缺省值为{1}.
Further Examples
Scan evaluates the result of applying a function to each element but does not construct a new expression.
In[1]:=
|


 With the third argument set to Infinity, Scan visits the parts of an expression in a depth-first walk, with the leaves visited first.
In[2]:=
|







|