据我所知, if 的形式是(if [condition] [true] [false])。同样, cond 是(cond [condition] [true] ... [condition] [true] [false])。每个真假段似乎只接受一个动作。如果我想代表以下逻辑:
if (i > 0)
{
a += 5;
b += 10;
}
Run Code Online (Sandbox Code Playgroud)
我想我必须这样做:
(if (> i 0) (def a (+ a 5)))
(if (> i 0) (def b (+ b 10)))
Run Code Online (Sandbox Code Playgroud)
这样第二个动作就不会被混淆为错误的结果。这是它需要的方式,还是有办法为 if 创建更大的主体?
ps 我也怀疑每次重新定义 a 和 b 不是增加的最佳方法,但也没有看到不同的方法。使用 conj 时,我还必须重新定义列表。