有人可以在 Racket 中为我解释这些功能吗?我完全迷路了。请帮我举一些例子。谢谢!我就是无法为我的生活弄清楚这些功能。
最佳答案
首先,如果:
(if (positive? 1) 1 -1)
Racket 首先评估 1 是否为正数(这是第一个表达式(正数?1))。如果是,则返回 1,否则,返回 -1。这相当于类 C 的语言在做:
if ( positive?(1))
return 1
else
return -1
Cond 基本上是一个有多个选项的 if。类 C 语言中的等价物是 else-if
(cond [(first-condition) (what-to-do)]
[(second-condition) (what-to-do)]
[(third-condition) (you-get-the-idea)])
And和Or只是逻辑运算符,相当于&&和||在类 C 语言中
(and true true) => true
(and true false) => false
(or true true) => true
(or true false) => true
(or false false) => false
关于if-statement - 条件如果和或在 Racket ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19569284/