在elisp中,有一个 "if" 语句,我希望能够执行许多不同的操作:(if condition (do-something) (do-another-thing) ...) 然而,(do-another-thing) 只在 else 语句中执行。你如何指定需要执行的一组指令?例如:(if condition (begin (do-something) (do-another-thing) ...))
如果没有需要使用else的情况,使用以下代码可能更易读:(when condition (do-something) (do-another-thing)) 还有一个相反的情况(unless (not condition) (do-something) (do-another-thing)) 查看Emacs Lisp条件语句手册。
when
和unless
(即它们仅用于产生副作用)。当返回值很重要时,我通常会使用and
和or
。当有多个分支(无论返回值是否重要)时,我通常会使用if
和cond
。 - Drew