定义Lisp宏时,双引号(双逗号)有用法吗? [英] Is there a use for double unquote (double comma) when defining a Lisp macro?

查看:166
本文介绍了定义Lisp宏时,双引号(双逗号)有用法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当定义一个使用宏的宏或定义一个定义宏的宏时,似乎使用,',,取消引用.有没有需要使用,,的情况?

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 ,,?

推荐答案

可以.

此处是代码. com/onlisp.html>格雷厄姆的《论Lisp》 :

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))))

另一个示例来自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.

这篇关于定义Lisp宏时,双引号(双逗号)有用法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆