Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!hookup!olivea!trib.apple.com!amd!netcomsv!zodiac!szh
From: szh@zcon.com (Syed Zaeem Hosain)
Subject: Re: Compound Statement in LISP
Message-ID: <1994Nov24.070749.20435@zcon.com>
Sender: szh@zcon.com (Syed Zaeem Hosain)
Nntp-Posting-Host: zodiac
Reply-To: szh@zcon.com
Organization: Z Consulting Group
References: <TAR.94Nov21174449@hobbes.ISI.EDU>
Date: Thu, 24 Nov 1994 07:07:49 GMT
Lines: 53



In article 4j3@hk.super.net,  Chris TSUI <christsk@hk.super.net> writes:

>I am a new student to LISP.
>
>I would like to know how to code compound statement like other
>languages. For example:
>
>in C:
>
>void test(int a, int b)
> {if (a > b)
>    { function_a();
>      function_b();
>    }
>  else 
>    { function_c();
>      function_d();
>    }
> }

Probably something like the following:

(defun test (a b)
  (cond ((> a b)
         (function_a)
         (function_b))
        (t
         (function_c)
         (function_d))))

You could also use the 'if' function (I prefer 'cond' myself - for no
good reason), but it only allows one expression for the condition being
true case. For this, if you wanted to call more than one function, you
could use a 'progn' to encapsulate the function calls:

(defun test (a b)
  (if (> a b)
    (progn
      (function_a)
      (function_b))
    (function_c)
    (function_d)))

								Z


-- 
-------------------------------------------------------------------------
| Syed Zaeem Hosain          P. O. Box 610097            (408) 441-7021 |
| Z Consulting Group        San Jose, CA 95161             szh@zcon.com |
-------------------------------------------------------------------------
