定义:只希望函数主体有一个表达式,但发现3个多余的部分

时间:2018-10-31 06:14:42

标签: racket

这是我的代码:

(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

1 个答案:

答案 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)