This is my function:
(defun MyFunction(input) (let ((NEWNUM (find input num))) (if (find input num) //if this (setq num NEWNUM) (FUNCT2) //then execute both of these (list 'not found)))) //else output this
So after the if
statement I want to be able to execute (setq num NEWNUM)
followed by (FUNCT2)
in order to set a new variable and then call a function. Any ideas on how to do this?
If you want to execute multiple statements for the else condition, enclose the code in curly brackets. If you only need to execute a single statement for the else condition, you do not need to use curly brackets.
The multiple IF conditions in Excel are IF statements contained within another IF statement. They are used to test multiple conditions simultaneously and return distinct values. The additional IF statements can be included in the “value if true” and “value if false” arguments of a standard IF formula.
While Excel will allow you to nest up to 64 different IF functions, it's not at all advisable to do so.
As a worksheet function, the IF function can be entered as part of a formula in a cell of a worksheet. It is possible to nest multiple IF functions within one Excel formula. You can nest up to 7 IF functions to create a complex IF THEN ELSE statement.
To do several things in sequence, you want progn
.
(defun MyFunction(input) (let ((NEWNUM (find input num))) (if (find input num) //if this (progn (setq num NEWNUM) (FUNCT2)) //then execute both of these (list 'not found)))) //else output this
When your if
is 'one-armed', as they call it (that is, it contains no else
branch), it's typically easier and more idiomatic to use when
and unless
: http://www.cs.cmu.edu/Groups/AI/html/hyperspec/HyperSpec/Body/mac_whencm_unless.html
When you call (when pred x y ... z)
, it will just evaluate x y z
sequentially if pred
is true. unless
behaves similarly when pred
is NIL. x y z
can represent any number of statements from one upwards. Thus:
(when pred (thunk))
is just the same as
(if pred (thunk))
Some people say when
and unless
should always be used for 'one-armed-ifs' because of clarity.
Edit: Your thread gave me an idea. This macro:
(defmacro if/seq (cond then else) `(if ,cond (progn ,@then) (progn ,@else)))
should enable this:
(if/seq (find input num) //if this ((setq num NEWNUM) (FUNCT2)) //then execute both of these ((list 'not found)))))
So the general format is:
(if/seq *condition* (x y ... z) (a b ... c))
Depending on the condition, it evaluates all of the subforms in the first or second, but only returns the last.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With