【问题标题】:Mathematica syntax with & symbol带 & 符号的 Mathematica 语法
【发布时间】:2013-10-20 16:32:33
【问题描述】:

我在 Mathematica 中遇到过这个表达式:

oneStep[plus[e1_ , e2_]] := Flatten[{With[{a=e1,b=#},plus[a,b]]&/@oneStep[e2],
                                  With[{a=#,b=e2},plus[a,b]]&/@oneStep[e1]}];

但我似乎无法理解这个 &/ 符号在这个表达式中的含义。

其次:这可以写成更“人性化”的方式吗?

【问题讨论】:

    标签: wolfram-mathematica


    【解决方案1】:

    & 表示pure function(有点像 lambda)。是的,它可以写成更友好的方式。正如链接文档所示:

    body&
    

    等价于

    Function[x,body]
    

    x 是参数。

    /@map(也可以用更友好的方式编写,您可以从文档中看到)。

    【讨论】:

      【解决方案2】:

      补充 arshajii 的回答:

      veryLongFunctionName[n_] := n + n/2;
      Map[veryLongFunctionName, {1, 2, 3}]
      

      返回:

      {3/2,3,9/2}

      长于:

      Map[# + #/2 &, {1, 2, 3}]
      

      长于:

      # + #/2 & /@ {1, 2, 3}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-18
        • 2022-10-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多