I\'m currently trying to write a function from a list of points that returns the distance from a point p to a point in my point list that is farthest away from p. My list of poi
get-y
should use cdr
, not car
.
get-x
and get-y
miss a closing parenthesis.
For max-distance
, I'd go for
(define (max-distance p pt-list)
(apply max (map (lambda (x) (distance p x)) pt-list)))
which means that you don't need get-first-point
and get-rest-points
.
Illustration (using (1 . 1) as p):
> (map (lambda (x) (distance '(1 . 1) x)) '((2 . 4) (3 . 6) (5 . 12) (-4 . 3) (8.4 . 9) (0 . -1)))
'(3.1622776601683795 5.385164807134504 11.704699910719626 5.385164807134504 10.897706180660222 2.23606797749979)
> (apply max (map (lambda (x) (distance '(1 . 1) x)) '((2 . 4) (3 . 6) (5 . 12) (-4 . 3) (8.4 . 9) (0 . -1))))
11.704699910719626
Depending on your definition of "farthest" you may want to include abs
in the expression.