Reputation: 21
Hey everyone so I'm looking for a way to convert a lisp macro to work in Clojure I looked at some other posts talking about if you could convert but they really didn't show an example and was maybe looking for some help on this.
(defmacro n-of (n form)
(let ((lst-sym (gensym))
(i-sym (gensym)))
`(let ((,lst-sym ()))
(dotimes (,i-sym ,n)
(push ,form ,lst-sym))
(nreverse ,lst-sym))))
Upvotes: 0
Views: 84
Reputation: 582
For lisp macro i assume Common Lisp macro.
(defmacro n-of [n & form]
`(let [f# #(do ~@form)]
(take ~n (repeatedly f#))))
where the & is like &rest or &body. #() is (lambda...). ~@ is ,@-. '~' is ','.
Upvotes: 2