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

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

View Full Document Right Arrow Icon
;; 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:
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
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

Page1 / 2

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online