【问题标题】:Scheme several actions if an if-statement proves true如果 if 语句被证明为真,则计划几个动作
【发布时间】:2015-05-29 14:16:21
【问题描述】:

我理解方案 if 语句的方式是,第一个条件是 if 语句为真,第二个条件是它为假。如果我想要几个条件来判断语句是否为真?

一个例子:

(if (= a b)
    (set! ([a 2]))  // This shall happen when true
    (set! ([b 4]))  // This shall happen when true

    (set! ([a b])) // This shall happen when NOT true

有可能做这样的事情吗?

【问题讨论】:

标签: if-statement syntax scheme


【解决方案1】:

您可以尝试在 if 语句中使用 begin。像这样:

(if (something)
(begin (foo)
       (bar)))

【讨论】:

  • @Avenon 你也可以使用cond: 如(cond [something (foo) (bar)])
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-04
  • 1970-01-01
  • 1970-01-01
  • 2020-03-16
  • 2022-11-25
相关资源
最近更新 更多