style-mutation

With unique input and output values

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: oid) ;; Purpose: consumes a number, ch, and produces (void). ;; Effects: Changes the values of x or y as follows: ;; * if ch < 0, then x is decreased by 1, ;; * if ch > 0, then x is increased by 1, ;; * if ch = 0, then x is not changed, but y is ;; set to the current value of x. ;; Examples: ;; if x and y are 0, after calling the function ;; (change ­x ­and ­y 5), x will be 1 and y will be 0. ;; if x is 100 and y is 3, after calling the function ;; (change ­x ­and ­y  ­5), x will be 99 and y will be 3. ;; if x is  ­5 and y is 7, after calling the function ;; (change ­x ­and ­y 0), x and y will both be  ­5. (define (change ­x ­and ­y ch) (cond [(< ch 0) (set! x ( x 1))] [(> ch 0) (set! x (+ x 1))] [else (set! y x)])) ;; Test with ch > 0 (check ­expect (begin (set! x 5) (set! y 12) (change ­x ­and ­y  ­3) (and (= x 4) (= y 3))) true) ;; Test with ch < 0 (check ­expect (begin (set! x 33) (set! y  ­12) (change ­x ­and ­y 7) (and (= x 34) (= y  ­12))) true) ;; Test with ch = 0 (check ­expect (begin (set! x  ­5) (set! y 2) (change ­x ­and ­y 0) (and (= x  ­5) (= y  ­5))) true) 2...
View Full Document

This note was uploaded on 09/30/2013 for the course CS 116 taught by Professor T.vasiga during the Spring '09 term at Waterloo.

Ask a homework question - tutors are online