Extended expression body for if-statements

Q&A's, tips, howto's
Locked
sponsy
Posts: 3
Joined: Tue Mar 05, 2013 3:29 pm

Extended expression body for if-statements

Post 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!

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: Extended expression body for if-statements

Post 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

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Re: Extended expression body for if-statements

Post 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.
(λx. x x) (λx. x x)

sponsy
Posts: 3
Joined: Tue Mar 05, 2013 3:29 pm

Re: Extended expression body for if-statements

Post by sponsy »

Excellent, thanks! My eyes seemed to have skipped over that after bouncing around the wiki so frequently the last few days.

Locked