Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 8

Artificial Intelligence

(TIT-752)
PRACTICAL FILE

SUBMITTED TO: SUBMITTED BY:


INDEX

Page
S.No. Name of Programs
No.
Date Signature Remarks
1. Simple examples of
list manipulation
functions
2. Define functions  in
lisp
3. Write conditional
functions using lisp
4. Write functions for
input-output using
lisp
5. Write function of
iteration using lisp
6. Write function of
recursion using lisp
                                                

Experiment No.-1 
1. Simple examples of list manipulation functions:
1. Append

( append ‘(a) ‘(bc) )

Ans-> ( a b c ) 

2. Last

( last ‘( e f g h ) )

Ans-> ( h ) 

3. Member

( member ‘c  ‘( a b e c g h ) )

Ans-> ( c  g h ) 

4. Reverse

( reverse  ‘( a ( b c ) d ) )

Ans-> ( d ( b c ) a ) 

                                     
Experiment No.-2 

2. Defining function in Lisp:


( defun fun_name ( para1 para2 … )

( operator para1 para2 … ) )

1. For addition

( defun add ( a b )

( + a b ) ) 

2. For multiplication

( defun multiply ( a b )

( * a b ) ) 

 
Experiment No.-3

          3. Write conditional function using Lisp:


1. For two variables

( defun fun_name ( var1 var2 )

( cond ( ( > var1 var2 ) var1 )

( t var2 ) ) ) 

2. For three variables

( defun fun_name  ( var1 var2 var3 )

( cond  ( ( > var1 var2 )

( cond ( ( > var1 var3 ) var1 )

( t var3 ) ) )

                ( ( > var2 var3 ) var2 )

                 ( t var3 ) ) ) 

         
                                                    

                                                

                                                  
Experiment No.-4

4. Write functions for input-output using lisp


1. read

( + 5 (read) )

2. print

( print  “ hello lisp” )

3. princ

( princ  “hello mam” )

4. Area of circle using I/O  function

                                                
Experiment No.-5

  5. Write function of iteration using lisp: 


1. Iteration with do statement-

               ( do ( <var1 val1>  <var-update1> )

                        ( <var2 val2>  <var-update2> )

                                  .

                                  .

                         (<test>  <return-value>)

                         (<S-expression>)) 

2. Iterative function of factorial-

( defun fact ( n )

      ( do ( ( count n ( - count 1 ) )

                 ( product n ( * product ( - count 1 ) )

               ( ( equal 0 count ) product ) ) )

 
 
 
 
 
 
 
 
 
 
 
 
 Experiment No.-6                                 

6. Write function of recursion using lisp:


o Recursive function of factorial

               ( defun fact ( n )

                    ( cond ( ( zerop n ) 1 )

                                 ( t ( * n ( fact ( - n 1 ) ) ) ) ) ) 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

                                                                    

You might also like