;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-beginner-reader.ss" "lang")((modname week2_tu_full) (read-case-sensitive #t) (teachpacks ((lib "image.ss" "teachpack" "2htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "image.ss" "teachpack" "2htdp"))))) (define (myif q a z) (cond [q a] [else z])) ;Design Recipe: ;Data ;Signature, Purpose Header ;Examples ;Body ;Tests (run the examples) ; addone : number -> number <--- signature ; adds one to a number <--- purpose (define (addone n) ;<--- header (+ n 1)) ;<--- body ;Examples/Tests: (check-expect (addone 4) 5) (check-expect (addone -5) -4) ; Exam question 4: Use the design recipe to write a function ; projectx that projects a posn to x-axis. ; projectx : posn -> posn ; projects posn to the x-axis (define (projectx p) (make-posn (posn-x p) 0) ) (check-expect (projectx (make-posn 3 4)) (make-posn 3 0)) (check-expect (projectx (make-posn -2 -6)) (make-posn -2 0)) (check-expect (projectx (make-posn 4 0)) (make-posn 4 0))