Writing more then 1 expressions after (if (cond)


#1

Hi ,
Is it possible to write more than 1 expressions after the if condition ?
Something like :

(if (a) ((something) (something_2) (something_3)) )

does this work , or is there an more elegant way ?
sometimes I need to do more than 1 things after the if-true condition.

Kind regards,
Ronny


#2

There are three alternative ways to achieve this:

  • In your example you could instead use when, which only takes a “then” argument which can be a list of forms:
(when (a) (something) (something_2) (something_3))
  • You could group together the three forms with progn:
(if (a) (progn (something) (something_2) (something_3)))

This option would also let you also supply an “else” argument:

(if (a) (progn (something) (something_2) (something_3))
   (otherwise_something))
  • Finally, you could use the more flexible cond clause, which lets you have any number of tests, each followed by one or more forms:
(cond
  ((a) (something) (something_2) (something_3))
  (t (otherwise_something)))

#3

Thank you very much !

Ronny