Returning from a function

Discussion of Common Lisp
Post Reply
imba
Posts: 35
Joined: Sun Nov 21, 2010 2:13 pm

Returning from a function

Post by imba » Wed Nov 24, 2010 1:00 pm

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?

Warren Wilkinson
Posts: 117
Joined: Tue Aug 10, 2010 11:24 pm
Location: Calgary, Alberta
Contact:

Re: Returning from a function

Post by Warren Wilkinson » Wed Nov 24, 2010 1:31 pm

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)))
Need an online wiki database? My Lisp startup http://www.formlis.com combines a wiki with forms and reports.

Post Reply