So at this point in the design recipe, we've written down:
; at-zero? : posn -> boolean
; returns whether the input posn is the origin
(define (at-zero? p) (...))
See below for the snippet of code we've written after including the tests:
; at-zero? : posn -> boolean
; returns whether the input posn is the origin
(define (at-zero? p) (...))
(check-expect (at-zero? (make-posn 0 0)) true)
(check-expect (at-zero? (make-posn 0 1)) false)
(check-expect (at-zero? (make-posn 1 0)) false)
(check-expect (at-zero? (make-posn 1 1)) false)
; template
; (... (posn-x p) ...
; ... (posn-y p) ...)
We also copy this template as a starter for the body of our code. Now, in the future you might simply write the template in the function body, and not include the comment. However, for homework #2 you should include the comment.
So at this point, we have the following code:
; at-zero? : posn -> boolean
; returns whether the input posn is the origin
; template
; (... (posn-x p) ...
; ... (posn-y p) ...)
(define (at-zero? p) (
... (posn-x p) ...
... (posn-y p) ...)
)
(check-expect (at-zero? (make-posn 0 0)) true)
(check-expect (at-zero? (make-posn 0 1)) false)
(check-expect (at-zero? (make-posn 1 0)) false)
(check-expect (at-zero? (make-posn 1 1)) false)
; at-zero? : posn -> boolean
; returns whether the input posn is the origin
; template
; (... (posn-x p) ...
; ... (posn-y p) ...)
(define (at-zero? p)
(and
(= (posn-x p) 0)
(= (posn-y p) 0)
)
)
(check-expect (at-zero? (make-posn 0 0)) true)
(check-expect (at-zero? (make-posn 0 1)) false)
(check-expect (at-zero? (make-posn 1 0)) false)
(check-expect (at-zero? (make-posn 1 1)) false)