Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

LISP Programming Assignment It is a good idea to start this assignment early; Li

ID: 3737240 • Letter: L

Question

LISP Programming Assignment It is a good idea to start this assignment early; Lisp programming, while not inherently difficult, often seem somewhat foreign at first, particularly when it comes to recursion and list manipulation. This assignment is loosely based on material by Dr. Henri Casanova. Make sure you have extensive comments! Problem #1 Define a function that takes two arguments and returns the greater of the two. Problem #2 Write a function called inches that accepts feet and inches and returns the equivalent length in centimeters. If x is the first argument and y is the second, the formula is 2.54(12x +y). For example, USER (1)inches 0 1) 2.54 USER (1)inches 6 2.5) 189.22999999999999 Problem #3-Remove an element from a list using iteration Write a Common Lisp function called my-remove that takes an atom and a list in input, and returnsa list that is identical to the input list, but with elements equal to the input atom removed, if any. Examples of the function in operation are shown below (user input is in red): CL-USER (1): (my-remove b '(a bc b d)) (a c d) CL-USER (2): (my-remove 'b '(a cd e f)) (a cde f) CL-USER (3): (my-remove'a '(b (a d) a d)) (b (a d) d) CL-USER (4): (my-remove 'a' nil Problem #4-Remove an element from a list using Recursion

Explanation / Answer

function for problem#1:

(defun largest (x y) (if (> x y) x y))

(print (largest 152 183))

output:183

function for problem#2:

(defun inches (x y) ( * 2.54(+ (* 12 x) y) ))

(print (inches 5 1.5))

output: 156.20999

function for problem #5:

(list '((5) 6 ((7 8) 9) ((())) (((10))) 11 12 ()))
(defun flatten (list1)
(cond ((null list1) nil)
((atom list1) (list list1))
(t (mapcan #'flatten list1))))
(flatten '((5) 6 ((7 8) 9) ((())) (((10))) 11 12 ()))
(write (flatten '((5) 6 ((7 8) 9) ((())) (((10))) 11 12 ())))

output: (5 6 7 8 9 10 11 12)