Kenneth Tilton
1/6/2016 6:21:00 PM
On Wednesday, December 30, 2015 at 11:59:51 PM UTC-5, Anoop GR wrote:
> (defmacro with-gensyms1 (names &body body)
> `(let ,(mapcar #'(lambda (name) `(,name (gensym)))
> names)
> ,@body))
>
>
> (defmacro with-gensyms2 ((&rest names) &body body)
> `(let ,(mapcar #'(lambda (name) `(,name (gensym)))
> names)
> ,@body))
>
> ;;which of the above two is a better coding style in lisp and why?
> ;;or are they both equivalent with the 2nd one being just more verbose ?
If you do not like verbose, WJ and Paul Graham can tell you, you got the wrong language (and you should learn loop):
(defmacro with-gensyms ((&rest symbols) &body body)
`(let ,(loop for sym in symbols
collecting `(,sym (gensym ,(string sym))))
,@body))
I am pretty sure I have one macro somewhere that takes your version one approach, but it was just for yucks. It feels brittle.
-hk