pass 或 "do nothing" 的 lisp/scheme 等价物是什么
What is the lisp/scheme equivalent of pass or "do nothing"
我想在方案中执行以下模式:
if N > 0:
pass
else:
do-function()
目前我把它模拟成这样:
(if (> N 0) pass?? (do-function))
pass
或continue
或return
或;
或'do-nothing'在方案中的正确方法是什么,但保留它有一个占位符所以我知道它是故意的(而不是将 if
更改为 if not N > 0
或 if N<=0
等)
您可以根据自己的喜好添加一个虚拟表达式,
(if (> n 0) '() (do-something))
或糖衣,
(define pass '())
(if (> n 0) pass (do-something))
但是 Common Lisp 和 Scheme 中都有一些结构可以使意图清晰而不混乱 – unless
和 when
:
(unless (> n 0) (do-something))
(when (<= n 0) (do-something))
如果不采用分支,则该值在 Common Lisp 中是 nil
,在 Scheme 中是未指定的(即一些依赖于实现的值)。
我想在方案中执行以下模式:
if N > 0:
pass
else:
do-function()
目前我把它模拟成这样:
(if (> N 0) pass?? (do-function))
pass
或continue
或return
或;
或'do-nothing'在方案中的正确方法是什么,但保留它有一个占位符所以我知道它是故意的(而不是将 if
更改为 if not N > 0
或 if N<=0
等)
您可以根据自己的喜好添加一个虚拟表达式,
(if (> n 0) '() (do-something))
或糖衣,
(define pass '())
(if (> n 0) pass (do-something))
但是 Common Lisp 和 Scheme 中都有一些结构可以使意图清晰而不混乱 – unless
和 when
:
(unless (> n 0) (do-something))
(when (<= n 0) (do-something))
如果不采用分支,则该值在 Common Lisp 中是 nil
,在 Scheme 中是未指定的(即一些依赖于实现的值)。