2

When one is defining a macro that uses a macrolet, or defining a macro that defines a macro, it seems one uses ,', or , to unquote things. Is there ever a case when I need to use ,,?

Jisang Yoo
  • 3,670
  • 20
  • 31

1 Answers1

6

Sure.

Here is code from Graham's "On Lisp":

(defmacro =defun (name parms &body body)
  (let ((f (intern (concatenate 'string
                                "=" (symbol-name name)))))
    `(progn
       (defmacro ,name ,parms
         `(,',f *cont* ,,@parms))
       (defun ,f (*cont* ,@parms) ,@body))))

Another example is from clx/gcontext.lisp:

(macrolet ((def-gc-internals (name &rest extras)
             (let ((macros nil)
                   (indexes nil)
                   (masks nil)
                   (index 0))
               (dolist (name *gcontext-components*)
                 (push `(defmacro ,(xintern 'gcontext-internal- name) (state)
                          `(svref ,state ,,index))
                       macros)
                 (setf (getf indexes name) index)
                 (push (ash 1 index) masks)
                 (incf index))
               (dolist (extra extras)
                 (push `(defmacro ,(xintern 'gcontext-internal- (first extra)) (state)
                          `(svref ,state ,,index))
                       macros)
                 ;; don't override already correct index entries
                 (unless (or (getf indexes (second extra)) (getf indexes (first extra)))
                   (setf (getf indexes (or (second extra) (first extra))) index))
                 (push (logior (ash 1 index)
                               (if (second extra)
                                   (ash 1 (position (second extra) *gcontext-components*))
                                   0))
                       masks)
                 (incf index))
               `(within-definition (def-gc-internals ,name)
                  ,@(nreverse macros)
                  (eval-when (:execute :compile-toplevel :load-toplevel)
                    (defparameter *gcontext-data-length* ,index)
                    (defparameter *gcontext-indexes* ',indexes)
                    (defparameter *gcontext-masks*
                      ',(coerce (nreverse masks) 'simple-vector)))))))
  (def-gc-internals ignore
    (:clip :clip-mask) (:dash :dashes) (:font-obj :font) (:timestamp)))

In short, this is not very common, but not unheard of.

sds
  • 58,617
  • 29
  • 161
  • 278
  • @Robert the `=defun` example seems to be for expanding `(=defun hello (x y) (+ x y))` to `(progn (defmacro hello (x y) \`(=hello *cont* ,x ,y)) ...)` which is for continuation according to On Lisp pdf. The `,,index` example seems to be doing the same as `,',index` because `index` holds a number which is self evaluating. – Jisang Yoo Aug 03 '13 at 13:49
  • Also, one may decide that `(=defun hello (x y) (+ x y))` should be expanded to `(progn (defmacro hello (&rest args) \`(=hello *cont* ,@args)) ...)` instead which eliminates use of `,,@` while achieving the same goal. – Jisang Yoo Aug 03 '13 at 13:51