Question

Let lst1 = '(a b c d e), lst2 = '(1 2 3 4 5). The...

Let lst1 = '(a b c d e), lst2 = '(1 2 3 4 5). The proc function takes a list as input and returns the middle element of the list. What will be the following expression evaluate to:

(append (cons (first lst1) '())

(cons (cdddr lst1) '())

(cons (proc lst1) '())

(cons (proc lst2) '())

(cons (fifth lst1) '())

)

a.

'(a d e c 3 e)

b.

'(a d e c 3 d)

c.

'(a (d e) c 3 e)

d.

'(a (d e) c (3) d)

e.

'((a) (d e) (c) (3) (d))

The answer is option c. '(a (d e) c 3 e)

;append function will append all the elements
;(cons (first lst1) '()) will return a (first element in lst1)
;(cons (proc lst1) '()) will return (d e) (since cdddr will exclude the first three element and returns the rest of the list)
;(cons (proc lst1) '()) will return c which is the middle element of lst1
;(cons (proc lst2) '()) will return 3 which is the middle element of lst2
;(cons (fifth lst1) '()) will return the 5th element in lst1 which is e
;so the final list of all these elements is (a (d e) c 3 e)
(append (cons (first lst1) '())
(cons (cdddr lst1) '())
(cons (proc lst1) '())
(cons (proc lst2) '())
(cons (fifth lst1) '())
)