当一个人定义一个使用宏的宏,或定义一个定义宏的宏时,似乎使用,',
或取消引用,
事物。有没有我需要使用的情况,,
?
问问题
331 次
1 回答
6
当然。
以下是Graham的“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))))
另一个例子来自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)))
简而言之,这不是很常见,但并非闻所未闻。
于 2013-07-30T04:46:17.953 回答