Page 1 of 1

Returning from a function

Posted: Wed Nov 24, 2010 1:00 pm
by imba
I want the following:

Code: Select all

(defun foo
  (if (bar)
      (if (foobar)
          (print result)
        nil)
    (barfoo)
This should work as follows: If bar, then: return result if foobar, and nil if not foobar. If not bar, then return barfoo.

How do I have to modify my code for this?

Re: Returning from a function

Posted: Wed Nov 24, 2010 1:31 pm
by Warren Wilkinson
Looks right to me, heres a slight simplification.

Code: Select all

(defun foo
  (if (bar)
    (when (foobar) result)
    (barfoo))
If you want the result that foobar is generating (and foobar returns NIL if no result)...

Code: Select all

(defun foo (if (bar) (foobar) (barfoo)))