1

I am trying to learn Lisp from Peter Seibel's book "Practical Common Lisp". In chapter 8 : "Macros: Defining your own", I came across this once-only macro. At the bottom of that page, an implementation is given.

I tried implementing my own macro for the same purpose earlier, but it had a bug, as pointed out at once-only lisp macro, is my implementation correct?.

This time I have done another alternate implementation, hopefully fixing that bug. I would like to know if my implementation is correct this time around ?

(defmacro my-once-only ((&rest args) &rest body)
  (let
    ((gensyms (loop for x in args collect (gensym))))

    `(let
      (,@(loop for g in gensyms for x in args collect `(,g ,x))
       ,@(loop for x in args collect `(,x (gensym))))

      `(let
         ,`(,,@(loop for x in args for g in gensyms collect ``(,,x ,,g)))

         ,,@body))))
Community
  • 1
  • 1
RKS
  • 309
  • 1
  • 6
  • 2
    If the code is (apparently) working, then this would be better for [Code Review](http://codereview.stackexchange.com/). I've flagged for migration. – Joshua Taylor Nov 04 '14 at 14:27
  • 1
    Ok, tnx. Wasnt aware of Code Review, my mistake, sorry. – RKS Nov 04 '14 at 14:58
  • 1
    No worries; it's a newer site. Since this question doesn't have a specific technical problem, it's not really on-topic for Stack Overflow, but it's a good fit for Code Review. I'd rather see it stay open and migrated than closed altogether. – Joshua Taylor Nov 04 '14 at 15:00

0 Answers0