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

后端 未结 16 2358
一整个雨季
一整个雨季 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 06:03

    I think this may not be exactly what you're looking for, but in Lisp 'labels' can be used to dynamically declare functions that can be called recursively.

    (labels ((factorial (x) ;define name and params
        ; body of function addrec
        (if (= x 1)
          (return 1)
          (+ (factorial (- x 1))))) ;should not close out labels
      ;call factorial inside labels function
      (factorial 5)) ;this would return 15 from labels
    

提交回复
热议问题