Dr code
I am writing a function that consumes two images and produces true if the first is greater than the second here is my code
(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)
But it shows the same error over and over again, highlighting this part of the code -> (circle y "solid" "blue"). error-> define: only one expression is expected for function body but 2 additional details found, kindly tell me what is wrong
source to share
The values true
and are false
simply written like true
and false
.
(define (image1 x y)
(circle x "solid" "blue")
(circle y "solid" "blue")
(if (> x y)
true
false))
Note that your function does not use images, so you can write
(define (image1 x y)
(if (> x y)
true
false))
But I think it was just an example.
UPDATE
You can use local definitions to name temporary values:
(define (image1 x y)
(local
[(define c1 (circle x "solid" "blue"))
(define c2 (circle y "solid" "blue"))]
(if (> x y)
true
false)))
UPDATE
(define (larger? image1 image2)
(and (> (image-width image1) (image-width image2)
(> (image-height image1) (image-height image2)))
UPDATE
Here's a complete example:
(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)
source to share