Scheme Programming language II

1.条件表达式(Conditionals)

(< a b)

如果a < b,返回true,否则返回false。

(<= a b)
如果a <= b,返回true,否则返回false。

(> a b)

如果a > b,返回true,否则返回false。

(>= a  b)

如果a >= b,返回true,否则返回false。

(equal? a b)

如果a == b,返回true,否则返回false。

 

2.If表达式

(if (> 6 5) (+ x y) (- x y))

如果第一个表达式为真的话,计算第二个表达式的值,否则计算第三个表达式的值。

if表达式的一般形式为:

(if (Predicate) (Body for true) (Body for false))

 

3.Cond关键字

(cond ((> x 0) x)

   ((< x 0) 0)

   ((= x 0) -x))

cond的一般形式为:

(cond (predicate1) (expression1)

     (predicate2) (expression2)

   (predicte3) (expression3)

   ......

   else (expression)

)

posted on 2013-09-06 07:20  Persistence  阅读(209)  评论(0编辑  收藏  举报

导航