[cl-faq] A FAQ, with answer: How do I do multiple statements in a row, in an IF?

Larry Clapp larry at theclapp.org
Sun Dec 18 10:27:33 CST 2005


#|
I found this in Google Groups.  I wanted to do a whole list of FAQ's &
A's, but life intervenes, so I'll post this one now and do more later.
|#

'(((:question
    "How do I do multiple statements in a row, in an IF?

    ;; Warning: Incorrect code!
    (if (test)
      ; then-part
      (statement1)
      (statement2)
      ; else-part
      (statement3)
      (statement4))
    ")
  (:answer
    "In general, wherever you can put a single expression, you can put
    a PROGN with multiple expressions.  So to solve this particular
    question,

    (if (test)
      (progn
	(statement1)
	(statement2))
      (progn
	(statement3)
	(statement4)))

    You could also use COND, which has implicit PROGN's for each set
    of result statements:

    (cond
      ((test) (statement1)
	      (statement2))
      (t (statement3)
	 (statement4)))

    Of course, COND also works with multiple tests.

    See the Hyperspec for PROGN and COND.")))

#|
-- Larry
|#



More information about the cl-faq mailing list