dr racket代码错误开始使用学生语言
我正在编写一个函数,该函数使用两个图像,如果第一个图像大于第二个图像,则生成true 这是我的密码dr racket代码错误开始使用学生语言,racket,Racket,我正在编写一个函数,该函数使用两个图像,如果第一个图像大于第二个图像,则生成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)
(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)
但通过突出显示代码的这一部分->(圆圈y“solid”“blue”)它一次又一次地显示相同的错误->错误是->定义:函数体只需要一个表达式,但是发现了两个额外的部分,请告诉我有什么问题值
true
和false
被简单地写为true
和false
(define (image1 x y)
(circle x "solid" "blue")
(circle y "solid" "blue")
(if (> x y)
true
false))
请注意,your函数不使用图像,因此您可以编写
(define (image1 x y)
(if (> x y)
true
false))
但我想这只是一个例子
更新
(define (larger? image1 image2)
(and (> (image-width image1) (image-width image2)
(> (image-height image1) (image-height image2)))
可以使用本地定义为临时值命名:
(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 (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)
我的目标是使用两个图像并进行比较这是我能做的最好的方法这就是为什么。还有其他方法吗???您可以使用局部定义为临时值命名。请参阅更新的答案。它表示此函数未定义,本地函数现在要做什么。shud我在顶部添加了一些东西??本地语言可以在中间语言中使用:我想用BSL来做,所以有没有关于shud我如何继续的建议