You are on page 1of 4

BASIC LISP ASSIGNMENT:

Question:01 Number of elements in the list and what type of elements are they:

a. L1 = (a b c d e f g h)
Answer:
Total Elements: 8
Type of Elements: All elements are Atomic.

b. L2 = ((a b c) (d) e (f g) h)
Answer:
Total Elements: 5
Type of Elements: 2 elements are Atomic and 3 are List elements.

c. L3 = ((a) (b (c) d) e (f g) h)
Answer:
Total Elements: 5
Type of Elements: 2 elements are Atomic and 3 are List elements.

d. L4 = ((a b) c (d) e (f g) h)
Answer:
Total Elements: 6
Type of Elements: 3 elements are Atomic and # are List elements.

e. L5 = ((a (b) c) (d e f) (g) h)

Answer:
Total Elements: 4
Type of Elements: 1 is Atomic element and 3 are List elements.

f. L6 = ((a (b c) (d) e (f g) h))


Answer:
Total Elements: 1
Type of Elements: List element.

Question:02 Make List in Lisp for following things.

a. 8 Fruits
Fruits = ( (strawberry) (mango) (kiwi) (apricot) (banana) (orange) (grapes)
( watermelon) )
b. 6 Vegetables
Vegetables = ( (carrot) (eggplant) (cucumber) (potato) (onion) (cabbage) )
b. First 6 Odd numbers
Odd = (1 3 5 7 9 (11) )

c. First 5 Even numbers


Even = (2 4 6 8 (10) )

Question:03 Apply operations on Lists in Q.1 and 2 and write the results:

a. (car L1)
result: a
b. (car L2)
result: (a b c)
c. (car L3)
result: (a)
d. (car L4)
result: (a b)
e. (car L5)
result: (a (b) c)
f. (car L6)
result: (a (b c) (d) e (f g) h))
g. (cdr L1)
result: (b c d e f g h)
h. (cdr L2)
result: ((d) e (f g) h)
i. (cdr L3)
result: ((b (c) d) e (f g) h)
j. (cdr L4)
result: (c (d) e (f g) h)
k. (cdr L5)
result: ((d e f) (g) h)
l. (cdr L6)
result: ( )
m. (car Fruits)
result: (strawberry)
n. (car Vegetables)
result: (carrot)
o. (car Odd)
result: 1
p. (car Even)
result: 2
q. (cdr Fruits)
result: ( (mango) (kiwi) (apricot) (banana) (orange) (grapes) ( watermelon) )
r. (cdr Vegetables)
result: ( (eggplant) (cucumber) (potato) (onion) (cabbage) )
s. (cdr Odd)
result: (3 5 7 9 (11))
t. (cdr Even)
result: (4 6 8 (10))
u. (car (cdr Fruits))
result: (mango)
v. (car (cdr Vegetables))
result: (eggplant)
w. (car (cdr Odd))
result: 3
x. (car (cdr Even))
result: 4
y. (car (cdr L2))
result: (d)
z. (car (cdr L3))
result: (b (c) d)

You might also like