01 Introduction to CS136
1/1
mwg@uwaterloo.ca
M. Jason Hinek (DC 3322)
mjhinek@uwaterloo.ca
Mark Petrick (DC 3529)
mdtpetri@uwaterloo.ca
Olga Zorin (DC 3119)
ozorin@cs.uwaterloo.ca
Course email: cs136@student.cs.uwaterloo.ca
01 Introduction to CS136
2/1
Tutors: Joe Istead jwistead@yahoo.ca Gregory Ling Kit Chow glkchow@uwaterloo.ca Rui Zhao rui.zhao@uwaterloo.ca Erik Karl Traikov ektraiko@uwaterloo.ca Huma Zafar hzafar@uwaterloo.ca Instructional Assistants (IAs): David Ryan Loker dloker@uwaterloo.ca Caelyn McAulay cmcaulay@uwaterloo.ca Lesley Ann Northam lanortha@uwaterloo.ca Richard Jason Peasgood jpeasgo@uwaterloo.ca Please send email to cs136@student.uwaterloo.ca for the fastest response.
01 Introduction to CS136
3/1
http://www.student.cs.uwaterloo.ca/~cs136/
Discussion: Your main discussion forum Piazza
https://piazza.com/
Tutorials: See course website Reading week: February 2024 Midterm: Monday, 27 Feb 7:00pm8:50pm
01 Introduction to CS136
4/1
Textbooks:
http://www.htdp.org
C Programming: A Modern Approach (CP:AMA) by K. N. King. Presentation handouts: Available on web page, one week before lecture
01 Introduction to CS136
5/1
Marking Scheme: 30% assignments 30% midterm 40% nal exam Your assignment average and weighted exam average must both be greater than 50% or you will not pass! A1 is due in one week! (But well do some together.) Software: DrRacket (and maybe the command line and RunC) will be used for Racket. RunC will be used for C. VirtualBox (go to a tutorial, see website) is by far the easiest.
01 Introduction to CS136
6/1
01 Introduction to CS136
7/1
Write programs that do stuff in the real world Interact with users, devices, other programs
Input from the outside world Output to the outside world (...more input, more output, input, output...)
01 Introduction to CS136
7/1
Write programs that do stuff in the real world Interact with users, devices, other programs
Input from the outside world Output to the outside world (...more input, more output, input, output...)
01 Introduction to CS136
7/1
Write programs that do stuff in the real world Interact with users, devices, other programs
Input from the outside world Output to the outside world (...more input, more output, input, output...)
Abstraction is how we will interact with other code Store and Manipulate data and state
01 Introduction to CS136
7/1
Specic Topics
In CS135, wrote functions
Data included as literals; exact same output every time
01 Introduction to CS136
8/1
Specic Topics
In CS135, wrote functions
Data included as literals; exact same output every time
In CS136, we will write programs. Behaviour now depends on interaction with other data/programs/users.
01 Introduction to CS136
8/1
Specic Topics
In CS135, wrote functions
Data included as literals; exact same output every time
In CS136, we will write programs. Behaviour now depends on interaction with other data/programs/users. I/O For interaction with other data/programs/users Modularization a.k.a. abstraction, a.k.a. hiding detail.
Somebodys code maybe does something complicated, but using it to do that thing is simple
Efciency Are our programs fast enough? Could we do better? Mutation For memory storing data or state
01 Introduction to CS136
8/1
http://docs.racket-lang.org/reference/ http://docs.racket-lang.org/guide/
01 Introduction to CS136
9/1
http://docs.racket-lang.org/reference/ http://docs.racket-lang.org/guide/
01 Introduction to CS136
9/1
http://docs.racket-lang.org/reference/ http://docs.racket-lang.org/guide/
C is imperative
repetition emphasized over recursion ability to manipulating memory directly
01 Introduction to CS136
9/1
http://docs.racket-lang.org/reference/ http://docs.racket-lang.org/guide/
C is imperative
repetition emphasized over recursion ability to manipulating memory directly
Reading:
http://docs.racket-lang.org/guide/module-basics.html
01 Introduction to CS136
10/1
In CS 136 we will use the full Racket language Put #lang racket as the very rst line of your program. This wraps your entire program in a module, which is a way of packaging code. More precisely, this wraps your code in a module as follows:
( module filename scheme ... your code here ... )
Your code is put into a module of the same name as that of the le containing the code (removing the sufx .rkt).
01 Introduction to CS136
11/1
Modules
Modules allow you to control what goes in and what comes out.
module
bindings
(require "myle.rkt")
#lang racket makes the full Racket language available inside the module.
01 Introduction to CS136
12/1
Racket is a Scheme/Lisp variant, derived most recently from PLT Scheme. Racket is an industrial strength programming language.
01 Introduction to CS136
13/1
Racket is a Scheme/Lisp variant, derived most recently from PLT Scheme. Racket is an industrial strength programming language. There are some important differences
check-expect and the Stepper are gone true and false are represented by actual values #t and #f
01 Introduction to CS136
13/1
The teaching languages enforce the restriction that the second argument to cons must be a list. R5RS and Racket do not.
01 Introduction to CS136
14/1
The teaching languages enforce the restriction that the second argument to cons must be a list. R5RS and Racket do not. The value of the expression (cons 1 2) is printed in the Interactions window as '(1 . 2)
We will not use this feature in CS 136. If you see dotted notation in your lists, you are probably doing something wrong. Check the arguments of the cons expressions in your code.
01 Introduction to CS136
14/1
;; a1p1.rkt #lang racket ;; Output the result of the sum of the numbers ;; from 1 to 10 (+ 1 2 3 4 5 6 7 8 9 10)
01 Introduction to CS136
15/1
#lang racket ;; Function that sums the numbers from 1 to n ;; Output the result of the sum of the numbers ;; from 1 to n ( define ( sum-1-to-n n) (cond [ (= n 0) 0] [ else (+ n ( sum-1-to-n (sub1 n))) ] ))
01 Introduction to CS136
16/1
#lang racket ;; This file is called "testsums.rkt" ( require " sum-1-to-n .rkt") ( sum-1-to-n 'foo) ( sum-1-to-n " eleventy ") (time ( sum-1-to-n 10)) (time ( sum-1-to-n 5000000)) (time ( sum-1-to-n 10000000)) (time ( sum-1-to-n 20000000)) (time ( sum-1-to-n 80000000))
CS 136 Winter 2012 01 Introduction to CS136 19/1
We should be a little careful accumulative recursion is not always faster than structural recursion. We havent even dened what it means for one implementation to be faster than another. Accumulative recursion does save space here; the recursive call is now tail-recursive. Well talk about algorithm and implementation efciency (for time and space) shortly.
01 Introduction to CS136
21/1
01 Introduction to CS136
22/1
Summary
01 Introduction to CS136
23/1