From: dlarkin on
Can an IF statement in lisp execute multiple expressions if it tests false.
For example:

(if (null expression) nil ;;if nil then skip the else part
((expression1) ;; else do expression 1 and expression 2
(expression2))


From: Pascal Bourguignon on
"dlarkin" <dlarkin3(a)mail.gatech.edu> writes:

> Can an IF statement in lisp execute multiple expressions if it tests false.

No it cannot.


> For example:
>
> (if (null expression) nil ;;if nil then skip the else part
> ((expression1) ;; else do expression 1 and expression 2
> (expression2))

This is meaningless in Common Lisp.

If you want to program in lisp, why don't you just read some lisp
tutorial instead of trying to invent some funny syntax?



If you want to do expression1 and expression2 only when expression is
not nil, why don't you just say so?

(when expression
expression1
expression2)


If you don't want to do expression1 and expressions unless expression
is nil, why don't you just say so?

(unless (null expression)
expression1
expression2)




Also, if you want the two branches of a IF, you have the same problem
than in Pascal, and the same solution. Only, a BEGIN ... END block is
written (PROGN ...) in lisp.

(if condition
(progn
...)
(progn
...))

But most often, you don't need to use progn, because you'll be using a
let or some other form that takes several expressions as body.

--
__Pascal Bourguignon__ http://www.informatimago.com/

"This statement is false." In Lisp: (defun Q () (eq nil (Q)))
From: Ralph Allan Rice on
I believe you can use UNLESS:

(unless (null expression)
(progn
(expression1)
(expression2)))

--
Ralph



dlarkin wrote:
> Can an IF statement in lisp execute multiple expressions if it tests false.
> For example:
>
> (if (null expression) nil ;;if nil then skip the else part
> ((expression1) ;; else do expression 1 and expression 2
> (expression2))

From: Ari Johnson on
"Ralph Allan Rice" <ralph.rice(a)gmail.com> writes:

> I believe you can use UNLESS:
>
> (unless (null expression)
> (progn
> (expression1)
> (expression2)))

Only if you like being redundant.

(unless X
Y
Z)

is equivalent to

(if (not X)
(progn
Y
Z))

From: Ralph Allan Rice on
Ahh.. touché. You are correct. Thank you.

--
Ralph



Ari Johnson wrote:
> "Ralph Allan Rice" <ralph.rice(a)gmail.com> writes:
>
> > I believe you can use UNLESS:
> >
> > (unless (null expression)
> > (progn
> > (expression1)
> > (expression2)))
>
> Only if you like being redundant.
>
> (unless X
> Y
> Z)
>
> is equivalent to
>
> (if (not X)
> (progn
> Y
> Z))