Extended expression body for if-statements

Started by sponsy, March 05, 2013, 07:49:58 AM

Previous topic - Next topic

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).



(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

#1
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/Introduction_to_newLISP/Controlling_the_flow#Selection:_if.2C_cond.2C_and_casej">//http://en.wikibooks.org/wiki/Introduction_to_newLISP/Controlling_the_flow#Selection:_if.2C_cond.2C_and_casej

rickyboy

#2
Use when to evaluate multiple expressions.



http://www.newlisp.org/downloads/newlisp_manual.html#when">//http://www.newlisp.org/downloads/newlisp_manual.html#when



And cormullion is right about the general conditional and the use of begin.
(λx. x x) (λx. x x)

sponsy

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