Page 73 - DCAP310_INTRODUCTION_TO_ARTIFICIAL_INTELLIGENCE_AND_EXPERT_SYSTEMS
P. 73

Unit 4: LISP




                                                                                                Notes
                 Example 2:
          Objective: Write a program for implementation of LISP manipulation functions.

          Solution:
          Function Call                 Value Returned
          (Car ‘(a b c))                    A
          (Cdr ‘(a b c))                    (B C)
          (Cons ‘a ‘(b c))                  (A B C)
          (List ‘a ‘(b c))                  (A (B C))

          (Append ‘(a) ‘(b c))              (A B C)
          (Last ‘(a b c d))                 (D)
          (Member ‘b ‘(a b d))              (B D)
          (Reverse ‘(a (b c) d))            (D (B C) A)


                 Example 3:
          Objective: Write a program for implementation of LISP Boolean function.
          Solution:

          Function Call                 Value Returned
          (Atom ‘aabb)                        t
          (Equal ‘a (car ‘(a b))              t
          (Evenp 3)                           nil
          (Number 10ab)                       nil
          (Oddp 3)                            t

          (Zerop .000001)                     nil
          (Greater 2 4 27)                    t
          (Lessp 5 3 1 2)                     nil
          (Listp ‘(a))                        t
          (Null nil)                          t


                 Example 4:
          Objective: Write a LISP Program calculating average of three numbers.

          Solution:
            AVERAGE OF THREE NUMBERS
              (defun averagethree(n1 n2 n3) (/(+ n1 n2 n3)3))
               AVERAGETHREE
            OUTPUT
               (Averagethree 10 20 30)




                                           LOVELY PROFESSIONAL UNIVERSITY                                   67
   68   69   70   71   72   73   74   75   76   77   78