CS 135 Tutorials Fall 2007


CS 135 Home »Tutorials »

CS 135 Tutorial 1: Introduction (September 12-14, 2007)

  1. Preliminaries
    1. Welcome to CS 135 Tutorials!
    2. Web page, labs, consulting hours

  2. Tools
    1. DrScheme
    2. DrScheme is an IDE (Integrated Development Environment) and interpreter for the Scheme programming language. Information on downloading and installing DrScheme can be found at http://www.drscheme.org.

      Make sure you install the latest version from the website. Older versions (even relatively recent ones) can sometimes have significant language differences which will be troublesome later on.

      With DrScheme installed on your system (or using a computer in one of the labs), try the following:

      • Open DrScheme
      • Go to LanguagesChoose Language and select the language "Beginning Student" under "How to Design Programs".
      • The following code defines a constant speed-of-light and a function meters->lightyears which converts a distance in meters to light years (approximately).
        (define speed-of-light 299792458) ;in m/s
        
        (define (meters->lightyears dist)
            (/ dist (* speed-of-light (* 60 60 24 365.3524))))

        Copy and paste the preceding code into the Definitions Window in DrScheme.

      • Save the Definitions as t1.scm.
      • Now compute the height of one of your IAs in light years by typing the line
        (meters->lightyears 1.85)
        into the Interactions Window.

    3. Odyssey
    4. Your programming assignments for CS 135 will be submitted electronically. The details of how to do this (and much more useful information) can be found in the Style Guide for Assignments. The easiest method is probably to use Odyssey, an online graphical interface to your UNIX account at https://www.student.cs.uwaterloo.ca/odyssey/.

      You will get practice submitting files in Assignment 0. Always be careful about what folders you put your solution files in and what you call your files, especially if you use Odyssey. Don't wait until the last moment to submit!

  3. Simple Functions in Scheme
    1. Scheme notation vs. Mathematical notation
    2. Convert the following functions from Scheme notation into standard mathematical function notation:
      • (define (f x) (- (* 5 x) 4))f(x) = ???
      • (define (g x) (- (/ (* (+ x 2) (- x 3)) 5) x))g(x) = ???
      Now convert the following from standard math notation into Scheme functions:
      • f(x) = (x+5)/(8x-9)⇒???
      • g(x,y) = (xy-7)(x+y) - (3x + 5y - 12)⇒???

    3. Function Evaluation
    4. Evaluate each of the following Scheme statements by hand. Then use DrScheme to check your work.
      • (- (* 4 5) (/ 6 3))
      • (/ (+ 2 (- 5 2) (* 3 3)) (/ (- (* 5 5) 4) 3))
      • (define (f x) (* x (+ x 1)))
        (+ (f 1) (/ (f 2) 3))
      • (define (f x) (- x 1))
        (define (g x) (* x (f (/ x 3)) 2))
        (/ (g (g 6)) 2)

  4. Reminders

This file generated Monday, December 17th, 2007 using PLT Scheme and WebIt!