About "If.." in Scheme (plt-scheme)

user59634 picture user59634 · Jul 17, 2009 · Viewed 11.8k times · Source

I had a pretty simple requirement in my Scheme program to execute more than one statement, in the true condition of a 'if'. . So I write my code, something like this:

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

Obviously, the above doesn't work, since I have unintentionally created a # procedure with # arguments. So, to get my work done, I simply put the above expressions in a new function and call it from there, in place of the expression1, expression2. It works.

So, my point here is: is there any other conditional construct which may support my requirement here?

Answer

notnoop picture notnoop · Jul 17, 2009

In MIT-Scheme, which is not very different, you can use begin:

(if (= 1 1)
    (begin expression1 expression2)
    expression3)

Or use Cond:

(cond ((= 1 1) expression1 expression2)
      (else expression3))