SlideShare a Scribd company logo
ARTIFICIAL INTELLIGENCE
LISP and PROLOG
Submitted to : Submitted by:
Dr.arpana chaturvedi Arti kumari
S No. CONTENT REMARK
LISP
1 To print “hello world” in LISP
2 program To find the area of circle
3 to print odd number form 1-20
4 to print the average of number 10,20,30,40
5 defining macro
OPERATORS
6 Arithmetic operator
7 Comparision operator
8 Logical operator
DECISIONS CONSTRUCT
9 Cond
10 If
11 When
12 case
LOOPS
13 Loop
14 Loop for
15 Do
16 dotimes
17 dolist
18 Predicate
29 Factorial of a number
20 Array
21 String
22 Sequence
23 list
24 Exiting from block
25 Let function
26 Prog function
27 Formatted output
PROLOG
28 Print hello world using prolog. In console
29 prolog program to print hello world..
30 Priya, Tiyasha, and Jaya are three girls, among
them, Priya can cook
31 some rules. Rules contain some information that
are conditionally true about the domain of
interest.
32 Priya, Tiyasha, and Jaya are three girls, among
them, Priya can cook.
;use of variable in our query
33 Prolog program, that can find the minimum of
two numbers and the maximum of two numbers.
34 write a prolog program that will help us find the
equivalent resistance
35 program to show working of Arithmetic operator
in prolog
36 prolog program to print values from 1 to10 using
loop
37 Example of decision making in Prolog.
38 prolog program to find the length of the list
39 prolog program to concatenate two list
40 Backtracking.
41 prolog program to find the cube of a number
LISP
Q1)To print “hello world” in LISP
CODE:
(write-line "Hello World")
(write-line "I am at 'Online class' !-
Learning LISP" )
Q2) LISP program To find the area of circle ..
CODE:
(defconstantp13.141592)
(defunarea-circle(rad)
(terpri)
(formatt " Radius:~5f"rad)
(formatt "~%area:~10f" (* p1 rad rad)))
(area-circle 10)
Q3)LISP program to print odd number form 1-20 ?
CODE:
(loopfor x from 1 to 20
if(oddpx)
do (printx)
)
Q4)LISP program to print the average of number 10,20,30,40
CODE:
;write a LISP program to find the average of numbers
(defunaveragenum(n1 n2 n3 n4)
( / ( + n1 n2 n3 n4) 4)
)
(write(averagenum10 20 30 40))
Q5.defining macro
CODE:
(defmacro setTo10(num)
(setq num 10)(print num))
(setq x 25)
(print x)
(setTo10 x)
Q6)Arithmetic operators
(setq a 10)
(setq b 20)
(format t "~% A + B = ~d" (+ a b))
(format t "~% A - B = ~d" (- a b))
(format t "~% A x B = ~d" (* a b))
(format t "~% B / A = ~d" (/ b a))
(format t "~% Increment A by 3 = ~d" (incf a 3))
(format t "~% Decrement A by 4 = ~d" (decf a 4))
Q7) Comparison operator
(setq a 10)
(setq b 20)
(format t "~% A = B is ~a" (= a b))
(format t "~% A /= B is ~a" (/= a b))
(format t "~% A > B is ~a" (> a b))
(format t "~% A < B is ~a" (< a b))
(format t "~% A >= B is ~a" (>= a b))
(format t "~% A <= B is ~a" (<= a b))
(format t "~% Max of A and B is ~d" (max a b))
(format t "~% Min of A and B is ~d" (min a b))
Q8) logical operator
(setq a 10)
(setq b 20)
(format t "~% A and B is ~a" (and a b))
(format t "~% A or B is ~a" (or a b))
(format t "~% not A is ~a" (not a))
(terpri)
(setq a nil)
(setq b 5)
(format t "~% A and B is ~a" (and a b))
(format t "~% A or B is ~a" (or a b))
(format t "~% not A is ~a" (not a))
(terpri)
(setq a nil)
(setq b 0)
(format t "~% A and B is ~a" (and a b))
(format t "~% A or B is ~a" (or a b))
(format t "~% not A is ~a" (not a))
(terpri)
(setq a 10)
(setq b 0)
(setq c 30)
(setq d 40)
(format t "~% Result of and operation on 10, 0, 30, 40 is ~a"
(and a b c d))
(format t "~% Result of and operation on 10, 0, 30, 40 is ~a"
(or a b c d))
(terpri)
(setq a 10)
(setq b 20)
(setq c nil)
(setq d 40)
(format t "~% Result of and operation on 10, 20, nil, 40 is ~a"
(and a b c d))
(format t "~% Result of and operation on 10, 20, nil, 40 is ~a"
(or a b c d))
Lisp and prolog in artificial intelligence
Q9) cond construct
(setq a 10)
(cond ((> a 20)
(format t "~% a is greater than 20"))
(t (format t "~% value of a is ~d " a)))
Q10) If construct
(setq a 10)
(if (> a 20)
(format t "~% a is less than 20"))
(format t "~% value of a is ~d " a)
Q11)When construct
(setq a 100)
(when (> a 20)
(format t "~% a is greater than 20"))
(format t "~% value of a is ~d " a)
Q12)Case construct
(setq day 4)
(case day
(1 (format t "~% Monday"))
(2 (format t "~% Tuesday"))
(3 (format t "~% Wednesday"))
(4 (format t "~% Thursday"))
(5 (format t "~% Friday"))
(6 (format t "~% Saturday"))
(7 (format t "~% Sunday")))
Q13)Loop construct
(setq a 10)
(loop
(setq a (+ a 1))
(write a)
(terpri)
(when (> a 17) (return a))
)
Q14)Loop for
(loop for x from 1 to 20
if(evenp x)
do (print x)
)
Q15)Do construct
(do ((x 0 (+ 2 x))
(y 20 ( - y 2)))
((= x y)(- x y))
(format t "~% x = ~d y = ~d" x y)
)
Q16)dotimes
(dotimes (n 11)
(print n) (prin1 (* n n))
)
Q17)dolist
(dolist (n '(1 2 3 4 5 6 7 8 9))
(format t "~% Number: ~d Square: ~d" n (* n n))
)
Q18)predicate
(write (atom 'abcd))
(terpri)
(write (equal 'a 'b))
(terpri)
(write (evenp 10))
(terpri)
(write (evenp 7 ))
(terpri)
(write (oddp 7 ))
(terpri)
(write (zerop 0.0000000001))
(terpri)
(write (eq 3 3.0 ))
(terpri)
(write (equal 3 3.0 ))
(terpri)
(write (null nil ))
Q19)To find the factorial of a number
(defun factorial (num)
(cond ((zerop num) 1)
(t ( * num (factorial (- num 1))))
)
)
(setq n 6)
(format t "~% Factorial ~d is: ~d" n (factorial n))
Q20)Array
(write (setf my-array (make-array '(10))))
(terpri)
(setf (aref my-array 0) 25)
(setf (aref my-array 1) 23)
(setf (aref my-array 2) 45)
(setf (aref my-array 3) 10)
(setf (aref my-array 4) 20)
(setf (aref my-array 5) 17)
(setf (aref my-array 6) 25)
(setf (aref my-array 7) 19)
(setf (aref my-array 8) 67)
(setf (aref my-array 9) 30)
(write my-array)
Q21)String
(write-line "Hello World")
(write-line "Welcome to JAGANNATH INSTITUTE OF MANAGEMENT
SCIENCES")
;escaping the double quote character
(write-line "Welcome SIXTH SEMESTER")
Q22) sequence
(write (count 7 '(1 5 6 7 8 9 2 7 3 4 5)))
(terpri)
(write (remove 5 '(1 5 6 7 8 9 2 7 3 4 5)))
(terpri)
(write (delete 5 '(1 5 6 7 8 9 2 7 3 4 5)))
(terpri)
(write (substitute 10 7 '(1 5 6 7 8 9 2 7 3 4 5)))
(terpri)
(write (find 7 '(1 5 6 7 8 9 2 7 3 4 5)))
(terpri)
(write (position 5 '(1 5 6 7 8 9 2 7 3 4 5)))
Q23)lists
(write (cons 1 2))
(terpri)
(write (cons 'a 'b))
(terpri)
(write (cons 1 nil))
(terpri)
(write (cons 1 (cons 2 nil)))
(terpri)
(write (cons 1 (cons 2 (cons 3 nil))))
(terpri)
(write (cons 'a (cons 'b (cons 'c nil))))
(terpri)
(write ( car (cons 'a (cons 'b (cons 'c nil)))))
(terpri)
(write ( cdr (cons 'a (cons 'b (cons 'c nil)))))
Q24)exiting from the block
Q25) let function
(let((x 'a)(y'b) (z'c))
(formatt "x= ~a y= ~a z= ~a" x y z))
Q26)prog function
(prog((x'(abc))(y'(12 3))(z'(pq10)))
(formatt"x=~a y=~a z=~a" x y z))
Q27)Formatted output
(setqx 10)
(setqy20)
(formatt"x=~2d y=~2d ~%" x y)
(setqx 100)
(setqy200)
(formatt"x=~2d y=~2d" x y)
PROLOG
Q28) Print hello world using prolog..
CODE:
write('Hello World').
Q29)prolog program to print hello world..
CODE:
main :- write('This is sample Prolog program'),
write(' This program is written into hello_world.pl file').
Q30) Priya, Tiyasha,and Jaya are three girls, among them,Priya can cook.
CODE:
girl(priya).
girl(tiyasha).
girl(jaya).
can_cook(priya).
Q31) some rules. Rules contain some informationthat are conditionally true about the
domain of interest.
CODE:
sing_a_song(ananya).
listens_to_music(rohit).
listens_to_music(ananya):- sing_a_song(ananya).
happy(ananya):- sing_a_song(ananya).
happy(rohit) :- listens_to_music(rohit).
playes_guitar(rohit):- listens_to_music(rohit).
Q32) Priya, Tiyasha,and Jaya are three girls, among them,Priya can cook.
;use of variable in our query
CODE:
can_cook(priya).
can_cook(jaya).
can_cook(tiyasha).
likes(priya,jaya) :- can_cook(jaya).
likes(priya,tiyasha) :- can_cook(tiyasha).
Q33) Prolog program,that can find the minimum of two numbers and the maximum
of two numbers.
CODE:
find_max(X,Y,X) :- X >= Y, !.
find_max(X,Y,Y) :- X < Y.
find_min(X,Y, X) :- X =< Y, !.
find_min(X,Y, Y) :- X > Y.
Q34) write a prolog program that will help us find the equivalent resistance.
 If R1 and R2 are in Series, then equivalent resistor Re = R1 + R2.
 If R1 and R2 are in Parallel, then equivalent resistor Re = (R1 * R2)/(R1 +
R2).
Lisp and prolog in artificial intelligence
Q35)programto show working of Arithmetic operatorin prolog
+ Addition
- Subtraction
* Multiplication
/ Division
** Power
// Integer Division
mod Modulus
Q36)prolog program to print values from 1 to10 using loop
CODE:
count_to_10(10):- write(10),nl.
count_to_10(X) :-
write(X),nl,
Y is X + 1,
count_to_10(Y).
Q37) Example of decision making in Prolog.
CODE:
% If-Then-Else statement
gt(X,Y) :- X >= Y,write('X is greateror equal').
gt(X,Y) :- X < Y,write('X is smaller').
% If-Elif-Else statement
gte(X,Y) :- X > Y,write('X is greater').
gte(X,Y) :- X =:= Y,write('X and Y are same').
gte(X,Y) :- X < Y,write('X is smaller').
Q38)prolog program to find the length of the list ;?
CODE:
list_length([],0).
list_length([_|TAIL],N) :- list_length(TAIL,N1),N is N1 + 1.
Q39)prolog program to concatenatetwo list
CODE:
list_concat([],L,L).
list_concat([X1|L1],L2,[X1|L3]) :- list_concat(L1,L2,L3).
Q40)Backtracking.
CODE:
boy(tom).
boy(bob).
girl(alice).
girl(lili).
pay(X,Y) :- boy(X), girl(Y).
Q41)prolog program to find the cube of a number
CODE:
cube :-
write('Write a number:'),
read(Number),
process(Number).
process(stop) :- !.
process(Number) :-
C is Number* Number* Number,
write('Cube of '),write(Number),write(': '),write(C),nl,cube.

More Related Content

PPT
Asymptotic notations
PDF
AI 7 | Constraint Satisfaction Problem
PPTX
8 queens problem using back tracking
PPTX
Theory of automata and formal language
PPTX
Asymptotic notations
PDF
Image Restoration (Digital Image Processing)
PPTX
Image processing ppt
Asymptotic notations
AI 7 | Constraint Satisfaction Problem
8 queens problem using back tracking
Theory of automata and formal language
Asymptotic notations
Image Restoration (Digital Image Processing)
Image processing ppt

What's hot (20)

PDF
Fundamentals of algorithms
PDF
Expert systems Artificial Intelligence
PDF
Rough K Means - Numerical Example
PPT
Histogram equalization
PPTX
Artificial Intelligence Searching Techniques
PPTX
Psuedo color
PPT
DESIGN AND ANALYSIS OF ALGORITHMS
PPT
Jumps in Assembly Language.
PPTX
Instruction sets of 8086
PPTX
5. phases of nlp
PPT
Unit 1 chapter 1 Design and Analysis of Algorithms
PPT
Spatial data mining
PPTX
Neural networks.ppt
PPTX
DISEASE PREDICTION SYSTEM USING DATA MINING
PPT
Data mining techniques unit 1
PPT
Discrete cosine transform
PPTX
Asymptotic Notations
PPTX
Object recognition
PPTX
Convolution Neural Network (CNN)
PPTX
Adaptive Median Filters
Fundamentals of algorithms
Expert systems Artificial Intelligence
Rough K Means - Numerical Example
Histogram equalization
Artificial Intelligence Searching Techniques
Psuedo color
DESIGN AND ANALYSIS OF ALGORITHMS
Jumps in Assembly Language.
Instruction sets of 8086
5. phases of nlp
Unit 1 chapter 1 Design and Analysis of Algorithms
Spatial data mining
Neural networks.ppt
DISEASE PREDICTION SYSTEM USING DATA MINING
Data mining techniques unit 1
Discrete cosine transform
Asymptotic Notations
Object recognition
Convolution Neural Network (CNN)
Adaptive Median Filters
Ad

Similar to Lisp and prolog in artificial intelligence (20)

PPTX
Prolog & lisp
DOCX
CSC8503 Principles of Programming Languages Semester 1, 2015.docx
PPT
Advance LISP (Artificial Intelligence)
DOCX
AI Lab Manual.docx
PPT
(Ai lisp)
PPTX
PPT
PROLOGPROLOGPROLOGPROLOGPROLOGPROLOGPROLOGPROLOGPROLOG
PPT
Prolog basics
PPT
Chaps 1-3-ai-prolog
PPT
Artificial intelligence Prolog Language
PPTX
Csci101 lect02 selection_andlooping
DOCX
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
PPTX
Functional Programming.pptx
PDF
Procedural Programming: It’s Back? It Never Went Away
PPT
Prolog programming
PPT
Prolog programming
PPT
Prolog programming
PPT
Prolog programming
PPT
Prolog programming
PPT
Prolog programming
Prolog & lisp
CSC8503 Principles of Programming Languages Semester 1, 2015.docx
Advance LISP (Artificial Intelligence)
AI Lab Manual.docx
(Ai lisp)
PROLOGPROLOGPROLOGPROLOGPROLOGPROLOGPROLOGPROLOGPROLOG
Prolog basics
Chaps 1-3-ai-prolog
Artificial intelligence Prolog Language
Csci101 lect02 selection_andlooping
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
Functional Programming.pptx
Procedural Programming: It’s Back? It Never Went Away
Prolog programming
Prolog programming
Prolog programming
Prolog programming
Prolog programming
Prolog programming
Ad

Recently uploaded (20)

PPTX
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
PPTX
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
PPTX
Business Ppt On Nestle.pptx huunnnhhgfvu
PPTX
MODULE 8 - DISASTER risk PREPAREDNESS.pptx
PDF
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
PPTX
Supervised vs unsupervised machine learning algorithms
PPT
Miokarditis (Inflamasi pada Otot Jantung)
PDF
Fluorescence-microscope_Botany_detailed content
PDF
Galatica Smart Energy Infrastructure Startup Pitch Deck
PPTX
IBA_Chapter_11_Slides_Final_Accessible.pptx
PDF
Mega Projects Data Mega Projects Data
PDF
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
PPTX
Introduction-to-Cloud-ComputingFinal.pptx
PPTX
Qualitative Qantitative and Mixed Methods.pptx
PPTX
Acceptance and paychological effects of mandatory extra coach I classes.pptx
PPTX
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
PDF
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
PPT
Quality review (1)_presentation of this 21
PDF
Clinical guidelines as a resource for EBP(1).pdf
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
Business Ppt On Nestle.pptx huunnnhhgfvu
MODULE 8 - DISASTER risk PREPAREDNESS.pptx
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
Supervised vs unsupervised machine learning algorithms
Miokarditis (Inflamasi pada Otot Jantung)
Fluorescence-microscope_Botany_detailed content
Galatica Smart Energy Infrastructure Startup Pitch Deck
IBA_Chapter_11_Slides_Final_Accessible.pptx
Mega Projects Data Mega Projects Data
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
Introduction-to-Cloud-ComputingFinal.pptx
Qualitative Qantitative and Mixed Methods.pptx
Acceptance and paychological effects of mandatory extra coach I classes.pptx
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
Quality review (1)_presentation of this 21
Clinical guidelines as a resource for EBP(1).pdf

Lisp and prolog in artificial intelligence

  • 1. ARTIFICIAL INTELLIGENCE LISP and PROLOG Submitted to : Submitted by: Dr.arpana chaturvedi Arti kumari
  • 2. S No. CONTENT REMARK LISP 1 To print “hello world” in LISP 2 program To find the area of circle 3 to print odd number form 1-20 4 to print the average of number 10,20,30,40 5 defining macro OPERATORS 6 Arithmetic operator 7 Comparision operator 8 Logical operator DECISIONS CONSTRUCT 9 Cond 10 If 11 When 12 case LOOPS 13 Loop 14 Loop for 15 Do 16 dotimes 17 dolist 18 Predicate 29 Factorial of a number 20 Array 21 String 22 Sequence 23 list 24 Exiting from block 25 Let function 26 Prog function 27 Formatted output
  • 3. PROLOG 28 Print hello world using prolog. In console 29 prolog program to print hello world.. 30 Priya, Tiyasha, and Jaya are three girls, among them, Priya can cook 31 some rules. Rules contain some information that are conditionally true about the domain of interest. 32 Priya, Tiyasha, and Jaya are three girls, among them, Priya can cook. ;use of variable in our query 33 Prolog program, that can find the minimum of two numbers and the maximum of two numbers. 34 write a prolog program that will help us find the equivalent resistance 35 program to show working of Arithmetic operator in prolog 36 prolog program to print values from 1 to10 using loop 37 Example of decision making in Prolog. 38 prolog program to find the length of the list 39 prolog program to concatenate two list 40 Backtracking. 41 prolog program to find the cube of a number
  • 4. LISP Q1)To print “hello world” in LISP CODE: (write-line "Hello World") (write-line "I am at 'Online class' !- Learning LISP" )
  • 5. Q2) LISP program To find the area of circle .. CODE: (defconstantp13.141592) (defunarea-circle(rad) (terpri) (formatt " Radius:~5f"rad) (formatt "~%area:~10f" (* p1 rad rad))) (area-circle 10)
  • 6. Q3)LISP program to print odd number form 1-20 ? CODE: (loopfor x from 1 to 20 if(oddpx) do (printx) )
  • 7. Q4)LISP program to print the average of number 10,20,30,40 CODE: ;write a LISP program to find the average of numbers (defunaveragenum(n1 n2 n3 n4) ( / ( + n1 n2 n3 n4) 4) ) (write(averagenum10 20 30 40))
  • 8. Q5.defining macro CODE: (defmacro setTo10(num) (setq num 10)(print num)) (setq x 25) (print x) (setTo10 x)
  • 9. Q6)Arithmetic operators (setq a 10) (setq b 20) (format t "~% A + B = ~d" (+ a b)) (format t "~% A - B = ~d" (- a b)) (format t "~% A x B = ~d" (* a b)) (format t "~% B / A = ~d" (/ b a)) (format t "~% Increment A by 3 = ~d" (incf a 3)) (format t "~% Decrement A by 4 = ~d" (decf a 4))
  • 10. Q7) Comparison operator (setq a 10) (setq b 20) (format t "~% A = B is ~a" (= a b)) (format t "~% A /= B is ~a" (/= a b)) (format t "~% A > B is ~a" (> a b)) (format t "~% A < B is ~a" (< a b)) (format t "~% A >= B is ~a" (>= a b)) (format t "~% A <= B is ~a" (<= a b)) (format t "~% Max of A and B is ~d" (max a b)) (format t "~% Min of A and B is ~d" (min a b))
  • 11. Q8) logical operator (setq a 10) (setq b 20) (format t "~% A and B is ~a" (and a b)) (format t "~% A or B is ~a" (or a b)) (format t "~% not A is ~a" (not a)) (terpri) (setq a nil) (setq b 5) (format t "~% A and B is ~a" (and a b)) (format t "~% A or B is ~a" (or a b)) (format t "~% not A is ~a" (not a)) (terpri) (setq a nil) (setq b 0) (format t "~% A and B is ~a" (and a b)) (format t "~% A or B is ~a" (or a b)) (format t "~% not A is ~a" (not a)) (terpri) (setq a 10) (setq b 0) (setq c 30) (setq d 40) (format t "~% Result of and operation on 10, 0, 30, 40 is ~a" (and a b c d)) (format t "~% Result of and operation on 10, 0, 30, 40 is ~a" (or a b c d)) (terpri) (setq a 10) (setq b 20) (setq c nil) (setq d 40) (format t "~% Result of and operation on 10, 20, nil, 40 is ~a" (and a b c d)) (format t "~% Result of and operation on 10, 20, nil, 40 is ~a" (or a b c d))
  • 13. Q9) cond construct (setq a 10) (cond ((> a 20) (format t "~% a is greater than 20")) (t (format t "~% value of a is ~d " a))) Q10) If construct (setq a 10) (if (> a 20) (format t "~% a is less than 20")) (format t "~% value of a is ~d " a)
  • 14. Q11)When construct (setq a 100) (when (> a 20) (format t "~% a is greater than 20")) (format t "~% value of a is ~d " a)
  • 15. Q12)Case construct (setq day 4) (case day (1 (format t "~% Monday")) (2 (format t "~% Tuesday")) (3 (format t "~% Wednesday")) (4 (format t "~% Thursday")) (5 (format t "~% Friday")) (6 (format t "~% Saturday")) (7 (format t "~% Sunday")))
  • 16. Q13)Loop construct (setq a 10) (loop (setq a (+ a 1)) (write a) (terpri) (when (> a 17) (return a)) )
  • 17. Q14)Loop for (loop for x from 1 to 20 if(evenp x) do (print x) )
  • 18. Q15)Do construct (do ((x 0 (+ 2 x)) (y 20 ( - y 2))) ((= x y)(- x y)) (format t "~% x = ~d y = ~d" x y) )
  • 19. Q16)dotimes (dotimes (n 11) (print n) (prin1 (* n n)) )
  • 20. Q17)dolist (dolist (n '(1 2 3 4 5 6 7 8 9)) (format t "~% Number: ~d Square: ~d" n (* n n)) )
  • 21. Q18)predicate (write (atom 'abcd)) (terpri) (write (equal 'a 'b)) (terpri) (write (evenp 10)) (terpri) (write (evenp 7 )) (terpri) (write (oddp 7 )) (terpri) (write (zerop 0.0000000001)) (terpri) (write (eq 3 3.0 )) (terpri) (write (equal 3 3.0 )) (terpri) (write (null nil ))
  • 22. Q19)To find the factorial of a number (defun factorial (num) (cond ((zerop num) 1) (t ( * num (factorial (- num 1)))) ) ) (setq n 6) (format t "~% Factorial ~d is: ~d" n (factorial n))
  • 23. Q20)Array (write (setf my-array (make-array '(10)))) (terpri) (setf (aref my-array 0) 25) (setf (aref my-array 1) 23) (setf (aref my-array 2) 45) (setf (aref my-array 3) 10) (setf (aref my-array 4) 20) (setf (aref my-array 5) 17) (setf (aref my-array 6) 25) (setf (aref my-array 7) 19) (setf (aref my-array 8) 67) (setf (aref my-array 9) 30) (write my-array)
  • 24. Q21)String (write-line "Hello World") (write-line "Welcome to JAGANNATH INSTITUTE OF MANAGEMENT SCIENCES") ;escaping the double quote character (write-line "Welcome SIXTH SEMESTER")
  • 25. Q22) sequence (write (count 7 '(1 5 6 7 8 9 2 7 3 4 5))) (terpri) (write (remove 5 '(1 5 6 7 8 9 2 7 3 4 5))) (terpri) (write (delete 5 '(1 5 6 7 8 9 2 7 3 4 5))) (terpri) (write (substitute 10 7 '(1 5 6 7 8 9 2 7 3 4 5))) (terpri) (write (find 7 '(1 5 6 7 8 9 2 7 3 4 5))) (terpri) (write (position 5 '(1 5 6 7 8 9 2 7 3 4 5)))
  • 26. Q23)lists (write (cons 1 2)) (terpri) (write (cons 'a 'b)) (terpri) (write (cons 1 nil)) (terpri) (write (cons 1 (cons 2 nil))) (terpri) (write (cons 1 (cons 2 (cons 3 nil)))) (terpri) (write (cons 'a (cons 'b (cons 'c nil)))) (terpri) (write ( car (cons 'a (cons 'b (cons 'c nil))))) (terpri) (write ( cdr (cons 'a (cons 'b (cons 'c nil)))))
  • 28. Q25) let function (let((x 'a)(y'b) (z'c)) (formatt "x= ~a y= ~a z= ~a" x y z))
  • 30. Q27)Formatted output (setqx 10) (setqy20) (formatt"x=~2d y=~2d ~%" x y) (setqx 100) (setqy200) (formatt"x=~2d y=~2d" x y)
  • 31. PROLOG Q28) Print hello world using prolog.. CODE: write('Hello World'). Q29)prolog program to print hello world.. CODE: main :- write('This is sample Prolog program'), write(' This program is written into hello_world.pl file').
  • 32. Q30) Priya, Tiyasha,and Jaya are three girls, among them,Priya can cook. CODE: girl(priya). girl(tiyasha). girl(jaya). can_cook(priya). Q31) some rules. Rules contain some informationthat are conditionally true about the domain of interest. CODE: sing_a_song(ananya).
  • 33. listens_to_music(rohit). listens_to_music(ananya):- sing_a_song(ananya). happy(ananya):- sing_a_song(ananya). happy(rohit) :- listens_to_music(rohit). playes_guitar(rohit):- listens_to_music(rohit). Q32) Priya, Tiyasha,and Jaya are three girls, among them,Priya can cook. ;use of variable in our query CODE: can_cook(priya).
  • 34. can_cook(jaya). can_cook(tiyasha). likes(priya,jaya) :- can_cook(jaya). likes(priya,tiyasha) :- can_cook(tiyasha). Q33) Prolog program,that can find the minimum of two numbers and the maximum of two numbers. CODE: find_max(X,Y,X) :- X >= Y, !. find_max(X,Y,Y) :- X < Y. find_min(X,Y, X) :- X =< Y, !. find_min(X,Y, Y) :- X > Y.
  • 35. Q34) write a prolog program that will help us find the equivalent resistance.  If R1 and R2 are in Series, then equivalent resistor Re = R1 + R2.  If R1 and R2 are in Parallel, then equivalent resistor Re = (R1 * R2)/(R1 + R2).
  • 37. Q35)programto show working of Arithmetic operatorin prolog + Addition - Subtraction * Multiplication / Division ** Power // Integer Division mod Modulus
  • 38. Q36)prolog program to print values from 1 to10 using loop CODE: count_to_10(10):- write(10),nl. count_to_10(X) :- write(X),nl, Y is X + 1, count_to_10(Y). Q37) Example of decision making in Prolog. CODE: % If-Then-Else statement
  • 39. gt(X,Y) :- X >= Y,write('X is greateror equal'). gt(X,Y) :- X < Y,write('X is smaller'). % If-Elif-Else statement gte(X,Y) :- X > Y,write('X is greater'). gte(X,Y) :- X =:= Y,write('X and Y are same'). gte(X,Y) :- X < Y,write('X is smaller'). Q38)prolog program to find the length of the list ;? CODE: list_length([],0). list_length([_|TAIL],N) :- list_length(TAIL,N1),N is N1 + 1.
  • 40. Q39)prolog program to concatenatetwo list CODE: list_concat([],L,L). list_concat([X1|L1],L2,[X1|L3]) :- list_concat(L1,L2,L3).
  • 42. Q41)prolog program to find the cube of a number CODE: cube :- write('Write a number:'), read(Number), process(Number).
  • 43. process(stop) :- !. process(Number) :- C is Number* Number* Number, write('Cube of '),write(Number),write(': '),write(C),nl,cube.