[racket] structures question
On 3/29/12 10:20 AM, Roelof Wobben wrote:
>
> ;; Posn -> Number.
> ;; A programm for calculating the distance is Manhatten
> (check-expect ( manhatten (make-posn 7 3 ) 10))
> (check-expect ( manhatten (make-posn 1 1 ) 2))
>
> (define (manhatten pos-manhatten)
> ( + (pos-y posmanhetten) (pos-x manhetten)))
You have several small problems in this program:
1) You use of parentheses in the test cases are wrong.
2) Several variables are misspelled, such as pos-x (should be posn-x),
posmanhetten (should be pos-manhatten), manhetten (should be
pos-manhatten), etc.
Fixing those problems fixes the program:
;; Posn -> Number.
;; A programm for calculating the distance is Manhatten
(check-expect (manhatten (make-posn 7 3 )) 10)
(check-expect (manhatten (make-posn 1 1 )) 2)
(define (manhatten pos-manhatten)
(+ (posn-y pos-manhatten) (posn-x pos-manhatten)))
[Also: "Manhattan" is the proper spelling.]
David