本文介绍了引用读者宏调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法引用阅读器宏的调用?更具体地说,我想创建一个宏,该宏一旦被评估,将生成defclass语句和相应的XML文件.这可能吗?

is there a way to quote an invocation of a reader macro? More specifically, I want to create a macro, that once evaluated, will generate a defclass statement and a respective XML file. Is this possible?

我考虑过使用#.( ... )读取器宏,但是我假设宏参数未绑定在读取器宏内使用.这是正确的吗?

I thought about using #.( ... ) reader macros, but I assume the macro parameters aren't bound for use inside the reader macro. Is this correct?

因此,我的第二个想法是尝试生成一个包含阅读器宏的语句,但是我不确定是否有这样做的方法.

Therefore, my second thought was to try to generate a statement that included the reader macros, but I'm unsure if there is a way to do that.

关于扩展宏调用时生成XML文件的任何建议吗?

Any suggestions on generating XML files when expanding a macro invocation?

预先感谢您的任何想法.

Thanks in advance for any ideas.

推荐答案

类似的内容:

(defmacro def-wsdl-class (name (&rest supers)
                           (&rest slots)
                           &rest options)
  `(progn
     (eval-when (:compile-toplevel :execute)
       (with-open-file (xml-file (make-pathname :name (string-capitalize name)
                                                :type "wsdl"
                                                :defaults (or *compile-pathname*
                                                              *load-pathname*))
                                 :direction :output
                                 :if-exists ,(getf options :if-wsdl-exists :error))
         (when xml-file
           (spit-xml xml-file ',name ',supers ',slots ,@options))))
    `(defclass ,name (,@supers)
       (,@slots)
       ,@(chew options)))))

要回答您的原始问题,通常不能(反向)引用阅读器宏.它们是在读取语法的地方执行的,我们称之为读取时间.阅读器宏不参与正常的宏扩展,而是在宏扩展之前起作用.

To answer your original question, you can't generally (back)quote reader macros. They are executed right where the syntax is read, let's call it read-time. Reader macros don't participate in normal macro expansion, they act before macro expansion.

您可能会创建一个读取器宏,知道它在反引号读取器宏中被调用以与之一起使用,但这需要了解或更改反引号读取器宏的实现相关行为.

You could probably create a reader macro that knows it's being called inside a backquote reader macro to play with it, but it would require knowing or changing implementation dependent behaviour of the backquote reader macro.

但是,您可以从阅读器宏中返回带引号的表格.

However, you can return backquoted forms from reader macros.

这篇关于引用读者宏调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 11:31