Convert the following COMPARE function using COND instead of

Convert the following COMPARE function using COND instead of IF. (defun compare (x y) (if (equal x y) (+ 1 2) (if ( (duplicate \'(1 2 3)) (1 1 2 2 3 3) > (duplicate \'(1 2 3 3)) (1 1 2 2 3 3 3 3) > (duplicate \'(1 (2) (3 4))) (1 1 (2) (2) (3 4) (3 4)) > (duplicate \' ()) NIL >

Solution

5. (defun comapre (x y)

( COND

(( equal x y) (+ 1 2)

((< x y) (+ 3 4)
(+ 5 6)

)

)))

6.a LISP function name is factorial and ist parameter is integer N

b. Yes factorial is recursive function.because each value of factorial is passed back through every level of the recursive call, where it is multiplied by the value of n at that level.

c. For the positive integer value

7.duplicate function to duplicate the element of the list :


(defun duplicate (lst)
(if (null lst) nil
(append (list (first lst) (first lst)) (duplicate (rest lst)))))

 Convert the following COMPARE function using COND instead of IF. (defun compare (x y) (if (equal x y) (+ 1 2) (if ( (duplicate \'(1 2 3)) (1 1 2 2 3 3) > (d

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site