是否可以将宏扩展为多个元素? [英] Is it possible to expand a macro into several elements?

查看:66
本文介绍了是否可以将宏扩展为多个元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个宏my-macro,它可以扩展为1 2 3而不是(1 2 3),这样

I want a macro my-macro which can expand to 1 2 3 rather than (1 2 3), so that

(list (my-macro) 4 5) -> (1 2 3 4 5)

这可能吗?

推荐答案

否,宏不能扩展为多个值.当您需要将宏扩展为多段代码时,通常要做的就是将返回值包装在progn中.

No, macros cannot expand to more than one value. The typical thing to do when you need a macro to expand to multiple pieces of code is to wrap the return value in a progn.

在注释的示例中,看起来好像您不是将宏用作语法抽象,而是将其作为廉价而愉悦的函数优化来使用,通常的响应是请不要这样做,这是错误的"并没有真正做到你想要的".

In your example in the comments, it looks as if you are using macros not as syntactic abstractions, but as cheap-and-cheerful function optimizations, the usual response to that is "please don't do it, it is wrong and doesn't actually do what you want".

这篇关于是否可以将宏扩展为多个元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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