在宏内部,我可以将 ,var 计算为空白/无吗?
感谢之前对 common 的回答lisp:宏如何使用以编程方式生成的名称定义其他方法/宏? 我有一个定义辅助函数的宏(实际上我有一个宏,我最喜欢的 lisp-newbie-hammer)。但在这个宏内部,有一些东西决定辅助函数是否需要接受特定的参数。因此,我有一个具有几乎相同分支的 if 语句 - 在一个分支下,我将 ,var 放入生成函数的 lambda 列表中。在另一个分支中,我省略了 ,var。 (我正在为非程序员编写 DSL,所以我不希望他们看到像 &可选 之类的东西)
有没有办法避免这里基本上重复的代码?如果我将 var 设置为“”,则“”将出现在生成的 defun 的 lambda 列表中。如果我将 var 设置为 nil,则会出现 NIL。
是否有一个我可以使用的值,使得 ,var 的计算结果完全为零,眨眼间就不存在了? (出于哲学兴趣,难道不应该有一个吗?)
Thanks to previous answers on common lisp: how can a macro define other methods/macros with programmatically generated names? I have a macro that defines helper functions (actually I have a macrolet, my new favorite lisp-newbie-hammer). But inside this macro, there is something that decides whether the helper functions need to take in a particular argument. So I have an if-statement with nearly identical branches -- down one branch, I place ,var in the lambda list of the generated functions. Down the other branch, I omit ,var. (I'm writing a DSL for non-programmers so I don't want them to see things like &optional)
Is there a way to avoid having basically duplicated code here? If I set var to "", then "" appears in the lambda list of my generated defuns. If I set var to nil, then NIL appears instead.
Is there a value that I can use such that ,var evaluates to absolutely nothing at all, winking out of existence? (And of philosophical interest, shouldn't there be one?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种选择是使用
,@var
,如果应该使用,则将您的值设置为列表,如果不应该使用,则将其设置为nil
。例如:unused
值已消失。One option is to use
,@var
and have your value be a list if it should be used,nil
if it shouldn't. For example:The
unused
value has disappeared.