'Racket/Begineer Student Language Function Confusion
Right now each individual function takes the coordinates (2,3) and does their respective tasks. I am confused about how I can format it so the functions will take "move right 2.2 units" instead of "move right 1 unit" starting from POSN-0 (0,0).
(define POSN-0 (make-posn 0 0))
(check-expect (right POSN-0 2 3) (make-posn 3 3))
(define (right p x y)
(make-posn (+ (+ (posn-x p) x) p)
(+ (posn-y p) y)))
(check-expect (left POSN-0 2 3) (make-posn 1 3))
(define (left p x y)
(make-posn (- (+ (posn-x p) x) 1)
(+ (posn-y p) y)))
(check-expect (down POSN-0 2 3) (make-posn 2 2))
(define (down p x y)
(make-posn (+ (posn-x p) x)
(- (+ (posn-y p) y) 1)))
(check-expect (up POSN-0 2 3) (make-posn 2 4))
(define (up p x y)
(make-posn (+ (posn-x p) x)
(+ (+ (posn-y p) y) 1)))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
