这是我的代码:
(define (distance-between-circle-centers x1 y1 x2 y2) (sqrt(+ (sqr(- x1 x2))
(sqr(- y1 y2)))))
(distance-between-circle-centers 1 1 2 2)
(define (cirles-position x1 y1 r1 x2 y2 r2)
cond
[(>(distance-between-circle-centers x1 y1 x2 y2) (+ r1 r2)) "external"]
[(<(distance-between-circle-centers x1 y1 x2 y2) (abs(- r1 r2)))
"interior" ]
[else "intersect"])
(circles-position 1 1 1 2 2 2)
为什么显示错误define: expected only one expression for the function body, but found 3 extra parts
?
答案 0 :(得分:1)
由于您的cond
子句中有错别字和缺少括号。
使用DrRacket编写球拍。
更正的版本:
(define (distance-between-circle-centers x1 y1 x2 y2)
(sqrt (+ (sqr (- x1 x2))
(sqr (- y1 y2)))))
(distance-between-circle-centers 1 1 2 2)
(define (circles-position x1 y1 r1 x2 y2 r2)
(cond
[(> (distance-between-circle-centers x1 y1 x2 y2) (+ r1 r2)) "external"]
[(< (distance-between-circle-centers x1 y1 x2 y2) (abs (- r1 r2))) "interior" ]
[else "intersect"]))
(circles-position 1 1 1 2 2 2)