Is there a use for double unquote (double comma) when defining a Lisp macro?
当定义一个使用宏的宏或定义一个定义宏的宏时,似乎使用
好的。
这是Graham的" On Lisp "中的代码:
1 2 3 4 5 6 7 | (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)))) |
另一个示例来自
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | (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))) |
简而言之,这不是很常见,但并非闻所未闻。