Page 1 of 1

Extended expression body for if-statements

Posted: Tue Mar 05, 2013 3:49 pm
by sponsy
Hi :) I'm pretty new to newlisp, but I'm loving it so far for its quick scripting abilities-- I want to see if it can outdo Python for terseness.

What I can't seem to find an answer to: I want to execute multiple expressions within an if-statement branch without defining a separate function. So, when the if-statement below evaluates to true, I want to push the value 10 onto the list x, and in the same breath clear the list y (without defining separate function).

Code: Select all

(set 'x '())
(set 'y '(1 2 3))

(if 
    (nil?) (push 10 x)) ; how can I also clear y here? (evaluate multiple expressions)
Probably an ignorant question, but I'm struggling to find a better way. Thanks!

Re: Extended expression body for if-statements

Posted: Tue Mar 05, 2013 4:51 pm
by cormullion
cond is a more powerful conditional handler, and allows a few more tricks. But you can just use begin to group statements,together... http://en.wikibooks.org/wiki/Introducti ... _and_casej

Re: Extended expression body for if-statements

Posted: Tue Mar 05, 2013 5:29 pm
by rickyboy
Use when to evaluate multiple expressions.

http://www.newlisp.org/downloads/newlis ... .html#when

And cormullion is right about the general conditional and the use of begin.

Re: Extended expression body for if-statements

Posted: Tue Mar 05, 2013 6:41 pm
by sponsy
Excellent, thanks! My eyes seemed to have skipped over that after bouncing around the wiki so frequently the last few days.