我在一个函数内定义另一个函数。以下两种方法,哪一种更好或更受欢迎?
(let [hey (println "hey there")] hey)
或者
(let [hey (fn [] (println "hey here"))] (hey))
我在一个函数内定义另一个函数。以下两种方法,哪一种更好或更受欢迎?
(let [hey (println "hey there")] hey)
或者
(let [hey (fn [] (println "hey here"))] (hey))
(let [hey0 #(println "hey0")] (hey0))
(letfn [(hey1 [] (println "hey1"))] (hey1))
我不知道它们的使用有具体规定。当我需要定义很短的函数时,我使用#()
读取宏形式;如果我一次性定义了一堆内部函数,我则使用letfn
。
#(println ...)
而不是(println ...)
,对吗? - Alex