我有一个对变量列表进行操作的运算符,如下所示:
(myfunc arg1 nil arg2 arg3)
我需要选择(取决于我们将调用的布尔变量my_bool
)向此列表添加一个额外的参数,以便函数调用如下所示:
(myfunc arg1 nil arg2 added_argument arg3)
我的第一个想法是用这样的 if 块来做到这一点:
(myfunc arg1 nil arg2 (if mybool t nil) arg3)
但这将导致 nil if mybool
is equal to nil
which is not allowed by the function syntax。
我的第二个想法是,也许我们可以过滤列表中的 nil 并将其删除,但我们无法这样做,因为首先出现的是 nil (或者我想不出办法,我很乐意被证明是错误的,只是在寻找解决方案)。
我的第三个想法是,如果我们有一个像 rubies 这样的 splat 运算符,我们可以过滤然后 splat 并且所有内容都会被整理出来,就像这样:
(myfunc arg1 nil (mysplat arg2 (filter (!= nil) (if mybool t nil)))) arg3)
但我一直无法找到一个 splat 运算符(从技术上讲是一个列表解构运算符)(PS 上面的代码是近似的,因为它是一个不起作用的解决方案,所以我确定在那里。
所以我的问题是如何有选择地向函数调用添加单个参数,并且如果我们不这样做,则不产生 nil 作为该参数。
在此先感谢,对不起我的菜鸟 emacs lisp 技能:(。