Which languages support *recursive* function literals / anonymous functions?

后端 未结 16 2352
一整个雨季
一整个雨季 2021-02-04 05:09

It seems quite a few mainstream languages support function literals these days. They are also called anonymous functions, but I don\'t care if they have a name. The important th

16条回答
  •  自闭症患者
    2021-02-04 05:54

    It also seems Mathematica lets you define recursive functions using #0 to denote the function itself, as:

    (expression[#0]) &
    

    e.g. a factorial:

    fac = Piecewise[{{1, #1 == 0}, {#1 * #0[#1 - 1], True}}] &;
    

    This is in keeping with the notation #i to refer to the ith parameter, and the shell-scripting convention that a script is its own 0th parameter.

提交回复
热议问题