This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Returning from a function

2 posts · 633 views

I want the following:
(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

Looks right to me, heres a slight simplification.
(defun foo
  (if (bar)
    (when (foobar) result)
    (barfoo))
If you want the result that foobar is generating (and foobar returns NIL if no result)...
(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.