a5q2 - Changes one to original value of three Change two to...

This preview shows pages 1–2. Sign up to view the full content.

;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-advanced-reader.ss" "lang")((modname a5q2) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ()))) ;;Assignment 5 Question 2 ;; Ru Wang r46wang 20319247 ;; a5q2 ;; State variables: ;; one: any ;; holds the first value, initially (define one 2) ;; two: any ;; holds the second value, initially (define two 3) ;; three: any ;; holds the third value, initially (define three 1) ;; shift: (void) -> (void) ; ;; this function neither consumes or produces anything. (consumes void and produces void) ; ;; Effects:

This preview has intentionally blurred sections. Sign up to view the full version.

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

Unformatted text preview: ;; Changes one to original value of three ;; Change two to original value of one ;; Change three to original value of two ; ;; Example: ;; if one is 1, two is 2, three is 3, after the function has been called, one is 3, two is 1, and three is 2. ;; if one is 'a, two is 'b, three is 'c, after the function has been called, one is 'c, two is 'a and hree is 'b. ; (define (shift) (local [(define x one)] (begin (set! one three) (set! three two) (set! two x)))) ;; Tests: (check-expect (begin (set! one 'a) (set! three 'b) (shift) (equal? one 'b)) true) (check-expect (begin (set! two 'a) (set! one 'b) (shift) (equal? two 'b)) true) (check-expect (begin (set! three 'a) (set! two 'b) (shift) (equal? three 'b)) true)...
View Full Document

This note was uploaded on 10/21/2010 for the course CS 116 taught by Professor T.vasiga during the Fall '09 term at Waterloo.

Page1 / 2

a5q2 - Changes one to original value of three Change two to...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online