我正在尝试弄清楚如何在数组定义中使用Return[]。为了学习这一点,我尝试创建一个长度为5的数组,其中每个元素都是数字10。以下是我的代码:
Array[Function[Return[10];], 5]下面是输出:
{Return[10], Return[10], Return[10], Return[10], Return[10]}哪里出了问题?为什么Return10不决定使用旧的简单的10?
在进阶时谢谢!
发布于 2012-10-10 09:40:31
您需要使用second argument指定从哪个头返回
Array[Function[Return[10, CompoundExpression];], 5]{10,10,10,10,10}
有关Return的基本功能的描述,请参阅Leonid Shifrin的this answer。
有关第二个论点(几乎没有记录)的进一步探索,请参阅这篇精美的自我问答:
What can be used as the second argument to Return on your own functions?
https://stackoverflow.com/questions/12792088
复制相似问题