我是Common Lisp的新手,正在尝试repeatedly从Clojure 实现a 。例如
(repeatedly 5 #(rand-int 11))
Run Code Online (Sandbox Code Playgroud)
这将收集5个(rand-int 11)调用,并返回一个列表:
(10 1 3 0 2)
目前,这是我正在做的:
(defun repeatedly (n f args)
(loop for x from 1 to n
collect (apply f args)))
Run Code Online (Sandbox Code Playgroud)
看起来不太好,我必须这样称呼:(repeatedly 5 #'random '(11))。有没有办法像Clojure的语法那样使函数更直观?
代码可能会变得很丑陋:(repeatedly 5 #'function (list (- x 1)))。