dr racket code error beginning student 语言

dr racket code error beginning student language

我正在编写一个函数,它使用两个图像并在第一个大于第二个时返回 true 这是我的代码

 (require 2htdp/image)

  (check-expect(image1 30 40)false)
    (check-expect(image1 50 20)true)

(define(image1 x y)
 (begin
 ( circle x "solid" "blue")

(circle y "solid" "blue")
  (if(> x y)
     "true"
     "false")))


(image1 500 100)

但是通过突出显示这部分代码 ->(circle y "solid" "blue") 错误是-> define: expected only one expression for函数体,但发现了2个额外的部分,请告诉我哪里出了问题

truefalse简单写为truefalse

(define (image1 x y)
  (circle x "solid" "blue")
  (circle y "solid" "blue")
  (if (> x y)
      true
      false))

请注意,您的函数不使用图像,因此您可以编写

(define (image1 x y)
  (if (> x y)
      true
      false))

但我想这只是一个例子。

更新

您可以使用本地定义为临时值命名:

(define (image1 x y)
  (local 
    [(define c1 (circle x "solid" "blue"))
     (define c2 (circle y "solid" "blue"))]
  (if (> x y)
      true
      false)))

更新

(define (larger? image1 image2)
  (and (> (image-width  image1) (image-width  image2) 
       (> (image-height image1) (image-height image2)))

更新

这是一个完整的例子:

(define circle1 (circle 20 "solid" "blue"))
(define circle2 (circle 30 "solid" "blue"))

(define (larger? image1 image2)
  (and (> (image-width  image1) (image-width  image2))
       (> (image-height image1) (image-height image2))))

(larger? circle1 circle2)