关于Scheme中的"If .."(plt-scheme)

16 lisp scheme racket

在我的Scheme程序中,我有一个非常简单的要求,即在'if' 的真实条件下执行多个语句..所以我写了我的代码,如下所示:

(if (= 1 1)
 ((expression1) (expression2))  ; these 2 expressions are to be
                                ; executed when the condition is true
  (expression3))
Run Code Online (Sandbox Code Playgroud)

显然,上面的方法不起作用,因为我无意间用#参数创建了一个#过程.因此,为了完成我的工作,我只需将上面的表达式放在一个新函数中,然后从那里调用它,代替expression1,expression2.有用.

所以,我的观点是:是否有其他条件结构可以支持我的要求?

not*_*oop 22

在MIT-Scheme中,你可以使用begin:

(if (= 1 1)
    (begin expression1 expression2)
    expression3)
Run Code Online (Sandbox Code Playgroud)

或者使用Cond:

(cond ((= 1 1) expression1 expression2)
      (else expression3))
Run Code Online (Sandbox Code Playgroud)