Write a function (euclid point1 point2) that accepts two parameters, each being a list containing exactly two numbers that define a two-dimensional point. Return the Euclidean distance between the two points. Use cond to check for the proper input (lists that contain exactly two numbers). If the input is improper, return

Answer :

Answer:

Explanation:

Solution:

-The task is more likely to compute the distance of n-dimensional vectors, i.e.

sqrt((x1-y1)^2 + ... + (xn-yn)^2).

- With a recursive version, I consider that p and q are two mathematical vectors, so that p contains different coordinates (p1, ..., pn), which differs from your implementation where p contains all x's and q all y's.

- So, you have to compute (pi - qi)^2 for each for pair (pi, qi) of elements taken in parallel from p and q, sum the intermediate values and take the square root.

- The function would be as follows:

 " (defun euclidean-distance-it (p q)

      (destructuring-bind (x1 x2) p

          (destructuring-bind (y1 y2) q

               (sqrt (+ (expt (- x1 y1) 2)

                       (expt (- x2 y2) 2)))))) "

- With high-order functions, you don't even need to use recursion. The function would be:

     "  (defun distance (p q)  

                 (sqrt

                    (reduce #'+  

                       (map 'list

                           (lambda (px qx) (expt (- px qx) 2))  

                            p q)))) "