在宏内部,我可以将 ,var 计算为空白/无吗?

发布于 2024-11-07 08:08:12 字数 558 浏览 2 评论 0原文

感谢之前对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╭ゆ眷念 2024-11-14 08:08:12

一种选择是使用 ,@var ,如果应该使用,则将您的值设置为列表,如果不应该使用,则将其设置为 nil 。例如:

(let ((used `((frob 1 2 3)))
      (unused nil))
  `(progn ,@unused ,@used))
=> (PROGN (FROB 1 2 3))

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:

(let ((used `((frob 1 2 3)))
      (unused nil))
  `(progn ,@unused ,@used))
=> (PROGN (FROB 1 2 3))

The unused value has disappeared.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文