I am writing a function that consumes two images and produces true if the first is larger 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 is showing the same error again and again by highlighting this portion of the code ->(circle y "solid" "blue") the error is-> define: expected only one expression for the function body, but found 2 extra parts kindly tell me what is wrong
The values true and false are simply written as true and false.
(define (image1 x y)
(circle x "solid" "blue")
(circle y "solid" "blue")
(if (> x y)
true
false))
Note that the your function doesn't use the images, so you can write
(define (image1 x y)
(if (> x y)
true
false))
But I guess it was just an example.
UPDATE
You can use local definitions to give names to 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 is 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With