views:

1505

answers:

5
+1  A: 

You can use COND, or put the expressions into something like PROGN in Lisp (I am not sure how it is called in PLT Scheme. edit: it is called BEGIN).

COND looks like this in Scheme:

(cond [(= 1 1)
       (expression1)
       (expression2)]
      [else
       (expression3)])
Svante
+8  A: 

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))
notnoop
Note that the second expression is really the same as the first: the (cond ...) function has an implicit (begin ...) within each condition it checks, so they are obstensibly the same.
Andrew Song
+1  A: 

you can use (begin ...) to get what you want in the true branch of your if statement. See here

SpaceghostAli
+1  A: 

(begin ...) is how you evaluate multiple expressions and return the last one. Many other constructs act as "implicit" begin blocks (they allow multiple expressions just like a begin block but you don't need to say begin), like the body of a cond clause, the body of a define for functions, the body of a lambda, the body of a let, etc.; you may have been using it without realizing it. But for if, that is not possible in the syntax because there are two expressions (the one for true and the one for false) next to each other, and so allowing multiple expressions would make it ambiguous. So you have to use an explicit begin construct.

newacct
A: 

use (when CONDITION STMTS)

Geoffrey King